improve question adding
This commit is contained in:
@@ -116,3 +116,36 @@ AnswerFormSet = inlineformset_factory(
|
||||
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']
|
||||
@@ -34,9 +34,9 @@
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#add_abnormality").appendTo($("label[for='id_abnormality']"));
|
||||
$("#add_examination").appendTo($("label[for='id_examination']"));
|
||||
$("#add_region").appendTo($("label[for='id_region']"));
|
||||
$("#add_body_part").appendTo($("label[for='id_body_part']"));
|
||||
$("#add_structure").appendTo($("label[for='id_structure']"));
|
||||
|
||||
|
||||
dropContainer = document.getElementById("drop-container");
|
||||
@@ -224,11 +224,11 @@
|
||||
<h2>Submit Question</h2>
|
||||
<form action="" method="post" enctype="multipart/form-data" id="anatomyquestion-form">
|
||||
{% csrf_token %}
|
||||
<a href="/rapids/abnormality/create" id="add_abnormality" class="add-popup"
|
||||
<a href="/anatomy/examination/create" id="add_examination" class="add-popup"
|
||||
onclick="return showAddPopup(this);"><img src="{% static '/img/icon-addlink.svg' %}"></a>
|
||||
<a href="/rapids/examination/create" id="add_examination" class="add-popup"
|
||||
<a href="/anatomy/body_part/create" id="add_body_part" class="add-popup"
|
||||
onclick="return showAddPopup(this);"><img src="{% static '/img/icon-addlink.svg' %}"></a>
|
||||
<a href="/rapids/region/create" id="add_region" class="add-popup" onclick="return showAddPopup(this);"><img
|
||||
<a href="/anatomy/structure/create" id="add_structure" class="add-popup" onclick="return showAddPopup(this);"><img
|
||||
src="{% static '/img/icon-addlink.svg' %}"></a>
|
||||
|
||||
<table>
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
</div>
|
||||
<div class="content container">
|
||||
<a href="{% url 'anatomy:exam_list' %}">Exams</a>
|
||||
<a href="{% url 'anatomy:anatomy_question_create' %}" title="Create a new question">Create Question</a>
|
||||
{% block navigation %}
|
||||
{% endblock %}
|
||||
<div class="row">
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<h2>Add new {{name}}</h2>
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit" class="save btn btn-default">Save</button>
|
||||
</form>
|
||||
@@ -8,6 +8,8 @@
|
||||
<!--<div id="dicom-image" data-url="http://localhost:8000/static/abdoct.jpg"
|
||||
data-annotations='{{question.image_annotations}}' data-edit_annotation=true></div>-->
|
||||
<div class="question">
|
||||
<a href="{% url 'anatomy:anatomy_question_update' question.id %}" title="Edit the Question">Edit</a>
|
||||
<a href="{% url 'admin:anatomy_anatomyquestion_change' question.id %}" title="Edit the Question using the admin interface">Admin Edit</a>
|
||||
<div class="date">
|
||||
Created: {{ question.created_date }}
|
||||
</div>
|
||||
@@ -21,6 +23,12 @@
|
||||
{{ exam.name }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>
|
||||
Modality: {{ question.modality }}
|
||||
</div>
|
||||
<div>
|
||||
Region: {{ question.region }}
|
||||
</div>
|
||||
<div>
|
||||
Annotation JSON: {{ question.image_annotations }}
|
||||
</div>
|
||||
|
||||
+17
-1
@@ -8,7 +8,7 @@ urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("question/<int:pk>/", views.question_detail, name="question_detail"),
|
||||
path("question/create/", views.AnatomyQuestionCreate.as_view(), name="anatomy_question_create"),
|
||||
path("question/<int:pk>/update", views.AnatomyQuestionUpdate.as_view(), name="anatomy_question_create"),
|
||||
path("question/<int:pk>/update", views.AnatomyQuestionUpdate.as_view(), name="anatomy_question_update"),
|
||||
path("question/<int:pk>/save_annotation", views.question_save_annotation, name="question_save_annotation"),
|
||||
path("question/<int:pk>/answer/",
|
||||
views.answer_question,
|
||||
@@ -29,4 +29,20 @@ urlpatterns = [
|
||||
path("exam/json/<int:pk>/recreate", views.exam_json_recreate, name="exam_json_recreate"),
|
||||
path("cid/<int:pk>/scores", views.cid_scores, name="cid_scores"),
|
||||
path("ajax/exam/flag/", views.flag_question, name="flag_question"),
|
||||
path("body_part/create/", views.create_body_part, name="create_body_part"),
|
||||
path("body_part/ajax/get_body_part_id",
|
||||
views.get_body_part_id,
|
||||
name="get_body_part_id"),
|
||||
path("structure/create/",
|
||||
views.create_structure,
|
||||
name="create_structure"),
|
||||
path("structure/ajax/get_structure_id",
|
||||
views.get_structure_id,
|
||||
name="get_structure_id"),
|
||||
path("examination/create/",
|
||||
views.create_examination,
|
||||
name="create_examination"),
|
||||
path("examination/ajax/get_examination_id",
|
||||
views.get_examination_id,
|
||||
name="get_examination_id"),
|
||||
]
|
||||
|
||||
+83
-10
@@ -21,10 +21,10 @@ from django.http import Http404, JsonResponse
|
||||
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
|
||||
from .forms import AnatomyAnswerForm, AnswerFormSet, MarkAnatomyQuestionForm, AnatomyQuestionForm
|
||||
from .forms import AnatomyAnswerForm, AnswerFormSet, AnswerUpdateFormSet, BodyPartForm, ExaminationForm, MarkAnatomyQuestionForm, AnatomyQuestionForm, StructureForm
|
||||
from .models import (
|
||||
AnatomyQuestion,
|
||||
CidUserAnswer,
|
||||
AnatomyQuestion, BodyPart,
|
||||
CidUserAnswer, Examination, Structure,
|
||||
UserAnswer,
|
||||
Exam,
|
||||
Answer,
|
||||
@@ -828,19 +828,15 @@ class AnatomyQuestionUpdate(LoginRequiredMixin, UpdateView):
|
||||
model = AnatomyQuestion
|
||||
form_class = AnatomyQuestionForm
|
||||
|
||||
# fields = '__all__'
|
||||
# #fields = [ 'condition' ]
|
||||
# #initial = {'date_of_death': '05/01/2018'}
|
||||
# exclude = [ 'created_date', 'published_date' ]
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AnatomyQuestionUpdate, self).get_context_data(**kwargs)
|
||||
if self.request.POST:
|
||||
context['answer_formset'] = AnswerFormSet(self.request.POST,
|
||||
context['answer_formset'] = AnswerUpdateFormSet(self.request.POST,
|
||||
self.request.FILES,
|
||||
instance=self.object)
|
||||
context['answer_formset'].full_clean()
|
||||
else:
|
||||
context['answer_formset'] = AnswerFormSet(instance=self.object)
|
||||
context['answer_formset'] = AnswerUpdateFormSet(instance=self.object)
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
@@ -859,4 +855,81 @@ class AnatomyQuestionUpdate(LoginRequiredMixin, UpdateView):
|
||||
formset.save()
|
||||
return response
|
||||
else:
|
||||
return super().form_invalid(form)
|
||||
return super().form_invalid(form)
|
||||
|
||||
@login_required
|
||||
def create_body_part(request):
|
||||
form = BodyPartForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
instance = form.save()
|
||||
return HttpResponse(
|
||||
'<script>opener.closePopup(window, "%s", "%s", "#id_body_part");</script>'
|
||||
% (instance.pk, instance))
|
||||
return render(request, "anatomy/create_simple.html", {
|
||||
'form': form,
|
||||
'name': "BodyPart"
|
||||
})
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def get_body_part_id(request):
|
||||
if request.is_ajax():
|
||||
body_part_name = request.GET['body_part_name']
|
||||
body_part_id = BodyPart.objects.get(name=body_part_name).id
|
||||
data = {
|
||||
'body_part_id': body_part_id,
|
||||
}
|
||||
return HttpResponse(json.dumps(data), content_type='application/json')
|
||||
return HttpResponse("/")
|
||||
|
||||
|
||||
@login_required
|
||||
def create_examination(request):
|
||||
form = ExaminationForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
instance = form.save()
|
||||
return HttpResponse(
|
||||
'<script>opener.closePopup(window, "%s", "%s", "#id_examination");</script>'
|
||||
% (instance.pk, instance))
|
||||
return render(request, "anatomy/create_simple.html", {
|
||||
'form': form,
|
||||
'name': "Examination"
|
||||
})
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def get_examination_id(request):
|
||||
if request.is_ajax():
|
||||
examination_name = request.GET['examination_name']
|
||||
examination_id = Examination.objects.get(name=examination_name).id
|
||||
data = {
|
||||
'examination_id': examination_id,
|
||||
}
|
||||
return HttpResponse(json.dumps(data), content_type='application/json')
|
||||
return HttpResponse("/")
|
||||
|
||||
|
||||
@login_required
|
||||
def create_structure(request):
|
||||
form = StructureForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
instance = form.save()
|
||||
return HttpResponse(
|
||||
'<script>opener.closePopup(window, "%s", "%s", "#id_structure");</script>'
|
||||
% (instance.pk, instance))
|
||||
return render(request, "anatomy/create_simple.html", {
|
||||
'form': form,
|
||||
'name': "Structure"
|
||||
})
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def get_structure_id(request):
|
||||
if request.is_ajax():
|
||||
structure_name = request.GET['structure_name']
|
||||
structure_id = Structure.objects.get(name=structure_name).id
|
||||
data = {
|
||||
'structure_id': structure_id,
|
||||
}
|
||||
return HttpResponse(json.dumps(data), content_type='application/json')
|
||||
return HttpResponse("/")
|
||||
Reference in New Issue
Block a user