.
This commit is contained in:
+37
-14
@@ -1,3 +1,4 @@
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django import forms
|
||||
@@ -23,7 +24,7 @@ from django.http import Http404, JsonResponse
|
||||
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
|
||||
from physics.models import CidUserAnswer as PhysicsCidUserAnswer
|
||||
from physics.models import CidUserAnswer as PhysicsCidUserAnswer, Question
|
||||
from physics.models import Exam as PhysicsExam
|
||||
|
||||
from anatomy.models import CidUserAnswer as AnatomyCidUserAnswer
|
||||
@@ -48,6 +49,9 @@ from generic.models import QuestionNote
|
||||
|
||||
import json
|
||||
|
||||
def feedback_checker(user):
|
||||
return user.groups.filter(name="feedback_checker").exists()
|
||||
|
||||
|
||||
@login_required
|
||||
def profile(request):
|
||||
@@ -162,6 +166,22 @@ def feedback_create(request, question_type, pk):
|
||||
|
||||
return JsonResponse({"success": False, "error": "Invalid exam type"})
|
||||
|
||||
def get_question_and_content_type(pk, question_type):
|
||||
if question_type == "rapid":
|
||||
question = Rapid
|
||||
content_type = ContentType.objects.get(model="rapid")
|
||||
elif question_type == "anatomy":
|
||||
question = AnatomyQuestion
|
||||
content_type = ContentType.objects.get(model="anatomyquestion")
|
||||
elif question_type == "long":
|
||||
question = Long
|
||||
content_type = ContentType.objects.get(model="long")
|
||||
else:
|
||||
raise PermissionError()
|
||||
|
||||
return question, content_type
|
||||
|
||||
|
||||
class AddQuestionNote(CreateView):
|
||||
model = QuestionNote
|
||||
form_class = QuestionNoteForm
|
||||
@@ -178,22 +198,24 @@ class AddQuestionNote(CreateView):
|
||||
def get_initial(self):
|
||||
pk = self.kwargs["pk"]
|
||||
question_type = self.kwargs["question_type"]
|
||||
if question_type == "rapid":
|
||||
question = Rapid
|
||||
content_type = ContentType.objects.get(model="rapid")
|
||||
elif question_type == "anatomy":
|
||||
question = AnatomyQuestion
|
||||
content_type = ContentType.objects.get(model="anatomyquestion")
|
||||
elif question_type == "long":
|
||||
question = Long
|
||||
content_type = ContentType.objects.get(model="long")
|
||||
else:
|
||||
raise PermissionError()
|
||||
|
||||
question, content_type = get_question_and_content_type(pk, question_type)
|
||||
|
||||
get_object_or_404(question, pk=pk)
|
||||
return { "content_type" : content_type,
|
||||
"object_id" : pk }
|
||||
|
||||
@login_required
|
||||
def feedback_mark_complete(request, pk):
|
||||
q = get_object_or_404(QuestionNote, pk=pk)
|
||||
|
||||
if request.user not in q.question.author.all() and not request.user.groups.filter(name="feedback_checker").exists():
|
||||
raise PermissionDenied()
|
||||
|
||||
q.complete = True
|
||||
q.save()
|
||||
return redirect(q.get_object_url())
|
||||
|
||||
@csrf_exempt
|
||||
def answer_suggestion_submit(request):
|
||||
if request.is_ajax and request.method == "POST":
|
||||
@@ -249,10 +271,11 @@ def answer_suggestion_confirm(request):
|
||||
return JsonResponse({"success": True, "error": "Answer changed"})
|
||||
|
||||
@login_required
|
||||
def view_feedback(request, pk):
|
||||
@user_passes_test(feedback_checker)
|
||||
def view_feedback(request):
|
||||
# exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
feedback_notes = QuestionNote.objects.all()
|
||||
feedback_notes = QuestionNote.objects.filter(complete=False)
|
||||
|
||||
return render(
|
||||
request,
|
||||
|
||||
Reference in New Issue
Block a user