.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user