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