import avec project.
[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
286d0aa9 7from project.dae.workflow import ETATS_EDITABLE
3f5cbabe 8from project.rh.groups import grp_correspondants_rh, grp_administrateurs, grp_drh
5579d48d
OL
9
10register = template.Library()
11
12@register.filter
3a62d4fe
OL
13def test_membre_drh(user):
14 return grp_drh in user.groups.all()
15
16@register.filter
5579d48d
OL
17def peut_ajouter(user):
18 for g in user.groups.all():
d8cfc3d5 19 if g in (grp_administrateurs, grp_correspondants_rh, grp_drh):
5579d48d
OL
20 return True
21 return False
22
286d0aa9 23@register.filter
67c10912
OL
24def peut_importer(user):
25 return grp_drh in user.groups.all()
26
27@register.filter
e7ee680f
OL
28def est_editable(obj, user):
29 klass = obj.__class__
30 groupes_users = user.groups.all()
c511cd1f
EMS
31 if obj.etat in ETATS_EDITABLE and \
32 (obj in klass.objects.mes_choses_a_faire(user).all() or grp_drh in groupes_users):
286d0aa9
OL
33 return True
34 else:
35 return False
36
0b2edb6e
OL
37@register.filter
38def region_ou_service(implantation):
39 if implantation.id == 15:
40 return u"Services centraux de Montréal (SCM)"
41 if implantation.id == 19:
42 return u"Services centraux de Paris (SCP)"
43 return implantation.region
bbf31587
EMS
44
45@register.filter
46def basename(path):
47 return os.path.basename(path)
428e3c0b
EMS
48
49@register.inclusion_tag('dae/sort_header.html', takes_context=True)
50def sort_header(context, field, title):
51 """Génère une entête qu'on peut cliquer pour trier la colonne correspondante dans une table."""
52 qs = context['request'].GET.copy()
53 current = qs.get('tri', None)
54 if current == field:
55 cls = 'header headerSortUp'
56 qs['tri'] = '-' + field
57 elif current == '-' + field:
58 cls = 'header headerSortDown'
59 qs['tri'] = field
60 else:
61 cls = 'header'
62 qs['tri'] = field
63 return {'title': title, 'qs': qs.urlencode(), 'cls': cls}
64
65@register.inclusion_tag('dae/pagination.html', takes_context=True)
66def pagination(context, page):
67 """Génère la navigation permettant de se promener de page en page."""
68 qs = context['request'].GET
69 previous_qs = qs.copy()
70 previous_qs['page'] = page.previous_page_number()
71 next_qs = qs.copy()
72 next_qs['page'] = page.next_page_number()
73 return {'page': page, 'previous_qs': previous_qs.urlencode(), 'next_qs': next_qs.urlencode()}