.
This commit is contained in:
@@ -57,6 +57,7 @@ urlpatterns = [
|
||||
#path('', include('generic.urls')),
|
||||
path("feedback/<str:question_type>/<int:pk>", views.AddQuestionNote.as_view(), name="feedback_create"),
|
||||
#path("feedback/", views.AddQuestionNote.as_view(), name="feedback"),
|
||||
path("feedback/answer", views.answer_suggestion_submit, name="answer_suggestion_submit"),
|
||||
|
||||
|
||||
path('api/', include(router.urls)),
|
||||
|
||||
+37
-1
@@ -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"})
|
||||
Reference in New Issue
Block a user