Organigramme: afficher toutes les employés qui occupent un même poste
[auf_rh_dae.git] / project / rh / graph.py
index bb17ee5..3bd52c6 100644 (file)
@@ -10,21 +10,28 @@ from rh import models as rh
 
 def bind_poste_to_graph(graph, postes_by_id):
     for n in graph.nodes():
-        p = postes_by_id[int(n)]
-        try:
-            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]
-
-
-            label = u"%s\\n[%s] %s\\n%s" % (d.poste.nom, d.employe_id, "%s %s" %
-                    (d.employe.nom.upper(), d.employe.prenom),
-                    d.poste.implantation)
-        except IndexError:
+        dossiers = 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__id=n)
+        ).exclude(supprime=True).all()
+
+
+        if dossiers:
+            employes = "\\n".join(
+                        ["[%s] %s %s" % 
+                            (d.employe_id, d.employe.nom.upper(), 
+                                d.employe.prenom
+                            ) for d in dossiers]
+                    )
+            label = u"%s\\n%s\\n%s" % (d.poste.nom, employes, d.poste.implantation)
+        else:
             label = u"%s\\n---\\n%s" % (d.poste.nom, d.poste.implantation)
             n.attr['fillcolor'] = 'azure4'
             n.attr['style'] = 'filled'
 
         n.attr['label'] = label.encode('ascii', 'xmlcharrefreplace')
-        n.attr['href'] = reverse("admin:rh_poste_change", args=(d.poste_id,))
+        n.attr['href'] = reverse("admin:rh_poste_change", args=(n,))
 
     return graph