start anatomy creation forms
This commit is contained in:
+98
-5
@@ -1,16 +1,109 @@
|
||||
from django import forms
|
||||
from django.forms import (
|
||||
Form,
|
||||
ModelForm,
|
||||
ModelMultipleChoiceField,
|
||||
ModelChoiceField,
|
||||
ChoiceField,
|
||||
CharField,
|
||||
)
|
||||
from django.forms import inlineformset_factory
|
||||
|
||||
from .models import CidUserAnswer, AnatomyQuestion
|
||||
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(forms.ModelForm):
|
||||
class AnatomyAnswerForm(ModelForm):
|
||||
class Meta:
|
||||
model = CidUserAnswer
|
||||
fields = ("answer",)
|
||||
|
||||
|
||||
class MarkAnatomyQuestionForm(forms.Form):
|
||||
class MarkAnatomyQuestionForm(Form):
|
||||
# correct = forms.CharField(required=False)
|
||||
# half_correct = forms.CharField(required=False)
|
||||
# incorrect = forms.CharField(required=False)
|
||||
marked_answers = 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", "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",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user