This commit is contained in:
Ross
2021-05-06 21:26:02 +01:00
parent 9c4844acde
commit 3e5afc4f38
5 changed files with 55 additions and 12 deletions
+37 -1
View File
@@ -29,10 +29,12 @@ from physics.models import Exam as PhysicsExam
from anatomy.models import CidUserAnswer as AnatomyCidUserAnswer
from anatomy.models import Exam as AnatomyExam
from anatomy.models import AnatomyQuestion
from anatomy.models import Answer as AnatomyAnswer
from rapids.models import CidUserAnswer as RapidsCidUserAnswer
from rapids.models import Exam as RapidsExam
from rapids.models import Rapid
from rapids.models import Answer as RapidAnswer
from longs.models import CidUserAnswer as LongsCidUserAnswer
from longs.models import Exam as LongsExam
@@ -44,6 +46,8 @@ from longs.views import LongExamViews
from generic.forms import QuestionNoteForm
from generic.models import QuestionNote
import json
@login_required
def profile(request):
@@ -188,4 +192,36 @@ class AddQuestionNote(CreateView):
get_object_or_404(question, pk=pk)
return { "content_type" : content_type,
"object_id" : pk }
"object_id" : pk }
@csrf_exempt
def answer_suggestion_submit(request):
if request.is_ajax and request.method == "POST":
j = json.loads(request.body.decode())
question_type, qid = j["qid"].split("/")
answer_string = j["answer"]
status = j["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"})
if AnswerModel.objects.filter(answer=answer_string):
return JsonResponse({"success": False, "error": "Answer already exists"})
q = get_object_or_404(question, pk=qid)
a = AnswerModel(question=q, answer=answer_string, status=status, proposed=True)
a.save()
return JsonResponse({"success": True, "error": "Answer submited"})
# postExamAnswers
return JsonResponse({"success": False, "error": "Invalid data"})