Organigramme: afficher toutes les employés qui occupent un même poste
[auf_rh_dae.git] / project / rh / graph.py
index 1e9f4b4..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_employe_change", args=(d.employe_id,))
+        n.attr['href'] = reverse("admin:rh_poste_change", args=(n,))
 
     return graph
 
@@ -49,10 +56,15 @@ def organigramme_postes_cluster(cluster_filter, titre=u"Organigramme", cluster_t
     #graph.rankdir='LR'
     graph_service = graph.subgraph(nbunch=[1,2], \
             name="cluster1", \
-            style='filled', \
-            color='lightgrey', \
-            label=cluster_titre.encode('ascii', 'xmlcharrefreplace'),
-            labeljust="l")
+    #        style='filled', \
+    #        color='lightgrey', \
+    #        label=cluster_titre.encode('ascii', 'xmlcharrefreplace'),
+    #        labeljust="l")
+    )
+    graph_service.graph_attr['style'] = 'filled'
+    graph_service.graph_attr['color'] = 'lightgrey'
+    graph_service.graph_attr['label'] = cluster_titre.encode('ascii', 'xmlcharrefreplace')
+    graph_service.graph_attr['labeljust'] = 'l'
 
     for p in postes:
         graph_service.add_node(p.id)