fix #1429
[auf_rh_dae.git] / project / decorators.py
CommitLineData
e993f3dc 1# -*- encoding: utf-8 -*-
2"""
3Décorateurs AUF
4"""
5from django.contrib.auth.decorators import user_passes_test
6from django.core.urlresolvers import reverse
7from django.http import HttpResponseRedirect
e993f3dc 8from permissions import is_employe, is_admin
9
10# Décorateurs des fonctions dans views (pour tester permissions dans views)
11
12def 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 :
f8daa167
OL
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)
e993f3dc 25 return inner