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