Suppression prints de debug
[auf_references_client.git] / auf_references_client / decorators.py
CommitLineData
1c827f00
CR
1#!/usr/bin/env python
2# -*- encoding: utf-8 -*-
3
4from django.http import HttpResponseForbidden
5from django.contrib.auth import logout
6from django.template.loader import get_template
7from django.template import Context
287a41be
CR
8from django.conf import settings
9
10from auf_references_modeles import Utilisateur, GroupesPersonne
11
12import sys, traceback
1c827f00
CR
13
14def 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:
287a41be
CR
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:
412aac6e 27 pass
1c827f00
CR
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