.
This commit is contained in:
@@ -18,6 +18,8 @@ from django.utils.html import mark_safe
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
|
||||
import string
|
||||
from collections import defaultdict
|
||||
from helpers.images import image_as_base64
|
||||
|
||||
from anatomy.models import Modality
|
||||
|
||||
@@ -303,6 +305,55 @@ class Exam(ExamBase):
|
||||
default=4500,
|
||||
)
|
||||
|
||||
def get_exam_json(self):
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
exam_questions = defaultdict(dict)
|
||||
|
||||
exam_order = []
|
||||
|
||||
for q in questions:
|
||||
exam_order.append(q.id)
|
||||
|
||||
# Loop through longimage associations
|
||||
images = []
|
||||
feedback_images = []
|
||||
for i in q.images.all():
|
||||
if i.feedback_image == True:
|
||||
feedback_images.append(image_as_base64(i.image))
|
||||
# feedback_images.append(i.image.url)
|
||||
else:
|
||||
images.append(image_as_base64(i.image))
|
||||
#images.append(i.image.url)
|
||||
|
||||
|
||||
|
||||
exam_questions[q.id] = {
|
||||
"images": images,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "long",
|
||||
}
|
||||
|
||||
#if feedback_images:
|
||||
# exam_questions[q.id]["feedback_image"] = feedback_images
|
||||
|
||||
|
||||
exam_json = {
|
||||
"eid": "long/{}".format(exam.id),
|
||||
"cached": False,
|
||||
"exam_type": "long",
|
||||
"exam_name": exam.name,
|
||||
"exam_mode": True,
|
||||
"exam_order": exam_order,
|
||||
"questions": exam_questions,
|
||||
}
|
||||
|
||||
|
||||
if exam.time_limit:
|
||||
exam_json["exam_time"] = exam.time_limit
|
||||
|
||||
return exam_json
|
||||
|
||||
class CidUserAnswer(models.Model):
|
||||
"""User answers by candidate"""
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ urlpatterns = [
|
||||
path("exam/submit", views.LongExamViews.postExamAnswers, name="exam_answers_submit"),
|
||||
path("exam/", views.LongExamViews.exam_list, name="exam_list"),
|
||||
path("exam/json/", views.LongExamViews.active_exams, name="active_exams"),
|
||||
path("exam/json/<int:pk>", views.exam_json, name="exam_json"),
|
||||
path("exam/json/<int:pk>", views.LongExamViews.exam_json, name="exam_json"),
|
||||
path(
|
||||
"exam/json/<int:pk>/recreate",
|
||||
views.LongExamViews.exam_json_recreate,
|
||||
|
||||
@@ -796,75 +796,6 @@ def mark(request, pk, sk):
|
||||
)
|
||||
|
||||
|
||||
|
||||
def exam_json(request, pk):
|
||||
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
if not exam.active:
|
||||
raise Http404("No available exam")
|
||||
|
||||
exam_json_cache = cache.get("longs_exam_json_{}".format(pk))
|
||||
|
||||
if exam_json_cache is not None and not exam.recreate_json:
|
||||
exam_json_cache["cached"] = True
|
||||
return JsonResponse(exam_json_cache)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
exam_questions = defaultdict(dict)
|
||||
|
||||
exam_order = []
|
||||
|
||||
for q in questions:
|
||||
exam_order.append(q.id)
|
||||
|
||||
# Loop through longimage associations
|
||||
images = []
|
||||
feedback_images = []
|
||||
for i in q.images.all():
|
||||
if i.feedback_image == True:
|
||||
feedback_images.append(image_as_base64(i.image))
|
||||
# feedback_images.append(i.image.url)
|
||||
else:
|
||||
images.append(image_as_base64(i.image))
|
||||
#images.append(i.image.url)
|
||||
|
||||
|
||||
|
||||
exam_questions[q.id] = {
|
||||
"images": images,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "long",
|
||||
}
|
||||
|
||||
#if feedback_images:
|
||||
# exam_questions[q.id]["feedback_image"] = feedback_images
|
||||
|
||||
|
||||
exam_json = {
|
||||
"eid": "long/{}".format(exam.id),
|
||||
"cached": False,
|
||||
"exam_type": "long",
|
||||
"exam_name": exam.name,
|
||||
"exam_mode": True,
|
||||
"exam_order": exam_order,
|
||||
"questions": exam_questions,
|
||||
}
|
||||
|
||||
|
||||
if exam.time_limit:
|
||||
exam_json["exam_time"] = exam.time_limit
|
||||
|
||||
exam.recreate_json = False
|
||||
exam.save()
|
||||
|
||||
cache.set("longs_exam_json_{}".format(pk), exam_json, 3600)
|
||||
|
||||
return JsonResponse(exam_json)
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_scores_cid(request, pk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
@@ -16,6 +16,8 @@ from django.utils.html import mark_safe
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
|
||||
import string
|
||||
from collections import defaultdict
|
||||
from helpers.images import image_as_base64
|
||||
|
||||
|
||||
from generic.models import Site, Condition, Sign, ExamBase
|
||||
@@ -350,6 +352,55 @@ class Exam(ExamBase):
|
||||
help_text="Exam time limit (in seconds). Default is 2100 secondse (35 minutes)", default=2100
|
||||
)
|
||||
|
||||
def get_exam_json(self):
|
||||
questions = self.exam_questions.all()
|
||||
|
||||
exam_questions = defaultdict(dict)
|
||||
|
||||
exam_order = []
|
||||
|
||||
for q in questions:
|
||||
exam_order.append(q.id)
|
||||
|
||||
# Loop through rapidimage associations
|
||||
images = []
|
||||
feedback_images = []
|
||||
for i in q.images.all():
|
||||
if i.feedback_image == True:
|
||||
feedback_images.append(image_as_base64(i.image))
|
||||
# feedback_images.append(i.image.url)
|
||||
else:
|
||||
images.append(image_as_base64(i.image))
|
||||
#images.append(i.image.url)
|
||||
|
||||
|
||||
|
||||
exam_questions[q.id] = {
|
||||
"images": images,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "rapid",
|
||||
}
|
||||
|
||||
#if feedback_images:
|
||||
# exam_questions[q.id]["feedback_image"] = feedback_images
|
||||
|
||||
|
||||
exam_json = {
|
||||
"eid": "rapid/{}".format(exam.id),
|
||||
"cached": False,
|
||||
"exam_type": "rapid",
|
||||
"exam_name": exam.name,
|
||||
"exam_mode": True,
|
||||
"exam_order": exam_order,
|
||||
"questions": exam_questions,
|
||||
}
|
||||
|
||||
if exam.time_limit:
|
||||
exam_json["exam_time"] = exam.time_limit
|
||||
|
||||
return
|
||||
|
||||
|
||||
class CidUserAnswer(models.Model):
|
||||
"""User answers by candidate"""
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ urlpatterns = [
|
||||
path("exam/submit", views.RapidExamViews.postExamAnswers, name="exam_answers_submit"),
|
||||
path("exam/", views.RapidExamViews.exam_list, name="exam_list"),
|
||||
path("exam/json/", views.RapidExamViews.active_exams, name="active_exams"),
|
||||
path("exam/json/<int:pk>", views.exam_json, name="exam_json"),
|
||||
path("exam/json/<int:pk>", views.RapidExamViews.exam_json, name="exam_json"),
|
||||
path("exam/json/<int:pk>/recreate", views.RapidExamViews.exam_json_recreate, name="exam_json_recreate"),
|
||||
path("create/", views.RapidCreate.as_view(), name="rapid_create"),
|
||||
path("create/defaults",
|
||||
|
||||
@@ -699,73 +699,6 @@ def mark(request, pk, sk):
|
||||
)
|
||||
|
||||
|
||||
def exam_json(request, pk):
|
||||
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
if not exam.active:
|
||||
raise Http404("No available exam")
|
||||
|
||||
exam_json_cache = cache.get("rapids_exam_json_{}".format(pk))
|
||||
|
||||
if exam_json_cache is not None and not exam.recreate_json:
|
||||
exam_json_cache["cached"] = True
|
||||
return JsonResponse(exam_json_cache)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
exam_questions = defaultdict(dict)
|
||||
|
||||
exam_order = []
|
||||
|
||||
for q in questions:
|
||||
exam_order.append(q.id)
|
||||
|
||||
# Loop through rapidimage associations
|
||||
images = []
|
||||
feedback_images = []
|
||||
for i in q.images.all():
|
||||
if i.feedback_image == True:
|
||||
feedback_images.append(image_as_base64(i.image))
|
||||
# feedback_images.append(i.image.url)
|
||||
else:
|
||||
images.append(image_as_base64(i.image))
|
||||
#images.append(i.image.url)
|
||||
|
||||
|
||||
|
||||
exam_questions[q.id] = {
|
||||
"images": images,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "rapid",
|
||||
}
|
||||
|
||||
#if feedback_images:
|
||||
# exam_questions[q.id]["feedback_image"] = feedback_images
|
||||
|
||||
|
||||
exam_json = {
|
||||
"eid": "rapid/{}".format(exam.id),
|
||||
"cached": False,
|
||||
"exam_type": "rapid",
|
||||
"exam_name": exam.name,
|
||||
"exam_mode": True,
|
||||
"exam_order": exam_order,
|
||||
"questions": exam_questions,
|
||||
}
|
||||
|
||||
if exam.time_limit:
|
||||
exam_json["exam_time"] = exam.time_limit
|
||||
|
||||
exam.recreate_json = False
|
||||
exam.save()
|
||||
|
||||
cache.set("rapids_exam_json_{}".format(pk), exam_json, 3600)
|
||||
|
||||
return JsonResponse(exam_json)
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_scores_cid(request, pk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
Reference in New Issue
Block a user