Commit | Line | Data |
---|---|---|
3f5cbabe OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
617d60c9 OL |
3 | from django.core.exceptions import ObjectDoesNotExist |
4 | ||
940c9dd8 | 5 | CORRESPONDANT_RH = 'Correspondants RH' |
25f2c148 | 6 | ADMINISTRATEURS = 'Administrateurs' |
940c9dd8 OL |
7 | DIRECTEUR_DE_BUREAU = 'Directeurs de bureau' |
8 | DRH_NIVEAU_1 = 'DRH' | |
9 | DRH_NIVEAU_2 = 'DRH-2' | |
10 | ACCIOR = 'ACCIOR' | |
11 | ABF = 'ABF' | |
25f2c148 | 12 | FINANCE = 'Finance' |
940c9dd8 OL |
13 | HAUTE_DIRECTION = 'Haute direction' |
14 | SERVICE_UTILISATEURS = 'Service utilisateurs' | |
15 | ||
afd3be54 | 16 | |
e8b6a20c BS |
17 | def get_zones_from_user(user): |
18 | from auf.django.references import models as ref | |
19 | try: | |
20 | profile = user.profile | |
21 | except ObjectDoesNotExist: | |
22 | return ref.ZoneAdministrative.objects.none() | |
23 | else: | |
24 | return profile.zones_administratives.all() | |
25 | ||
26 | ||
afd3be54 | 27 | def get_employe_from_user(user): |
25f2c148 OL |
28 | """ |
29 | Retourne un employé AUF à partir de son user Django. | |
30 | """ | |
31e71fb6 | 31 | import auf.django.references.models as ref |
25f2c148 | 32 | try: |
617d60c9 OL |
33 | employe = ref.Employe.objects.get(courriel=user.email) |
34 | except ObjectDoesNotExist: | |
25f2c148 OL |
35 | raise Exception(u"L'employé avec le courriel %s n'a pas \ |
36 | été trouvé dans le référentiel." % user.email) | |
37 | return employe | |
38 | ||
afd3be54 DB |
39 | |
40 | def is_user_dans_services_centraux(user): | |
e8b6a20c BS |
41 | # Set de codes de zones. |
42 | zones = set() | |
43 | ||
44 | # Set de comparaison (services centraux Montreal et Paris) | |
45 | central_zones = set(['SCM', 'SCP']) | |
46 | ||
47 | # Ajout de zones du profil, si existantes. | |
48 | try: | |
49 | profile = user.profile | |
50 | except ObjectDoesNotExist: | |
51 | pass | |
52 | else: | |
53 | zones.update([ | |
54 | x[0] for x in profile.zones_administratives | |
55 | .all().values_list('code') | |
56 | ]) | |
57 | ||
58 | return len(central_zones.intersection(zones)) > 0 | |
afd3be54 | 59 | |
25f2c148 | 60 | |
afd3be54 | 61 | def is_user_dans_region(user): |
afd3be54 | 62 | return not is_user_dans_services_centraux(user) |