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