Files
penracourses/physics/decorators.py
T
Ross 8b78466925 .
2021-09-30 22:56:59 +01:00

25 lines
986 B
Python
Executable File

from django.core.exceptions import PermissionDenied
from .models import Exam, Question
def user_is_author_or_physics_checker(function):
def wrap(request, *args, **kwargs):
question = Question.objects.get(pk=kwargs['pk'])
if request.user in question.author.all() or request.user.groups.filter(name='physics_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_physics_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='physics_checker').exists():
return function(request, *args, **kwargs)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap