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