Project

General

Profile

Download (835 Bytes) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / decorators.py @ 78bae9a3

1
from django.contrib.auth.decorators import login_required
2
from django.http import HttpResponseRedirect
3
from functools import wraps
4

    
5
from utils import is_super_user, is_validator
6

    
7
auth_url = '/accounts/login/'
8

    
9

    
10
'''
11
''''''
12
    Decorators to protect views
13
''''''
14
'''
15

    
16
def super_user_only(view_func):
17
    def _wrapped_view(request, *args, **kwargs):
18
        if not is_super_user(request.user):
19
            return HttpResponseRedirect(auth_url)
20
        return view_func(request, *args, **kwargs)
21
    return login_required(wraps(view_func)(_wrapped_view))
22

    
23
def validator_only(view_func):
24
    def _wrapped_view(request, *args, **kwargs):
25
        if not is_validator(request.user):
26
            return HttpResponseRedirect(auth_url)
27
        return view_func(request, *args, **kwargs)
28
    return login_required(wraps(view_func)(_wrapped_view))
(5-5/17)