Merge branch 'dev' of ssh://git.auf.org/auf_rh_dae into dev
[auf_rh_dae.git] / project / rh / graph.py
CommitLineData
5c0f1778
JPC
1import unicodedata
2from datetime import date
3from django.db.models import Q
4from django.core.urlresolvers import reverse
5
6from rh import models as rh
7
8def bind_poste_to_graph(graph, postes_by_id):
9 for n in graph.nodes():
10 p = postes_by_id[int(n)]
11 try:
12 d = rh.Dossier.objects.select_related('employe').filter((Q(date_fin__gt=date.today()) | Q(date_fin=None)) & (Q(date_debut__lt=date.today()) | Q(date_debut=None)) & Q(poste=p)).exclude(supprime=True).all()[0]
13
14
15 label = u"%s\\n[%s] %s\\n%s" % (d.poste.nom, d.employe_id, "%s %s" %
16 (d.employe.nom.upper(), d.employe.prenom),
17 d.poste.implantation)
18 except IndexError:
19 label = u"%s\\n---\\n%s" % (d.poste.nom, d.poste.implantation)
20 n.attr['fillcolor'] = 'azure4'
21 n.attr['style'] = 'filled'
22
23 label = unicodedata.normalize('NFKD', label).encode('ascii','ignore')
24 n.attr['label'] = label
25 n.attr['href'] = reverse("admin:rh_employe_change", args=(d.employe_id,))
26
27 return graph