Ajout d'un menu, et correction des liens du breadcrumbs
[auf_rh_dae.git] / project / rh / views.py
1 # -*- encoding: utf-8 -*-
2 from datetime import date
3
4 from django.contrib.auth.decorators import login_required
5 from django.utils.encoding import smart_str
6 from django.shortcuts import redirect, render_to_response, get_object_or_404
7 from django.template import RequestContext
8
9 from datamaster_modeles import models as ref
10 from project.lib import get_employe_from_id
11
12 from rh import models as rh
13
14 # homes
15 @login_required
16 def profil(request):
17 """Profil personnel de l'employé - éditable"""
18 rc = RequestContext(request)
19 c = {}
20
21 employe = rc['this_employe']
22
23 c['user'] = request.user
24 c['employe'] = employe
25 return render_to_response('rh/profil.html', c, rc)
26
27 # employes
28 @login_required
29 def employes_liste(request):
30 """Liste des employés."""
31 today = date.today()
32 employes = rh.Employe.objects \
33 .filter(actif=True, supprime=False) \
34 .filter(dossiers__actif=True, dossiers__supprime=False) \
35 .exclude(dossiers__date_debut__gt=today) \
36 .exclude(dossiers__date_fin__lt=today) \
37 .order_by('nom')
38 c = {
39 'user':request.user,
40 'employes':employes,
41 }
42 return render_to_response('rh/employes_liste.html', c, RequestContext(request))
43
44 @login_required
45 def employe(request, id):
46 """Information publique sur un employé."""
47 try:
48 employe = rh.Employe.objects.get(pk=id)
49 except:
50 employe = rh.Employe.objects.none()
51 c = {
52 'user':request.user,
53 'employe':employe,
54 }
55 return render_to_response('rh/employe.html', c, RequestContext(request))
56
57
58 # Rapports
59
60 @login_required
61 def rapports_poste(request):
62
63 lookup_params = dict(request.GET.items())
64
65 comble = 'all'
66
67 for key, value in lookup_params.items():
68 if not isinstance(key, str):
69 # 'key' will be used as a keyword argument later, so Python
70 # requires it to be a string.
71 del lookup_params[key]
72 lookup_params[smart_str(key)] = value
73
74 if key == 'comble':
75 comble = value
76 del lookup_params[key]
77
78 postes = rh.Poste.actifs.select_related('implantation').all()
79 postes = postes.filter(**lookup_params)
80
81 poste_ids = set([p.pk for p in postes])
82
83 dossiers = rh.Dossier.objects.select_related('poste', 'employe').filter(poste__in=poste_ids)
84
85 employes = dict((d.poste.id, d.employe) for d in dossiers)
86
87 out = []
88
89 for p in postes:
90 employe = employes.get(p.id)
91
92 if comble == 'c' and not employe:
93 continue
94
95 if comble == 'n' and employe:
96 continue
97
98 line = {}
99 out.append(line)
100
101 line['id'] = p.id
102 line['nom'] = p.nom
103 line['implantation'] = p.implantation.nom
104 if employe:
105 line['employe_id'] = employe.id
106 line['employe_nom'] = employe.nom
107 line['employe_prenom'] = employe.prenom
108
109 c = {
110 'title': 'Rapport des postes',
111 'postes': out,
112 }
113
114 return render_to_response('rh/rapports/postes.html', c, RequestContext(request))
115
116
117 def rapports_contrat(request):
118
119 lookup_params = dict(request.GET.items())
120
121 for key, value in lookup_params.items():
122 if not isinstance(key, str):
123 # 'key' will be used as a keyword argument later, so Python
124 # requires it to be a string.
125 del lookup_params[key]
126 lookup_params[smart_str(key)] = value
127
128 contrats = rh.Contrat.objects.select_related('dossier', 'dossier__poste', 'dossier__poste__implantation', 'type_contrat', 'dossier__employe').all()
129 contrats = contrats.filter(**lookup_params)
130
131 c = {
132 'title': 'Rapport des contrats',
133 'contrats': contrats,
134 }
135
136 return render_to_response('rh/rapports/contrats.html', c, RequestContext(request))