rh.Employe méthodes
[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']
21
9b0a8554 22 # dossiers en cours et passés
c9122f1d 23 today = date.today()
9b0a8554 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
c9122f1d 33
34 c['user'] = request.user
35 c['employe'] = employe
9b0a8554 36 c['dossiers'] = dossiers.count()
c9122f1d 37 return render_to_response('rh/profil.html', c, rc)
a9faef67 38
39# employes
3411ac33 40@login_required
a9faef67 41def employes_liste(request):
42 """Liste des employés."""
5ea6b5bb 43 today = date.today()
44 employes = rh.Employe.objects \
45 .filter(actif=True, supprime=False) \
46 .filter(dossiers__actif=True, dossiers__supprime=False) \
47 .exclude(dossiers__date_debut__gt=today) \
48 .exclude(dossiers__date_fin__lt=today) \
49 .order_by('nom')
a9faef67 50 c = {
51 'user':request.user,
52 'employes':employes,
53 }
54 return render_to_response('rh/employes_liste.html', c, RequestContext(request))
55
3411ac33 56@login_required
a9faef67 57def employe(request, id):
58 """Information publique sur un employé."""
59 try:
60 employe = rh.Employe.objects.get(pk=id)
61 except:
62 employe = rh.Employe.objects.none()
63 c = {
64 'user':request.user,
65 'employe':employe,
66 }
67 return render_to_response('rh/employe.html', c, RequestContext(request))