fix #1429
[auf_rh_dae.git] / project / decorators.py
1 # -*- encoding: utf-8 -*-
2 """
3 Décorateurs AUF
4 """
5 from django.contrib.auth.decorators import user_passes_test
6 from django.core.urlresolvers import reverse
7 from django.http import HttpResponseRedirect
8 from permissions import is_employe, is_admin
9
10 # Décorateurs des fonctions dans views (pour tester permissions dans views)
11
12 def admin_required(fn):
13 def inner(request, *args, **kwargs):
14 user = request.user
15 if is_admin(user):
16 return fn(request, *args, **kwargs)
17 else :
18 from django.conf import settings
19 from django.contrib.auth import REDIRECT_FIELD_NAME
20 from django.utils.http import urlquote
21 login_url = settings.LOGIN_URL
22 path = urlquote(request.get_full_path())
23 tup = login_url, REDIRECT_FIELD_NAME, path
24 return HttpResponseRedirect('%s?%s=%s' % tup)
25 return inner