.
This commit is contained in:
@@ -369,6 +369,9 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||||
|
|
||||||
def exam_json_unbased(self, request, pk):
|
def exam_json_unbased(self, request, pk):
|
||||||
|
"""
|
||||||
|
No (file based) caching is enabled for unbased exams
|
||||||
|
"""
|
||||||
exam = get_object_or_404(self.Exam, pk=pk)
|
exam = get_object_or_404(self.Exam, pk=pk)
|
||||||
|
|
||||||
if not exam.active:
|
if not exam.active:
|
||||||
|
|||||||
+31
-1
@@ -169,10 +169,40 @@ class Long(models.Model):
|
|||||||
answers = self.cid_user_answers.all()
|
answers = self.cid_user_answers.all()
|
||||||
return [ans for ans in answers if not ans.is_marked()]
|
return [ans for ans in answers if not ans.is_marked()]
|
||||||
|
|
||||||
def get_json(self, question_id):
|
def get_json(self, question_id, based=True):
|
||||||
# self == q?
|
# self == q?
|
||||||
q = get_object_or_404(Long, pk=question_id)
|
q = get_object_or_404(Long, pk=question_id)
|
||||||
|
|
||||||
|
|
||||||
|
if not based:
|
||||||
|
image_titles = []
|
||||||
|
images = []
|
||||||
|
question_series = q.series.all()
|
||||||
|
# Loop through longimage associations
|
||||||
|
for i, series in enumerate(question_series):
|
||||||
|
#image_array = []
|
||||||
|
#for i in series.images.all():
|
||||||
|
# image_array.append(image_as_base64(i.image))
|
||||||
|
# #image_array.append(i.image.url)
|
||||||
|
|
||||||
|
# We are still limited by the size of a series (although this should not be too big or computers will crash...)
|
||||||
|
images.append([i.image for i in series.images.all()])
|
||||||
|
#image_array = [i.image.url for i in series.images.all()]
|
||||||
|
#images.append(url)
|
||||||
|
image_titles.append(series.get_examination())
|
||||||
|
|
||||||
|
question_json = {
|
||||||
|
"title": q.history,
|
||||||
|
"images": images,
|
||||||
|
"image_titles": image_titles,
|
||||||
|
#"feedback_image": [],
|
||||||
|
#"annotations": [str(q.image_annotations)],
|
||||||
|
"type": "long",
|
||||||
|
"cached": False,
|
||||||
|
}
|
||||||
|
return question_json
|
||||||
|
|
||||||
|
|
||||||
#exam_order.append(q.id)
|
#exam_order.append(q.id)
|
||||||
path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, question_id)
|
path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, question_id)
|
||||||
url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, question_id)
|
url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, question_id)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ urlpatterns = [
|
|||||||
# path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
|
# path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
|
||||||
path("question/<int:pk>/", views.question_detail, name="question_detail"),
|
path("question/<int:pk>/", views.question_detail, name="question_detail"),
|
||||||
path("question/<int:pk>/json", views.question_json, name="question_json"),
|
path("question/<int:pk>/json", views.question_json, name="question_json"),
|
||||||
|
path("question/<int:pk>/json/unbased", views.question_json_unbased, name="question_json_unbased"),
|
||||||
path("question/<int:pk>/json/recreate", views.question_json_recreate, name="question_json_recreate"),
|
path("question/<int:pk>/json/recreate", views.question_json_recreate, name="question_json_recreate"),
|
||||||
path("question/<int:pk>/split", views.long_split, name="long_split"),
|
path("question/<int:pk>/split", views.long_split, name="long_split"),
|
||||||
path("question/<int:pk>/clone", views.LongClone.as_view(), name="long_clone"),
|
path("question/<int:pk>/clone", views.LongClone.as_view(), name="long_clone"),
|
||||||
|
|||||||
@@ -988,6 +988,14 @@ class ExamViewSet(viewsets.ModelViewSet):
|
|||||||
queryset = Exam.objects.all().order_by('name')
|
queryset = Exam.objects.all().order_by('name')
|
||||||
serializer_class = ExamSerializer
|
serializer_class = ExamSerializer
|
||||||
|
|
||||||
|
def question_json_unbased(self, request, pk):
|
||||||
|
"""
|
||||||
|
No (file based) caching is enabled for unbased quesitons
|
||||||
|
"""
|
||||||
|
question = get_object_or_404(self.Exam, pk=pk)
|
||||||
|
|
||||||
|
question_json = question.get_json(pk, based=False)
|
||||||
|
return JsonResponse(question_json)
|
||||||
|
|
||||||
def question_json(request, pk):
|
def question_json(request, pk):
|
||||||
question = get_object_or_404(Long, pk=pk)
|
question = get_object_or_404(Long, pk=pk)
|
||||||
|
|||||||
Reference in New Issue
Block a user