Suppression prints de debug
[auf_references_client.git] / auf_references_client / decorators.py
1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*-
3
4 from django.http import HttpResponseForbidden
5 from django.contrib.auth import logout
6 from django.template.loader import get_template
7 from django.template import Context
8 from django.conf import settings
9
10 from auf_references_modeles import Utilisateur, GroupesPersonne
11
12 import sys, traceback
13
14 def has_group(group = ""):
15 def _dec(view_func):
16 def _view(request, *args, **kwargs):
17 allowed = False
18 if request.user.is_authenticated():
19 try:
20 p = Utilisateur.objects.get(courriel = request.user.email)
21 #g = Groupe.objects.get(nom = group)
22 for g in GroupesPersonne.objects.filter(personne__pk = p.pk):
23 if g.groupe.nom == group:
24 allowed = True
25 break
26 except:
27 pass
28 else:
29 allowed = True
30
31 if allowed:
32 r = view_func(request, *args, **kwargs)
33 else:
34 logout(request)
35 t = get_template('references_403.html')
36 html = t.render(Context({}))
37 r = HttpResponseForbidden(html)
38
39 return r
40
41 _view.__name__ = view_func.__name__
42 _view.__dict__ = view_func.__dict__
43 _view.__doc__ = view_func.__doc__
44
45 return _view
46 return _dec