Optimise en mettant spaceless
[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
e9bbd6ba 5from django.shortcuts import redirect, render_to_response, get_object_or_404
6from django.template import RequestContext
7
d04d084c 8from datamaster_modeles import models as ref
d04d084c 9from project.lib import get_employe_from_id
ae936f8d 10
d04d084c 11from rh import models as rh
a9faef67 12
3411ac33 13# homes
c9122f1d 14@login_required
15def profil(request):
16 """Profil personnel de l'employé - éditable"""
17 rc = RequestContext(request)
18 c = {}
d04d084c 19
c9122f1d 20 employe = rc['this_employe']
65f9fac8 21
c9122f1d 22 c['user'] = request.user
23 c['employe'] = employe
c9122f1d 24 return render_to_response('rh/profil.html', c, rc)
a9faef67 25
26# employes
3411ac33 27@login_required
a9faef67 28def employes_liste(request):
29 """Liste des employés."""
5ea6b5bb 30 today = date.today()
31 employes = rh.Employe.objects \
32 .filter(actif=True, supprime=False) \
33 .filter(dossiers__actif=True, dossiers__supprime=False) \
34 .exclude(dossiers__date_debut__gt=today) \
35 .exclude(dossiers__date_fin__lt=today) \
36 .order_by('nom')
a9faef67 37 c = {
38 'user':request.user,
39 'employes':employes,
40 }
41 return render_to_response('rh/employes_liste.html', c, RequestContext(request))
42
3411ac33 43@login_required
a9faef67 44def employe(request, id):
45 """Information publique sur un employé."""
46 try:
47 employe = rh.Employe.objects.get(pk=id)
48 except:
49 employe = rh.Employe.objects.none()
50 c = {
51 'user':request.user,
52 'employe':employe,
53 }
54 return render_to_response('rh/employe.html', c, RequestContext(request))
63e17dff
PP
55
56
57# Rapports
58
59@login_required
60def rapports_poste(request):
61
62 postes = rh.Poste.actifs.select_related('implantation').all()
63 poste_ids = set([p.pk for p in postes])
64
65 dossiers = rh.Dossier.objects.select_related('poste', 'employe').filter(poste__in=poste_ids)
66
67 employes = dict((d.poste.id, d.employe) for d in dossiers)
68
69 out = []
70
71 for p in postes:
72 line = {}
73 out.append(line)
74
75 line['id'] = p.id
76 line['nom'] = p.nom
77 line['implantation'] = p.implantation.nom
78 employe = employes.get(p.id)
79 if employe:
80 line['employe_id'] = employe.id
81 line['employe_nom'] = employe.nom
82 line['employe_prenom'] = employe.prenom
83
84 c = {
85 'title': 'Rapport des postes',
86 'postes': out,
87 }
88
89 return render_to_response('rh/rapports/postes.html', c, RequestContext(request))