Organigramme: afficher toutes les employés qui occupent un même poste
authorJean-Philippe Caissy <jpcaissy@piji.ca>
Wed, 14 Mar 2012 15:08:37 +0000 (10:08 -0500)
committerJean-Philippe Caissy <jpcaissy@piji.ca>
Wed, 14 Mar 2012 15:08:37 +0000 (10:08 -0500)
project/rh/graph.py

index 2337aa2..3bd52c6 100644 (file)
@@ -10,17 +10,22 @@ from rh import models as rh
 
 def bind_poste_to_graph(graph, postes_by_id):
     for n in graph.nodes():
-        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__id=n)
-            ).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'