.
This commit is contained in:
+57
-32
@@ -9,7 +9,7 @@ from django.forms import (
|
|||||||
from django.forms import inlineformset_factory
|
from django.forms import inlineformset_factory
|
||||||
|
|
||||||
from longs.models import (
|
from longs.models import (
|
||||||
#Examination,
|
# Examination,
|
||||||
AnswerMarks,
|
AnswerMarks,
|
||||||
Long,
|
Long,
|
||||||
LongSeries,
|
LongSeries,
|
||||||
@@ -22,7 +22,8 @@ from longs.models import (
|
|||||||
from anatomy.models import Modality
|
from anatomy.models import Modality
|
||||||
|
|
||||||
from generic.models import Examination, Condition, Sign
|
from generic.models import Examination, Condition, Sign
|
||||||
#from generic.models import Examination, Site, Condition, Sign
|
|
||||||
|
# from generic.models import Examination, Site, Condition, Sign
|
||||||
|
|
||||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||||
from django.forms.widgets import RadioSelect, TextInput, Textarea
|
from django.forms.widgets import RadioSelect, TextInput, Textarea
|
||||||
@@ -30,11 +31,16 @@ from django.forms.widgets import RadioSelect, TextInput, Textarea
|
|||||||
from tinymce.widgets import TinyMCE
|
from tinymce.widgets import TinyMCE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LongAnswerForm(ModelForm):
|
class LongAnswerForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CidUserAnswer
|
model = CidUserAnswer
|
||||||
fields = ("answer_observations","answer_interpretation","answer_principle_diagnosis","answer_differential_diagnosis","answer_management",)
|
fields = (
|
||||||
|
"answer_observations",
|
||||||
|
"answer_interpretation",
|
||||||
|
"answer_principle_diagnosis",
|
||||||
|
"answer_differential_diagnosis",
|
||||||
|
"answer_management",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MarkLongQuestionSingleForm(ModelForm):
|
class MarkLongQuestionSingleForm(ModelForm):
|
||||||
@@ -42,6 +48,7 @@ class MarkLongQuestionSingleForm(ModelForm):
|
|||||||
model = CidUserAnswer
|
model = CidUserAnswer
|
||||||
fields = ["score"]
|
fields = ["score"]
|
||||||
|
|
||||||
|
|
||||||
class MarkLongQuestionDoubleForm(ModelForm):
|
class MarkLongQuestionDoubleForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AnswerMarks
|
model = AnswerMarks
|
||||||
@@ -57,9 +64,10 @@ class ExaminationForm(ModelForm):
|
|||||||
class LongCreationDefaultForm(ModelForm):
|
class LongCreationDefaultForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = LongCreationDefault
|
model = LongCreationDefault
|
||||||
#fields = ["site"]
|
# fields = ["site"]
|
||||||
exclude = ["author"]
|
exclude = ["author"]
|
||||||
|
|
||||||
|
|
||||||
class LongSeriesForm(ModelForm):
|
class LongSeriesForm(ModelForm):
|
||||||
class Media:
|
class Media:
|
||||||
# Django also includes a few javascript files necessary
|
# Django also includes a few javascript files necessary
|
||||||
@@ -74,10 +82,10 @@ class LongSeriesForm(ModelForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(LongSeriesForm, self).__init__(*args, **kwargs)
|
super(LongSeriesForm, self).__init__(*args, **kwargs)
|
||||||
#self.fields["examination"] = ModelChoiceField(
|
# self.fields["examination"] = ModelChoiceField(
|
||||||
# queryset=Examination.objects.all(),
|
# queryset=Examination.objects.all(),
|
||||||
# widget=FilteredSelectMultiple(verbose_name="Examination", is_stacked=False),
|
# widget=FilteredSelectMultiple(verbose_name="Examination", is_stacked=False),
|
||||||
#)
|
# )
|
||||||
|
|
||||||
self.fields["modality"] = ModelChoiceField(
|
self.fields["modality"] = ModelChoiceField(
|
||||||
required=True,
|
required=True,
|
||||||
@@ -86,6 +94,19 @@ class LongSeriesForm(ModelForm):
|
|||||||
|
|
||||||
ModelForm.__init__(self, *args, **kwargs)
|
ModelForm.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
if self.user.groups.filter(name="long_checker").exists():
|
||||||
|
long_queryset = Long.objects.all()
|
||||||
|
else:
|
||||||
|
long_queryset = Long.objects.filter(
|
||||||
|
author__id=self.user.id
|
||||||
|
) | Long.objects.filter(open_access=True)
|
||||||
|
|
||||||
|
self.fields["long"] = ModelMultipleChoiceField(
|
||||||
|
required=False,
|
||||||
|
queryset=long_queryset,
|
||||||
|
widget=FilteredSelectMultiple(verbose_name="Long", is_stacked=False),
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = LongSeries
|
model = LongSeries
|
||||||
exclude = ["author"]
|
exclude = ["author"]
|
||||||
@@ -93,7 +114,7 @@ class LongSeriesForm(ModelForm):
|
|||||||
|
|
||||||
class LongForm(ModelForm):
|
class LongForm(ModelForm):
|
||||||
|
|
||||||
#exams = ModelMultipleChoiceField(required=False, queryset=Exam.objects.all(),widget=FilteredSelectMultiple(verbose_name="Exams", is_stacked=False))
|
# exams = ModelMultipleChoiceField(required=False, queryset=Exam.objects.all(),widget=FilteredSelectMultiple(verbose_name="Exams", is_stacked=False))
|
||||||
|
|
||||||
class Media:
|
class Media:
|
||||||
# Django also includes a few javascript files necessary
|
# Django also includes a few javascript files necessary
|
||||||
@@ -107,7 +128,9 @@ class LongForm(ModelForm):
|
|||||||
js = ["jsi18n.js", "tesseract.min.js"]
|
js = ["jsi18n.js", "tesseract.min.js"]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.user = kwargs.pop('user') # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole
|
self.user = kwargs.pop(
|
||||||
|
"user"
|
||||||
|
) # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole
|
||||||
if kwargs.get("instance"):
|
if kwargs.get("instance"):
|
||||||
# We get the 'initial' keyword argument or initialize it
|
# We get the 'initial' keyword argument or initialize it
|
||||||
# as a dict if it didn't exist.
|
# as a dict if it didn't exist.
|
||||||
@@ -123,7 +146,9 @@ class LongForm(ModelForm):
|
|||||||
if self.user.groups.filter(name="long_checker").exists():
|
if self.user.groups.filter(name="long_checker").exists():
|
||||||
exam_queryset = Exam.objects.all()
|
exam_queryset = Exam.objects.all()
|
||||||
else:
|
else:
|
||||||
exam_queryset = Exam.objects.filter(author__id=self.user.id) | Exam.objects.filter(open_access=True)
|
exam_queryset = Exam.objects.filter(
|
||||||
|
author__id=self.user.id
|
||||||
|
) | Exam.objects.filter(open_access=True)
|
||||||
|
|
||||||
self.fields["exams"] = ModelMultipleChoiceField(
|
self.fields["exams"] = ModelMultipleChoiceField(
|
||||||
required=False,
|
required=False,
|
||||||
@@ -136,8 +161,8 @@ class LongForm(ModelForm):
|
|||||||
# fields = ['due_back']
|
# fields = ['due_back']
|
||||||
# fields = '__all__'
|
# fields = '__all__'
|
||||||
fields = [
|
fields = [
|
||||||
#"examination",
|
# "examination",
|
||||||
#"site",
|
# "site",
|
||||||
"description",
|
"description",
|
||||||
"history",
|
"history",
|
||||||
"feedback",
|
"feedback",
|
||||||
@@ -156,15 +181,15 @@ class LongForm(ModelForm):
|
|||||||
# "normal": RadioSelect(
|
# "normal": RadioSelect(
|
||||||
# choices=[(True, 'Yes'),
|
# choices=[(True, 'Yes'),
|
||||||
# (False, 'No')])
|
# (False, 'No')])
|
||||||
"feedback" : TinyMCE(attrs={'cols': 80, 'rows': 20}),
|
"feedback": TinyMCE(attrs={"cols": 80, "rows": 20}),
|
||||||
"mark_scheme" : TinyMCE(attrs={'cols': 80, 'rows': 30}),
|
"mark_scheme": TinyMCE(attrs={"cols": 80, "rows": 30}),
|
||||||
"description" : Textarea(attrs={'cols': 80, 'rows': 5}),
|
"description": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||||
"history" : Textarea(attrs={'cols': 80, 'rows': 5}),
|
"history": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||||
"model_observations" : Textarea(attrs={'cols': 80, 'rows': 5}),
|
"model_observations": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||||
"model_interpretation" : Textarea(attrs={'cols': 80, 'rows': 5}),
|
"model_interpretation": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||||
"model_principle_diagnosis" : Textarea(attrs={'cols': 80, 'rows': 5}),
|
"model_principle_diagnosis": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||||
"model_differential_diagnosis" : Textarea(attrs={'cols': 80, 'rows': 5}),
|
"model_differential_diagnosis": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||||
"model_management" : Textarea(attrs={'cols': 80, 'rows': 5}),
|
"model_management": Textarea(attrs={"cols": 80, "rows": 5}),
|
||||||
}
|
}
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
@@ -190,6 +215,7 @@ class LongForm(ModelForm):
|
|||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
SeriesFormSet = inlineformset_factory(
|
SeriesFormSet = inlineformset_factory(
|
||||||
Long,
|
Long,
|
||||||
LongSeries.long.through,
|
LongSeries.long.through,
|
||||||
@@ -199,16 +225,6 @@ SeriesFormSet = inlineformset_factory(
|
|||||||
max_num=10,
|
max_num=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
LongFormSet = inlineformset_factory(
|
|
||||||
LongSeries,
|
|
||||||
Long.series.through,
|
|
||||||
exclude=[],
|
|
||||||
can_delete=True,
|
|
||||||
extra=0,
|
|
||||||
max_num=10,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
LongSeriesImageFormSet = inlineformset_factory(
|
LongSeriesImageFormSet = inlineformset_factory(
|
||||||
LongSeries,
|
LongSeries,
|
||||||
LongSeriesImage,
|
LongSeriesImage,
|
||||||
@@ -219,7 +235,16 @@ LongSeriesImageFormSet = inlineformset_factory(
|
|||||||
field_classes="testing",
|
field_classes="testing",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ExamForm(ModelForm):
|
class ExamForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Exam
|
model = Exam
|
||||||
fields = ["name", "time_limit", "open_access", "exam_mode", "active", "double_mark", "archive"]
|
fields = [
|
||||||
|
"name",
|
||||||
|
"time_limit",
|
||||||
|
"open_access",
|
||||||
|
"exam_mode",
|
||||||
|
"active",
|
||||||
|
"double_mark",
|
||||||
|
"archive",
|
||||||
|
]
|
||||||
|
|||||||
+1
-8
@@ -26,7 +26,6 @@ from django.http import HttpResponseRedirect, HttpResponse
|
|||||||
|
|
||||||
from .forms import (
|
from .forms import (
|
||||||
LongForm,
|
LongForm,
|
||||||
LongFormSet,
|
|
||||||
LongSeriesForm,
|
LongSeriesForm,
|
||||||
LongSeriesImageFormSet,
|
LongSeriesImageFormSet,
|
||||||
MarkLongQuestionDoubleForm,
|
MarkLongQuestionDoubleForm,
|
||||||
@@ -319,11 +318,8 @@ class LongSeriesCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
|||||||
self.request.POST, self.request.FILES
|
self.request.POST, self.request.FILES
|
||||||
)
|
)
|
||||||
context["image_formset"].full_clean()
|
context["image_formset"].full_clean()
|
||||||
context["long_formset"] = LongFormSet(self.request.POST, self.request.FILES)
|
|
||||||
context["long_formset"].full_clean()
|
|
||||||
else:
|
else:
|
||||||
context["image_formset"] = LongSeriesImageFormSet()
|
context["image_formset"] = LongSeriesImageFormSet()
|
||||||
context["leng_formset"] = LongFormSet()
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
@@ -335,13 +331,10 @@ class LongSeriesCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
|||||||
|
|
||||||
context = self.get_context_data(form=form)
|
context = self.get_context_data(form=form)
|
||||||
series_formset = context["image_formset"]
|
series_formset = context["image_formset"]
|
||||||
long_formset = context["long_formset"]
|
if series_formset.is_valid():
|
||||||
if series_formset.is_valid() and long_formset.is_valid():
|
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
series_formset.instance = self.object
|
series_formset.instance = self.object
|
||||||
series_formset.save()
|
series_formset.save()
|
||||||
long_formset.instance = self.object
|
|
||||||
long_formset.save()
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user