.
This commit is contained in:
+36
-26
@@ -58,6 +58,7 @@ import json
|
||||
|
||||
from django.template import RequestContext
|
||||
|
||||
|
||||
def feedback_checker(user):
|
||||
return user.groups.filter(name="feedback_checker").exists()
|
||||
|
||||
@@ -101,7 +102,7 @@ def cid_scores(request, pk):
|
||||
|
||||
if request.user.groups.filter(name="view_all_results").exists():
|
||||
kwargs = {}
|
||||
|
||||
|
||||
physics_exam_ids = physics_answers.values_list("exam").distinct()
|
||||
physics_exams = PhysicsExam.objects.filter(id__in=physics_exam_ids, **kwargs)
|
||||
|
||||
@@ -109,13 +110,13 @@ def cid_scores(request, pk):
|
||||
anatomy_exams = AnatomyExam.objects.filter(id__in=anatomy_exam_ids, **kwargs)
|
||||
|
||||
rapids_exam_ids = rapids_answers.values_list("exam").distinct()
|
||||
rapids_exams = RapidsExam.objects.filter(id__in=rapids_exam_ids, **kwargs)
|
||||
rapid_exams = RapidsExam.objects.filter(id__in=rapids_exam_ids, **kwargs)
|
||||
|
||||
longs_exam_ids = longs_answers.values_list("exam").distinct()
|
||||
longs_exams = LongsExam.objects.filter(id__in=longs_exam_ids, **kwargs)
|
||||
|
||||
sbas_exam_ids = sbas_answers.values_list("exam").distinct()
|
||||
sbas_exams = SbasExam.objects.filter(id__in=sbas_exam_ids, **kwargs)
|
||||
sba_exams = SbasExam.objects.filter(id__in=sbas_exam_ids, **kwargs)
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -123,9 +124,9 @@ def cid_scores(request, pk):
|
||||
{
|
||||
"physics_exams": physics_exams,
|
||||
"anatomy_exams": anatomy_exams,
|
||||
"rapids_exams": rapids_exams,
|
||||
"rapid_exams": rapid_exams,
|
||||
"longs_exams": longs_exams,
|
||||
"sbas_exams": sbas_exams,
|
||||
"sba_exams": sba_exams,
|
||||
"cid": cid,
|
||||
},
|
||||
)
|
||||
@@ -150,6 +151,7 @@ def active_exams(request):
|
||||
|
||||
return JsonResponse(active_exams)
|
||||
|
||||
|
||||
def active_exams_unbased(request):
|
||||
anatomy_exams = AnatomyExamViews.active_exams(request, False, False)
|
||||
rapid_exams = RapidExamViews.active_exams(request, False, False)
|
||||
@@ -181,6 +183,7 @@ def exam_submit(request):
|
||||
# postExamAnswers
|
||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||
|
||||
|
||||
def feedback_create(request, question_type, pk):
|
||||
if question_type == "anatomy":
|
||||
question = AnatomyQuestion
|
||||
@@ -192,13 +195,11 @@ def feedback_create(request, question_type, pk):
|
||||
return JsonResponse({"success": False, "error": "Invalid exam type"})
|
||||
|
||||
|
||||
|
||||
class AddQuestionNote(CreateView):
|
||||
model = QuestionNote
|
||||
form_class = QuestionNoteForm
|
||||
|
||||
#fields = ("author", "note_type", "note")
|
||||
|
||||
# fields = ("author", "note_type", "note")
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddQuestionNote, self).get_form_kwargs()
|
||||
@@ -210,18 +211,17 @@ class AddQuestionNote(CreateView):
|
||||
def get_initial(self):
|
||||
pk = self.kwargs["pk"]
|
||||
self.question_type = self.kwargs["question_type"]
|
||||
|
||||
|
||||
question, content_type = get_question_and_content_type(self.question_type)
|
||||
|
||||
|
||||
self.question = get_object_or_404(question, pk=pk)
|
||||
return { "content_type" : content_type,
|
||||
"object_id" : pk }
|
||||
return {"content_type": content_type, "object_id": pk}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
# This can also be accessed via view.**** in the template
|
||||
context = super(AddQuestionNote, self).get_context_data(**kwargs)
|
||||
context['question'] = self.question
|
||||
context['question_type'] = self.question_type
|
||||
context["question"] = self.question
|
||||
context["question_type"] = self.question_type
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
@@ -237,6 +237,7 @@ class AddQuestionNote(CreateView):
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
def feedback_note_delete(request, pk):
|
||||
q = get_object_or_404(QuestionNote, pk=pk)
|
||||
@@ -244,17 +245,22 @@ def feedback_note_delete(request, pk):
|
||||
|
||||
return redirect(q.get_object_url())
|
||||
|
||||
|
||||
@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():
|
||||
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":
|
||||
@@ -274,12 +280,11 @@ def answer_suggestion_submit(request):
|
||||
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, proposed=True)
|
||||
a.save()
|
||||
return JsonResponse({"success": True, "error": "Answer submited"})
|
||||
@@ -287,6 +292,7 @@ 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":
|
||||
@@ -306,18 +312,18 @@ def answer_submit(request):
|
||||
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": True, "error": "Answer added"})
|
||||
|
||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||
|
||||
|
||||
@login_required
|
||||
def answer_suggestion_confirm(request):
|
||||
if request.is_ajax and request.method == "POST":
|
||||
@@ -340,6 +346,7 @@ def answer_suggestion_confirm(request):
|
||||
answer.save()
|
||||
return JsonResponse({"success": True, "error": "Answer changed"})
|
||||
|
||||
|
||||
@login_required
|
||||
@user_passes_test(feedback_checker)
|
||||
def view_feedback(request):
|
||||
@@ -355,24 +362,27 @@ def view_feedback(request):
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# HTTP Error 400
|
||||
def page_not_found(request, exception):
|
||||
response = render(request, '404.html', {})
|
||||
response = render(request, "404.html", {})
|
||||
|
||||
#response.status_code = 404
|
||||
# response.status_code = 404
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def page_forbidden(request, exception):
|
||||
response = render(request, '403.html', {})
|
||||
response = render(request, "403.html", {})
|
||||
|
||||
#response.status_code = 404
|
||||
# response.status_code = 404
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def server_error(request):
|
||||
response = render(request, '500.html', {})
|
||||
response = render(request, "500.html", {})
|
||||
|
||||
#response.status_code = 404
|
||||
# response.status_code = 404
|
||||
|
||||
return response
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user