poste
[auf_rh_dae.git] / project / dae / templatetags / dae.py
CommitLineData
0b2edb6e
OL
1# -*- encoding: utf-8 -*-
2
bbf31587
EMS
3import os
4
5579d48d 5from django import template
75f0e87b 6
3383b2d1 7from project import groups
d41d8e47 8
286d0aa9 9from project.dae.workflow import ETATS_EDITABLE
d41d8e47 10
5579d48d
OL
11
12register = template.Library()
13
14@register.filter
3a62d4fe 15def test_membre_drh(user):
3383b2d1
OL
16 grps = [g.name for g in user.groups.all()]
17 if groups.DRH_NIVEAU_1 in grps or groups.DRH_NIVEAU_2 in grps:
2c8d834d
OL
18 return True
19 else:
20 return False
3a62d4fe
OL
21
22@register.filter
5579d48d 23def peut_ajouter(user):
3383b2d1
OL
24 for g in [g.name for g in user.groups.all()]:
25 if g in (groups.ADMINISTRATEURS,
26 groups.CORRESPONDANT_RH,
27 groups.DRH_NIVEAU_1,
28 groups.DRH_NIVEAU_2):
5579d48d
OL
29 return True
30 return False
31
286d0aa9 32@register.filter
67c10912 33def peut_importer(user):
3383b2d1 34 return groups.DRH_NIVEAU_1 in [g.name for g in user.groups.all()]
67c10912
OL
35
36@register.filter
e7ee680f
OL
37def est_editable(obj, user):
38 klass = obj.__class__
3383b2d1 39 groupes_users = [g.name for g in user.groups.all()]
66fefd2f
OL
40 print ETATS_EDITABLE
41 print klass.objects.mes_choses_a_faire(user).all()
c511cd1f 42 if obj.etat in ETATS_EDITABLE and \
3383b2d1
OL
43 (obj in klass.objects.mes_choses_a_faire(user).all() or \
44 groups.DRH_NIVEAU_1 in groupes_users or \
45 groups.DRH_NIVEAU_2 in groupes_users):
286d0aa9
OL
46 return True
47 else:
48 return False
49
0b2edb6e
OL
50@register.filter
51def region_ou_service(implantation):
52 if implantation.id == 15:
53 return u"Services centraux de Montréal (SCM)"
54 if implantation.id == 19:
55 return u"Services centraux de Paris (SCP)"
56 return implantation.region
bbf31587
EMS
57
58@register.filter
59def basename(path):
60 return os.path.basename(path)
428e3c0b
EMS
61
62@register.inclusion_tag('dae/sort_header.html', takes_context=True)
63def sort_header(context, field, title):
64 """Génère une entête qu'on peut cliquer pour trier la colonne correspondante dans une table."""
65 qs = context['request'].GET.copy()
66 current = qs.get('tri', None)
67 if current == field:
68 cls = 'header headerSortUp'
69 qs['tri'] = '-' + field
70 elif current == '-' + field:
71 cls = 'header headerSortDown'
72 qs['tri'] = field
73 else:
74 cls = 'header'
75 qs['tri'] = field
76 return {'title': title, 'qs': qs.urlencode(), 'cls': cls}
77
78@register.inclusion_tag('dae/pagination.html', takes_context=True)
79def pagination(context, page):
80 """Génère la navigation permettant de se promener de page en page."""
81 qs = context['request'].GET
82 previous_qs = qs.copy()
83 previous_qs['page'] = page.previous_page_number()
84 next_qs = qs.copy()
85 next_qs['page'] = page.next_page_number()
86 return {'page': page, 'previous_qs': previous_qs.urlencode(), 'next_qs': next_qs.urlencode()}