| 1 | # -*- encoding: utf-8 -*- |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | from django import template |
| 6 | from project.dae.workflow import ETATS_EDITABLE |
| 7 | from project.dae.workflow import grp_correspondants_rh, grp_administrateurs, grp_drh |
| 8 | |
| 9 | register = template.Library() |
| 10 | |
| 11 | @register.filter |
| 12 | def test_membre_drh(user): |
| 13 | return grp_drh in user.groups.all() |
| 14 | |
| 15 | @register.filter |
| 16 | def peut_ajouter(user): |
| 17 | for g in user.groups.all(): |
| 18 | if g in (grp_administrateurs, grp_correspondants_rh, grp_drh): |
| 19 | return True |
| 20 | return False |
| 21 | |
| 22 | @register.filter |
| 23 | def est_editable(obj, user): |
| 24 | klass = obj.__class__ |
| 25 | groupes_users = user.groups.all() |
| 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): |
| 28 | return True |
| 29 | else: |
| 30 | return False |
| 31 | |
| 32 | @register.filter |
| 33 | def 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 |
| 39 | |
| 40 | @register.filter |
| 41 | def basename(path): |
| 42 | return os.path.basename(path) |