.
This commit is contained in:
@@ -163,6 +163,37 @@ class Long(models.Model):
|
||||
answers = self.cid_user_answers.all()
|
||||
return [ans for ans in answers if not ans.is_marked()]
|
||||
|
||||
def get_json(self, question_id):
|
||||
q = get_object_or_404(Long, pk=question_id)
|
||||
|
||||
#exam_order.append(q.id)
|
||||
|
||||
# Loop through longimage associations
|
||||
images = []
|
||||
image_titles = []
|
||||
for series in q.series.all():
|
||||
#image_array = []
|
||||
#for i in series.images.all():
|
||||
# image_array.append(image_as_base64(i.image))
|
||||
# #image_array.append(i.image.url)
|
||||
image_array = [image_as_base64(i.image) for i in series.images.all()]
|
||||
images.append(image_array)
|
||||
image_titles.append(series.get_examination())
|
||||
|
||||
|
||||
|
||||
exam_question = {
|
||||
"title": q.history,
|
||||
"images": images,
|
||||
"image_titles": image_titles,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "long",
|
||||
}
|
||||
|
||||
return exam_question
|
||||
|
||||
|
||||
|
||||
# def GetNonFeedbackQuestionImages(self):
|
||||
# return self.GetImages()
|
||||
|
||||
+21
-1
@@ -966,4 +966,24 @@ LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer)
|
||||
|
||||
class ExamViewSet(viewsets.ModelViewSet):
|
||||
queryset = Exam.objects.all().order_by('name')
|
||||
serializer_class = ExamSerializer
|
||||
serializer_class = ExamSerializer
|
||||
|
||||
|
||||
def question_json(self, request, pk):
|
||||
question = get_object_or_404(self.Question, pk=pk)
|
||||
#exam = get_object_or_404(self.Exam, pk=pk)
|
||||
|
||||
#if not exam.active:
|
||||
# raise Http404("No available exam")
|
||||
|
||||
question_json_cache = cache.get("{}_question_json_{}".format("longs", sk))
|
||||
|
||||
if question_json_cache is not None and not question.recreate_json:
|
||||
question_json_cache["cached"] = True
|
||||
return JsonResponse(question_json_cache)
|
||||
|
||||
question_json = question.get_json(pk)
|
||||
|
||||
cache.set("{}_question_json_{}".format("longs", pk), question_json, 3600)
|
||||
|
||||
return JsonResponse(question_json)
|
||||
Reference in New Issue
Block a user