Organigramme des employés: on remonte tout en haut
authorJean-Philippe Caissy <jpcaissy@piji.ca>
Mon, 5 Mar 2012 16:10:16 +0000 (10:10 -0600)
committerJean-Philippe Caissy <jpcaissy@piji.ca>
Mon, 5 Mar 2012 16:10:16 +0000 (10:10 -0600)
project/rh/views.py

index 85aafa6..d8a8f70 100644 (file)
@@ -496,18 +496,30 @@ def organigrammes_employe(request, id):
 
         graph = nx.bfs_tree(graph, poste.id)
         a = nx.to_agraph(graph)
+
+        poste_remontant = poste
+        while poste_remontant.responsable_id:
+            a.add_edge(poste_remontant.responsable_id, poste_remontant.id)
+            poste_remontant = poste_remontant.responsable
+
         for n in a.nodes():
             p = postes_by_id[int(n)]
-            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]
+            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)
+
+                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:
+                label = u"%s\\n---\\n%s" % (d.poste.nom, d.poste.implantation)
+                n.attr['fillcolor'] = 'azure4'
+                n.attr['style'] = 'filled'
 
             label = unicodedata.normalize('NFKD', label).encode('ascii','ignore')
             n.attr['label'] = label
             n.attr['href'] = reverse("admin:rh_employe_change", args=(d.employe_id,))
-
+        
         #a.graph_attr['normalize'] = True
         #a.graph_attr['level'] = 2
         a.layout(prog='dot')