Organigrammes des employés, ajout du menu
authorJean-Philippe Caissy <jpcaissy@piji.ca>
Thu, 1 Mar 2012 20:42:47 +0000 (14:42 -0600)
committerJean-Philippe Caissy <jpcaissy@piji.ca>
Thu, 1 Mar 2012 20:42:47 +0000 (14:42 -0600)
project/menu.py
project/rh/templates/rh/organigrammes/employe.html
project/rh/views.py

index 1a1ab8e..c57b943 100644 (file)
@@ -25,7 +25,7 @@ class CustomMenu(Menu):
             #items.Bookmarks(),
             items.AppList(
                 _('Applications'),
-                exclude=('django.contrib.*',)
+                exclude=('django.contrib.*', 'project.rh.models.EmployeProxy')
             ),
             items.AppList(
                 _('Administration'),
@@ -54,6 +54,7 @@ class CustomMenu(Menu):
                               ),
                 items.MenuItem('Organigrammes',
                     children=[
+                        items.MenuItem('Organigramme par employé', reverse('admin:rh_employeproxy_changelist'))
                         ]
                     ),
             ]
index 5f8b565..3972a71 100644 (file)
@@ -477,35 +477,36 @@ def employe_apercu(request, employe_id):
 def organigrammes_employe(request, id):
 
     poste = get_object_or_404(rh.Poste, pk=id)
+    if rh.Poste.objects.filter(responsable=poste).count() > 0:
+        graph = nx.DiGraph()
+        postes = rh.Poste.objects.select_related('implantation').filter((Q(date_fin__gt=date.today()) | Q(date_fin=None)) & (Q(date_debut__lt=date.today()) | Q(date_debut=None)) ).exclude(supprime=True).exclude(responsable=None).all()
+        dossiers_by_poste = dict((d.poste_id, d) for d in rh.Dossier.objects.select_related('employe', 'poste').all())
+        postes_by_id = dict((p.id, p) for p in rh.Poste.objects.all())
 
-    graph = nx.DiGraph()
-    postes = rh.Poste.objects.select_related('implantation').filter((Q(date_fin__gt=date.today()) | Q(date_fin=None)) & (Q(date_debut__lt=date.today()) | Q(date_debut=None)) ).exclude(supprime=True).exclude(responsable=None).all()
-    dossiers_by_poste = dict((d.poste_id, d) for d in rh.Dossier.objects.select_related('employe', 'poste').all())
-    postes_by_id = dict((p.id, p) for p in rh.Poste.objects.all())
-
-    for p in rh.Poste.objects.filter((Q(date_fin__gt=date.today()) | Q(date_fin=None)) & (Q(date_debut__lt=date.today()) | Q(date_debut=None)) ).exclude(supprime=True).exclude(responsable=None).all():
-        graph.add_node(p.id)
-
-    for p in postes:
-        if p.responsable_id != p.id:
-            graph.add_edge(dossiers_by_poste[p.responsable_id].poste_id, p.id)
+        for p in rh.Poste.objects.filter((Q(date_fin__gt=date.today()) | Q(date_fin=None)) & (Q(date_debut__lt=date.today()) | Q(date_debut=None)) ).exclude(supprime=True).exclude(responsable=None).all():
+            graph.add_node(p.id)
 
-    graph = nx.bfs_tree(graph, poste.id)
-    a = nx.to_agraph(graph)
-    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).exclude(poste__responsable=None).all()[0]
+        for p in postes:
+            if p.responsable_id != p.id:
+                graph.add_edge(dossiers_by_poste[p.responsable_id].poste_id, p.id)
 
-        n.attr['label'] = u"%s %s\\n%s\\n%s" % (d.id, d.poste.nom, "%s %s" % (d.employe.nom.upper(), d.employe.prenom), d.poste.implantation)
+        graph = nx.bfs_tree(graph, poste.id)
+        a = nx.to_agraph(graph)
+        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).exclude(poste__responsable=None).all()[0]
 
-    a.graph_attr['normalize'] = True
-    a.graph_attr['level'] = 2
-    a.layout(prog='dot')
+            n.attr['label'] = u"%s %s\\n%s\\n%s" % (d.id, d.poste.nom, "%s %s" % (d.employe.nom.upper(), d.employe.prenom), d.poste.implantation)
 
-    png = a.draw(format='png')
+        a.graph_attr['normalize'] = True
+        a.graph_attr['level'] = 2
+        a.layout(prog='dot')
 
+        png = a.draw(format='png')
 
-    c = {
-        'png': b64encode(png)
-    }
+        c = {
+            'png': b64encode(png)
+        }
+    else:
+        c = {}
     return render_to_response('rh/organigrammes/employe.html', c, RequestContext(request))