Verified Commit 3ce929b2 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Add membership decorator and require an active membership to download exams/summaries

parent dc43cab9
......@@ -32,6 +32,14 @@ members\.apps module
:undoc-members:
:show-inheritance:
members\.decorators module
--------------------------
.. automodule:: members.decorators
:members:
:undoc-members:
:show-inheritance:
members\.emails module
----------------------
......
......@@ -9,6 +9,7 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from sendfile import sendfile
from members.decorators import membership_required
from .forms import AddExamForm, AddSummaryForm
from .models import Category, Course, Exam, Summary
......@@ -52,6 +53,7 @@ def student_participation(request):
@login_required
@membership_required
def exam(request, id):
exam = get_object_or_404(Exam, id=int(id))
......@@ -65,6 +67,7 @@ def exam(request, id):
@login_required
@membership_required
def summary(request, id):
obj = get_object_or_404(Summary, id=int(id))
......
from django.core.exceptions import PermissionDenied
def membership_required(view_function):
return ActiveMembershipRequired(view_function)
class ActiveMembershipRequired(object):
def __init__(self, view_function):
self.view_function = view_function
def __call__(self, request, *args, **kwargs):
if request.member and request.member.has_active_membership():
return self.view_function(request, *args, **kwargs)
raise PermissionDenied
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment