.
This commit is contained in:
@@ -60,6 +60,7 @@ urlpatterns = [
|
||||
path("feedback/note/<int:pk>/complete", views.feedback_mark_complete, name="feedback_mark_complete"),
|
||||
#path("feedback/", views.AddQuestionNote.as_view(), name="feedback"),
|
||||
path("feedback/answer", views.answer_suggestion_submit, name="answer_suggestion_submit"),
|
||||
path("feedback/answer_submit", views.answer_submit, name="answer_submit"),
|
||||
path("feedback/answer/confirm", views.answer_suggestion_confirm, name="answer_suggestion_confirm"),
|
||||
path("feedback/view", views.view_feedback, name="view_feedback"),
|
||||
|
||||
|
||||
@@ -248,6 +248,37 @@ def answer_suggestion_submit(request):
|
||||
# postExamAnswers
|
||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||
|
||||
@login_required
|
||||
def answer_submit(request):
|
||||
if request.is_ajax and request.method == "POST":
|
||||
post_data = json.loads(request.body)
|
||||
qid = post_data["qid"]
|
||||
question_type = post_data["question_type"]
|
||||
answer_string = post_data["answer"]
|
||||
status = post_data["status"]
|
||||
|
||||
if str(status) not in "012":
|
||||
return JsonResponse({"success": False, "error": "Invalid status"})
|
||||
|
||||
if question_type == "anatomy":
|
||||
AnswerModel = AnatomyAnswer
|
||||
question = AnatomyQuestion
|
||||
elif question_type == "rapid":
|
||||
AnswerModel = RapidAnswer
|
||||
question = Rapid
|
||||
else:
|
||||
return JsonResponse({"success": False, "error": "Invalid question type"})
|
||||
|
||||
q = get_object_or_404(question, pk=qid)
|
||||
if AnswerModel.objects.filter(answer=answer_string, question=q):
|
||||
return JsonResponse({"success": False, "error": "Answer already exists"})
|
||||
|
||||
|
||||
a = AnswerModel(question=q, answer=answer_string, status=status)
|
||||
a.save()
|
||||
|
||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||
|
||||
@login_required
|
||||
def answer_suggestion_confirm(request):
|
||||
if request.is_ajax and request.method == "POST":
|
||||
|
||||
Reference in New Issue
Block a user