Removed unused 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
b9098c33
BS
11from project.dae.forms import (
12 ReadOnlyRemunFormSet,
13 PosteCompReadOnlyRemunFormSet,
14 DossierCompReadOnlyRemunFormSet,
15 )
16from project.dae import models as dae
17from project.rh import models as rh
d41d8e47 18
5579d48d
OL
19
20register = template.Library()
21
be46739d 22
5579d48d 23@register.filter
3a62d4fe 24def test_membre_drh(user):
3383b2d1
OL
25 grps = [g.name for g in user.groups.all()]
26 if groups.DRH_NIVEAU_1 in grps or groups.DRH_NIVEAU_2 in grps:
2c8d834d
OL
27 return True
28 else:
29 return False
3a62d4fe 30
be46739d 31
3a62d4fe 32@register.filter
5579d48d 33def peut_ajouter(user):
be46739d
OL
34 grp_ok = (groups.ADMINISTRATEURS,
35 groups.CORRESPONDANT_RH,
36 groups.DRH_NIVEAU_1,
37 groups.DRH_NIVEAU_2)
3383b2d1 38 for g in [g.name for g in user.groups.all()]:
be46739d 39 if g in grp_ok:
5579d48d
OL
40 return True
41 return False
42
67c10912
OL
43
44@register.filter
e7ee680f
OL
45def est_editable(obj, user):
46 klass = obj.__class__
3383b2d1 47 groupes_users = [g.name for g in user.groups.all()]
c511cd1f 48 if obj.etat in ETATS_EDITABLE and \
3383b2d1
OL
49 (obj in klass.objects.mes_choses_a_faire(user).all() or \
50 groups.DRH_NIVEAU_1 in groupes_users or \
51 groups.DRH_NIVEAU_2 in groupes_users):
286d0aa9
OL
52 return True
53 else:
54 return False
55
be46739d 56
0b2edb6e 57@register.filter
bbf31587
EMS
58def basename(path):
59 return os.path.basename(path)
428e3c0b 60
be46739d 61
428e3c0b
EMS
62@register.inclusion_tag('dae/sort_header.html', takes_context=True)
63def sort_header(context, field, title):
be46739d
OL
64 """
65 Génère une entête qu'on peut cliquer pour trier
66 la colonne correspondante dans une table.
67 """
428e3c0b
EMS
68 qs = context['request'].GET.copy()
69 current = qs.get('tri', None)
70 if current == field:
71 cls = 'header headerSortUp'
72 qs['tri'] = '-' + field
73 elif current == '-' + field:
74 cls = 'header headerSortDown'
75 qs['tri'] = field
76 else:
77 cls = 'header'
78 qs['tri'] = field
79 return {'title': title, 'qs': qs.urlencode(), 'cls': cls}
80
be46739d 81
428e3c0b
EMS
82@register.inclusion_tag('dae/pagination.html', takes_context=True)
83def pagination(context, page):
84 """Génère la navigation permettant de se promener de page en page."""
85 qs = context['request'].GET
86 previous_qs = qs.copy()
87 previous_qs['page'] = page.previous_page_number()
88 next_qs = qs.copy()
89 next_qs['page'] = page.next_page_number()
be46739d
OL
90 return {'page': page,
91 'previous_qs': previous_qs.urlencode(),
92 'next_qs': next_qs.urlencode()
93 }
b9098c33
BS
94
95
96@register.inclusion_tag('dae/embauche-remun.html', takes_context=True)
97def remun_form(context, dossier):
98
99 return {
100 'remunForm': ReadOnlyRemunFormSet(instance=dossier)
101 }
102
103
104@register.inclusion_tag('dae/embauche-remun.html', takes_context=True)
105def poste_cmp_remun_form(context, poste_cmp):
106 return {
107 'remunForm': PosteCompReadOnlyRemunFormSet(instance=poste_cmp)
108 }
109
110
111@register.inclusion_tag('dae/embauche-remun.html', takes_context=True)
112def dossier_cmp_remun_form(context, dossier_cmp):
113 return {
114 'remunForm': DossierCompReadOnlyRemunFormSet(instance=dossier_cmp)
115 }