Filtre comblé
[auf_rh_dae.git] / project / rh / views.py
CommitLineData
e9bbd6ba 1# -*- encoding: utf-8 -*-
c9122f1d 2from datetime import date
9b0a8554 3
3411ac33 4from django.contrib.auth.decorators import login_required
fd009814 5from django.utils.encoding import smart_str
e9bbd6ba 6from django.shortcuts import redirect, render_to_response, get_object_or_404
7from django.template import RequestContext
8
d04d084c 9from datamaster_modeles import models as ref
d04d084c 10from project.lib import get_employe_from_id
ae936f8d 11
d04d084c 12from rh import models as rh
a9faef67 13
3411ac33 14# homes
c9122f1d 15@login_required
16def profil(request):
17 """Profil personnel de l'employé - éditable"""
18 rc = RequestContext(request)
19 c = {}
d04d084c 20
c9122f1d 21 employe = rc['this_employe']
65f9fac8 22
c9122f1d 23 c['user'] = request.user
24 c['employe'] = employe
c9122f1d 25 return render_to_response('rh/profil.html', c, rc)
a9faef67 26
27# employes
3411ac33 28@login_required
a9faef67 29def employes_liste(request):
30 """Liste des employés."""
5ea6b5bb 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')
a9faef67 38 c = {
39 'user':request.user,
40 'employes':employes,
41 }
42 return render_to_response('rh/employes_liste.html', c, RequestContext(request))
43
3411ac33 44@login_required
a9faef67 45def 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))
63e17dff
PP
56
57
58# Rapports
59
60@login_required
61def rapports_poste(request):
62
fd009814
PP
63 lookup_params = dict(request.GET.items())
64
7821915f
PP
65 comble = 'all'
66
fd009814
PP
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
7821915f
PP
74 if key == 'comble':
75 comble = value
76 del lookup_params[key]
77
63e17dff 78 postes = rh.Poste.actifs.select_related('implantation').all()
fd009814
PP
79 postes = postes.filter(**lookup_params)
80
63e17dff
PP
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:
7821915f
PP
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
63e17dff
PP
98 line = {}
99 out.append(line)
100
101 line['id'] = p.id
102 line['nom'] = p.nom
103 line['implantation'] = p.implantation.nom
63e17dff
PP
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))