dd820dabb993b001118c9ab8d7d6877cd10a7a6b
[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.shortcuts import redirect, render_to_response, get_object_or_404
6 from django.template import RequestContext
7
8 from datamaster_modeles import models as ref
9 from project.lib import get_employe_from_id
10
11 from rh import models as rh
12
13 # homes
14 @login_required
15 def profil(request):
16 """Profil personnel de l'employé - éditable"""
17 rc = RequestContext(request)
18 c = {}
19
20 employe = rc['this_employe']
21
22 # dossiers en cours et passés
23 today = date.today()
24 dossiers = employe.dossiers.all().order_by('-date_fin')
25 dossiers_passes = dossiers.filter(date_fin__lt=today)
26 dossiers_futurs = dossiers.filter(date_debut__gt=today)
27 dossiers_p_f = dossiers_passes | dossiers_futurs
28 ids_dossiers_p_f = [d.id for d in dossiers_p_f]
29 dossiers_encours = dossiers.exclude(id__in=ids_dossiers_p_f)
30
31 for d in dossiers_passes:
32 d.archive = True
33
34 c['user'] = request.user
35 c['employe'] = employe
36 c['dossiers'] = dossiers.count()
37 c['dossiers_passes'] = dossiers_passes
38 c['dossiers_encours'] = dossiers_encours
39 return render_to_response('rh/profil.html', c, rc)
40
41 # employes
42 @login_required
43 def employes_liste(request):
44 """Liste des employés."""
45 today = date.today()
46 employes = rh.Employe.objects \
47 .filter(actif=True, supprime=False) \
48 .filter(dossiers__actif=True, dossiers__supprime=False) \
49 .exclude(dossiers__date_debut__gt=today) \
50 .exclude(dossiers__date_fin__lt=today) \
51 .order_by('nom')
52 c = {
53 'user':request.user,
54 'employes':employes,
55 }
56 return render_to_response('rh/employes_liste.html', c, RequestContext(request))
57
58 @login_required
59 def employe(request, id):
60 """Information publique sur un employé."""
61 try:
62 employe = rh.Employe.objects.get(pk=id)
63 except:
64 employe = rh.Employe.objects.none()
65 c = {
66 'user':request.user,
67 'employe':employe,
68 }
69 return render_to_response('rh/employe.html', c, RequestContext(request))