151 lines
3.6 KiB
Python
151 lines
3.6 KiB
Python
from django.forms import (
|
|
Form,
|
|
ModelForm,
|
|
ModelMultipleChoiceField,
|
|
ModelChoiceField,
|
|
ChoiceField,
|
|
CharField,
|
|
)
|
|
from django.forms import inlineformset_factory
|
|
|
|
from .models import (
|
|
Answer,
|
|
CidUserAnswer,
|
|
AnatomyQuestion,
|
|
Examination,
|
|
BodyPart,
|
|
Structure,
|
|
Region,
|
|
Modality,
|
|
QuestionType,
|
|
)
|
|
|
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
|
from django.forms.widgets import RadioSelect, TextInput
|
|
|
|
|
|
class AnatomyAnswerForm(ModelForm):
|
|
class Meta:
|
|
model = CidUserAnswer
|
|
fields = ("answer",)
|
|
|
|
|
|
class MarkAnatomyQuestionForm(Form):
|
|
# correct = forms.CharField(required=False)
|
|
# half_correct = forms.CharField(required=False)
|
|
# incorrect = forms.CharField(required=False)
|
|
marked_answers = CharField(required=False)
|
|
|
|
|
|
class AnatomyQuestionForm(ModelForm):
|
|
class Media:
|
|
# Django also includes a few javascript files necessary
|
|
# for the operation of this form element. You need to
|
|
# include <script src="/admin/jsi18n"></script>
|
|
# in the template.
|
|
css = {
|
|
"all": ["css/widgets.css"],
|
|
}
|
|
# Adding this javascript is crucial
|
|
js = ["jsi18n.js", "tesseract.min.js"]
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(AnatomyQuestionForm, self).__init__(*args, **kwargs)
|
|
# self.fields['question'].widget.attrs = {'class': 'question-form', 'rows': 10, 'cols': 100}
|
|
# self.fields['feedback'].widget.attrs = {'class': 'feedback-form', 'rows': 10, 'cols': 100}
|
|
self.fields["question_type"] = ModelChoiceField(
|
|
required=True,
|
|
queryset=QuestionType.objects.all(),
|
|
initial=1,
|
|
)
|
|
|
|
self.fields["region"] = ModelChoiceField(
|
|
required=False,
|
|
queryset=Region.objects.all(),
|
|
)
|
|
|
|
self.fields["modality"] = ModelChoiceField(
|
|
required=True,
|
|
queryset=Modality.objects.all(),
|
|
)
|
|
|
|
self.fields["structure"] = ModelChoiceField(
|
|
required=False,
|
|
queryset=Structure.objects.all(),
|
|
)
|
|
|
|
self.fields["examination"] = ModelChoiceField(
|
|
required=False,
|
|
queryset=Examination.objects.all(),
|
|
)
|
|
|
|
self.fields["body_part"] = ModelChoiceField(
|
|
required=False,
|
|
queryset=BodyPart.objects.all(),
|
|
)
|
|
|
|
class Meta:
|
|
model = AnatomyQuestion
|
|
|
|
fields = [
|
|
"question_type",
|
|
"image",
|
|
"region",
|
|
"modality",
|
|
"structure",
|
|
"examination",
|
|
"body_part",
|
|
"description",
|
|
]
|
|
|
|
widgets = {}
|
|
|
|
|
|
AnswerFormSet = inlineformset_factory(
|
|
AnatomyQuestion,
|
|
Answer,
|
|
fields=["answer", "status"],
|
|
widgets={
|
|
"answer": TextInput(
|
|
attrs={"required": "true", "minlength": 2, "maxlength": 500}
|
|
)
|
|
},
|
|
exclude=[],
|
|
can_delete=True,
|
|
extra=1,
|
|
max_num=10,
|
|
field_classes="testing",
|
|
)
|
|
|
|
AnswerUpdateFormSet = inlineformset_factory(
|
|
AnatomyQuestion,
|
|
Answer,
|
|
fields=["answer", "status"],
|
|
widgets={
|
|
"answer": TextInput(
|
|
attrs={"required": "true", "minlength": 2, "maxlength": 500}
|
|
)
|
|
},
|
|
exclude=[],
|
|
can_delete=True,
|
|
extra=0,
|
|
max_num=10,
|
|
field_classes="testing",
|
|
)
|
|
|
|
class ExaminationForm(ModelForm):
|
|
class Meta:
|
|
model = Examination
|
|
fields = ['examination']
|
|
|
|
|
|
class StructureForm(ModelForm):
|
|
class Meta:
|
|
model = Structure
|
|
fields = ['structure']
|
|
|
|
|
|
class BodyPartForm(ModelForm):
|
|
class Meta:
|
|
model = BodyPart
|
|
fields = ['bodypart'] |