.
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.http.response import JsonResponse
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
import tagulous
|
import tagulous
|
||||||
import tagulous.models
|
import tagulous.models
|
||||||
@@ -333,6 +335,40 @@ class Rapid(models.Model):
|
|||||||
new_answers = [a for a in answers if get_answer_compare(a) not in compare_answers]
|
new_answers = [a for a in answers if get_answer_compare(a) not in compare_answers]
|
||||||
|
|
||||||
return new_answers
|
return new_answers
|
||||||
|
|
||||||
|
def get_question_json(self, based=True):
|
||||||
|
"""Returns json"""
|
||||||
|
|
||||||
|
# Loop through rapidimage associations
|
||||||
|
images = []
|
||||||
|
feedback_images = []
|
||||||
|
for i in self.images.all():
|
||||||
|
if i.feedback_image == True:
|
||||||
|
if based:
|
||||||
|
feedback_images.append(image_as_base64(i.image))
|
||||||
|
else:
|
||||||
|
feedback_images.append("{}/{}".format(settings.REMOTE_URL, i.image.url))
|
||||||
|
else:
|
||||||
|
if based:
|
||||||
|
images.append(image_as_base64(i.image))
|
||||||
|
else:
|
||||||
|
images.append("{}/{}".format(settings.REMOTE_URL, i.image.url))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
json = {
|
||||||
|
"images": images,
|
||||||
|
#"feedback_image": [],
|
||||||
|
#"annotations": [str(q.image_annotations)],
|
||||||
|
"type": "rapid",
|
||||||
|
}
|
||||||
|
|
||||||
|
if not self.exam_mode:
|
||||||
|
json["normal"] = self.normal
|
||||||
|
json["feedback_images"] = feedback_images
|
||||||
|
json["answers"] = list(self.get_correct_unstripped_answers())
|
||||||
|
|
||||||
|
return json
|
||||||
|
|
||||||
|
|
||||||
#reversion.register(Rapid, follow=["images"])
|
#reversion.register(Rapid, follow=["images"])
|
||||||
@@ -594,3 +630,12 @@ class CidUserAnswer(models.Model):
|
|||||||
else:
|
else:
|
||||||
mark = "unmarked"
|
mark = "unmarked"
|
||||||
return mark
|
return mark
|
||||||
|
|
||||||
|
def question_json_unbased(request, pk):
|
||||||
|
"""
|
||||||
|
No (file based) caching is enabled for unbased quesitons
|
||||||
|
"""
|
||||||
|
question = get_object_or_404(Rapid, pk=pk)
|
||||||
|
|
||||||
|
question_json = question.get_question_json(based=False)
|
||||||
|
return JsonResponse(question_json)
|
||||||
@@ -12,6 +12,12 @@ urlpatterns = [
|
|||||||
# path("unchecked/", views.unchecked_list, name="unchecked_list"),
|
# path("unchecked/", views.unchecked_list, name="unchecked_list"),
|
||||||
# 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/unbased",
|
||||||
|
views.question_json_unbased,
|
||||||
|
name="question_json_unbased",
|
||||||
|
),
|
||||||
path("question/<int:pk>/split", views.rapid_split, name="rapid_split"),
|
path("question/<int:pk>/split", views.rapid_split, name="rapid_split"),
|
||||||
path("question/<int:pk>/clone", views.RapidClone.as_view(), name="rapid_clone"),
|
path("question/<int:pk>/clone", views.RapidClone.as_view(), name="rapid_clone"),
|
||||||
# path("verified/", views.verified, name="verified"),
|
# path("verified/", views.verified, name="verified"),
|
||||||
|
|||||||
Reference in New Issue
Block a user