.
This commit is contained in:
+10
-10
@@ -1,13 +1,13 @@
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from .models import ExamBase
|
||||
|
||||
def user_is_exam_author_or_exam_checker(function):
|
||||
def wrap(request, *args, **kwargs):
|
||||
exam = Exam.objects.get(pk=kwargs['pk'])
|
||||
if request.user in exam.author.all() or request.user.groups.filter(name='exam_checker').exists():
|
||||
return function(request, *args, **kwargs)
|
||||
else:
|
||||
raise PermissionDenied
|
||||
wrap.__doc__ = function.__doc__
|
||||
#wrap.__name__ = function.__name__
|
||||
return wrap
|
||||
#def user_is_exam_author_or_exam_checker(function):
|
||||
# def wrap(request, *args, **kwargs):
|
||||
# exam = Exam.objects.get(pk=kwargs['pk'])
|
||||
# if request.user in exam.author.all() or request.user.groups.filter(name='exam_checker').exists():
|
||||
# return function(request, *args, **kwargs)
|
||||
# else:
|
||||
# raise PermissionDenied
|
||||
# wrap.__doc__ = function.__doc__
|
||||
# #wrap.__name__ = function.__name__
|
||||
# return wrap
|
||||
+3
-1
@@ -204,13 +204,15 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
|
||||
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(user_is_exam_author_or_exam_checker)
|
||||
def exam_overview(self, request, pk):
|
||||
#print(Exam.objects.all())
|
||||
#exams = Exam.objects.all()
|
||||
#print("test", Exam.objects.all().get(id=pk))
|
||||
exam = get_object_or_404(self.Exam, pk=pk)
|
||||
|
||||
if not (request.user in exam.author.all() or request.user.groups.filter(name='rapid_checker').exists()):
|
||||
raise PermissionDenied
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
question_number = len(questions)
|
||||
|
||||
Reference in New Issue
Block a user