This commit is contained in:
Ross
2021-01-03 16:44:56 +00:00
parent 166843a611
commit 2205bd4dfe
4 changed files with 59 additions and 30 deletions
+11 -28
View File
@@ -317,38 +317,21 @@ def loadJsonAnswer(answer):
return True
def exam_json_edit(request):
if request.is_ajax and request.method == "POST":
def exam_json_edit(request, pk):
if request.is_ajax() and request.method == "POST":
n = 0
# horrible but it works
for k in request.POST.dict():
print(k)
for answer in json.loads(k):
if not "exam" in answer:
return JsonResponse({"success": False})
exam = get_object_or_404(Exam, pk=pk)
exam = get_object_or_404(answer["exam"])
for q in exam.exam_questions.all():
q.open_acess = request.POST.get("set_open_access")
q.save()
if "set_open_access" in answer:
#answer["set_open_access"]
for q in exam.exam_questions.all():
q.open_acess = answer["set_open_access"]
q.save()
data = {"status": "success"}
return JsonResponse(data, status=200)
else:
data = {"status": "error"}
return JsonResponse(data, status=400)
return JsonResponse({"success": True})
if ret is not True:
return ret
n = n + 1
# print(UserAnswer.objects.filter(exam__id=q["eid"]))
# print(request.urlencode())
return JsonResponse({"success": True, "question_count": n})
return JsonResponse({"success": False, "error": "Invalid data"})
@csrf_exempt
def postExamAnswers(request):