fix ajax for salaire proposition
[auf_rh_dae.git] / project / rh / views.py
CommitLineData
e9bbd6ba 1# -*- encoding: utf-8 -*-
22343fe7 2
c9122f1d 3from datetime import date
a7de62d7 4from itertools import izip
fa1624f6 5import networkx as nx
5c0f1778 6import pygraphviz as pgv
9b0a8554 7
fbe60a9d 8from django.db.models import Q
3411ac33 9from django.contrib.auth.decorators import login_required
fd009814 10from django.utils.encoding import smart_str
22343fe7 11from django.shortcuts import render_to_response, get_object_or_404
e9bbd6ba 12from django.template import RequestContext
a251ac8d 13from django.http import HttpResponse
e9bbd6ba 14
d04d084c 15from datamaster_modeles import models as ref
ae936f8d 16
d04d084c 17from rh import models as rh
e2c0b1ac 18from rh.lib import calc_remun
02c1b3dc 19from rh.decorators import drh_or_admin_required
9d53bc73 20from rh.templatetags.rapports import SortHeaders
f0f6b03e 21from rh.change_list import RechercheTemporelle
5c0f1778 22from rh import graph as rh_graph
a9faef67 23
9817fed5
OL
24# pas de reference a DAE devrait etre refactorisé
25from dae.utils import get_employe_from_user
26from dae.decorators import redirect_interdiction
27from dae.workflow import grp_drh, grp_correspondants_rh
baf9b78c 28from django.conf import settings
9817fed5 29
22343fe7 30
c9122f1d 31@login_required
32def profil(request):
33 """Profil personnel de l'employé - éditable"""
34 rc = RequestContext(request)
35 c = {}
22343fe7 36
c9122f1d 37 employe = rc['this_employe']
22343fe7 38
c9122f1d 39 c['user'] = request.user
40 c['employe'] = employe
c9122f1d 41 return render_to_response('rh/profil.html', c, rc)
22343fe7
OL
42
43
3411ac33 44@login_required
a9faef67 45def employes_liste(request):
46 """Liste des employés."""
5ea6b5bb 47 today = date.today()
48 employes = rh.Employe.objects \
5ea6b5bb 49 .exclude(dossiers__date_debut__gt=today) \
50 .exclude(dossiers__date_fin__lt=today) \
51 .order_by('nom')
a9faef67 52 c = {
22343fe7
OL
53 'user': request.user,
54 'employes': employes,
a9faef67 55 }
22343fe7
OL
56 return render_to_response('rh/employes_liste.html',
57 c,
58 RequestContext(request))
59
60
3411ac33 61@login_required
a9faef67 62def employe(request, id):
63 """Information publique sur un employé."""
64 try:
65 employe = rh.Employe.objects.get(pk=id)
66 except:
67 employe = rh.Employe.objects.none()
68 c = {
22343fe7
OL
69 'user': request.user,
70 'employe': employe,
a9faef67 71 }
72 return render_to_response('rh/employe.html', c, RequestContext(request))
63e17dff
PP
73
74
75# Rapports
76
77@login_required
02c1b3dc 78@drh_or_admin_required
48487f09
JPC
79def rapports_postes_hierarchie(request):
80
81 c = {}
ce18dd0a 82 graph = nx.DiGraph()
fa1624f6
JPC
83 postes = rh.Poste.objects.all()
84 postes_id = dict((p.id, p) for p in postes)
ce18dd0a 85 graph.add_node(p for p in postes)
48487f09 86
fa1624f6
JPC
87 for p in postes:
88 if p.responsable_id != p.id:
ce18dd0a 89 graph.add_edge(postes_id[p.responsable_id], p)
48487f09 90
fa1624f6 91 c['postes'] = nx.to_dict_of_lists(graph)
48487f09 92
22343fe7
OL
93 return render_to_response('rh/rapports/postes_hierarchie.html',
94 c,
95 RequestContext(request))
96
48487f09
JPC
97
98@login_required
99@drh_or_admin_required
08faf06e
JPC
100def hierarchie_poste(request):
101 pass
102
22343fe7 103
08faf06e
JPC
104@login_required
105@drh_or_admin_required
63e17dff
PP
106def rapports_poste(request):
107
fd009814
PP
108 lookup_params = dict(request.GET.items())
109
110 for key, value in lookup_params.items():
9d53bc73
JPC
111 if key == 'o' or key == 'ot':
112 del lookup_params[key]
113 continue
fd009814
PP
114 if not isinstance(key, str):
115 # 'key' will be used as a keyword argument later, so Python
116 # requires it to be a string.
117 del lookup_params[key]
118 lookup_params[smart_str(key)] = value
119
7821915f 120 if key == 'comble':
7821915f
PP
121 del lookup_params[key]
122
ed3cbb32
OL
123 postes = rh.Poste.objects.select_related('implantation') \
124 .extra(select={'employe_id':'select group_concat(employe separator "|") from rh_dossier where poste=rh_poste.id and rh_dossier.date_fin is null %s' % \
9202c5db
JPC
125 ("%s" % (('order by employe %s' % ('asc' if 'ot' in request.GET and request.GET['ot'] == "asc" else "desc"))) if 'o' in request.GET and request.GET['o'] == "employe_id" else "") \
126 }) \
ed3cbb32 127 .extra(select={'employe_nom':'select group_concat(rh_employe.nom separator "|") from rh_dossier inner join rh_employe on rh_dossier.employe = rh_employe.id where poste=rh_poste.id and rh_dossier.date_fin is null %s' % \
9202c5db
JPC
128 ("%s" % (('order by rh_employe.nom %s' % ('asc' if 'ot' in request.GET and request.GET['ot'] == "asc" else "desc"))) if 'o' in request.GET and request.GET['o'] == "employe_nom" else "") \
129 }) \
ed3cbb32 130 .extra(select={'employe_prenom':'select group_concat(rh_employe.prenom separator "|") from rh_dossier inner join rh_employe on rh_dossier.employe = rh_employe.id where poste=rh_poste.id and rh_dossier.date_fin is null %s' % \
9202c5db
JPC
131 ("%s" % (('order by rh_employe.prenom %s' % ('asc' if 'ot' in request.GET and request.GET['ot'] == "asc" else "desc"))) if 'o' in request.GET and request.GET['o'] == "employe_prenom" else "") \
132 })
9d53bc73 133
65e02621 134 postes = postes.filter(**lookup_params)
9d53bc73 135 if 'o' in request.GET:
65e02621
JPC
136 postes = postes.order_by("%s%s" % ('-' if 'ot' in request.GET and request.GET['ot'] == "desc" else '', request.GET['o']))
137
a7de62d7
JPC
138 out = []
139 for p in postes:
140 out.append({
141 'id': p.id,
142 'nom': p.nom,
143 'implantation': p.implantation,
144 'employes': [] if not p.employe_id else [{'id': id, 'nom': nom, 'prenom': prenom} for id, nom, prenom in izip(p.employe_id.split('|'), p.employe_nom.split('|'), p.employe_prenom.split('|'))] })
145
146
4dade240
JPC
147 headers = [
148 ("id", u"# du poste"),
149 ("nom", u"Nom du poste"),
65e02621 150 ("implantation__id", u"Implantation"),
4dade240 151 ("employe_nom", u"Nom"),
4dade240
JPC
152 ]
153 h = SortHeaders(request, headers, order_field_type="ot", order_field="o")
63e17dff
PP
154 c = {
155 'title': 'Rapport des postes',
a7de62d7
JPC
156 'postes': out,
157 'count': len(out),
65e02621 158 'headers': list(h.headers()),
63e17dff
PP
159 }
160
161 return render_to_response('rh/rapports/postes.html', c, RequestContext(request))
f2d65e83 162
02c1b3dc
JPC
163@login_required
164@drh_or_admin_required
f2d65e83
PP
165def rapports_contrat(request):
166
167 lookup_params = dict(request.GET.items())
65e02621
JPC
168 if 'ot' in lookup_params:
169 del lookup_params['ot']
170 if 'o' in lookup_params:
171 del lookup_params['o']
f2d65e83
PP
172
173 for key, value in lookup_params.items():
174 if not isinstance(key, str):
175 # 'key' will be used as a keyword argument later, so Python
176 # requires it to be a string.
177 del lookup_params[key]
178 lookup_params[smart_str(key)] = value
179
65e02621 180 contrats = rh.Contrat.objects.select_related('dossier', 'dossier__poste', 'dossier__poste__implantation', 'type_contrat', 'dossier__employe')
22343fe7 181
f0f6b03e
OL
182 cl = RechercheTemporelle(request, rh.Contrat)
183 lookup_params = cl.purge_params(lookup_params)
821b9889 184 contrats = contrats.filter(**lookup_params).exclude(dossier__employe__supprime=1)
f0f6b03e
OL
185 contrats = cl.filter_temporel(contrats)
186
65e02621
JPC
187 if 'o' in request.GET:
188 contrats = contrats.order_by("%s%s" % ('-' if 'ot' in request.GET and request.GET['ot'] == "desc" else '', request.GET['o']))
f2d65e83 189
8ee135b7
JPC
190 employes = set([c.dossier.employe_id for c in contrats])
191
65e02621
JPC
192 headers = [
193 ("dossier__employe__id", u"# de l'employé"),
194 ("dossier__employe__nom", u"Nom"),
195 ("dossier__employe__prenom", u"Prénom"),
196 ("type_contrat__nom", u"Poste"),
197 ("type_contrat__nom", u"Type de contrat"),
198 ("date_debut", u"Date début"),
199 ("date_fin", u"Date fin"),
200 ]
201 h = SortHeaders(request, headers, order_field_type="ot", order_field="o")
202
f2d65e83 203 c = {
f0f6b03e 204 'cl' : cl,
f2d65e83
PP
205 'title': 'Rapport des contrats',
206 'contrats': contrats,
8ee135b7
JPC
207 'count': len(contrats),
208 'count_employe' : len(employes),
65e02621 209 'headers': list(h.headers()),
f2d65e83
PP
210 }
211
212 return render_to_response('rh/rapports/contrats.html', c, RequestContext(request))
e2c0b1ac
PP
213
214
02c1b3dc
JPC
215@login_required
216@drh_or_admin_required
e2c0b1ac
PP
217def rapports_remuneration(request):
218
219 lookup_params = dict(request.GET.items())
9202c5db
JPC
220 if 'ot' in lookup_params:
221 del lookup_params['ot']
222 if 'o' in lookup_params:
223 del lookup_params['o']
e2c0b1ac
PP
224
225 for key, value in lookup_params.items():
226 if not isinstance(key, str):
227 # 'key' will be used as a keyword argument later, so Python
228 # requires it to be a string.
229 del lookup_params[key]
230 lookup_params[smart_str(key)] = value
231
232 employes = rh.Employe.objects.all()
9202c5db
JPC
233 if 'o' in request.GET:
234 employes = employes.order_by("%s%s" % ('-' if 'ot' in request.GET and request.GET['ot'] == "desc" else '', request.GET['o']))
235
e2c0b1ac
PP
236 employes = employes.filter(**lookup_params)
237
238 output = []
9202c5db
JPC
239 headers = [
240 ("id", u"# de l'employé"),
241 ("nom", u"Nom"),
242 ("prenom", u"Prénom"),
243 ("", u"Salaire"),
244 ("", u"RAS"),
245 ("", u"Indemnités"),
246 ("", u"Accessoire"),
247 ("", u"Charges patronales"),
248 ("", u"Total"),
249 ]
250 h = SortHeaders(request, headers, order_field_type="ot", order_field="o")
e2c0b1ac
PP
251
252 for employe in employes:
253 line = {}
254 output.append(line)
255
da6c523f 256 dossiers = employe.rh_dossiers.all()
e2c0b1ac
PP
257
258 remun = {}
259 remun_sum_euro = 0
260
261 for dossier in dossiers:
262 this_remun, this_remun_sum, this_remun_sum_euro = calc_remun(dossier)
263
264 for item in this_remun:
265 if item not in remun:
266 remun[item] = this_remun[item]
267 else:
268 remun[item][0] += this_remun[item][0]
269 remun[item][1] += this_remun[item][1]
270
271 remun_sum_euro += this_remun_sum_euro
272
273 line['remun_sum_euro'] = remun_sum_euro
274
275 for r in remun:
276 if r == u'Indemnité':
e2c0b1ac
PP
277 line['Indemnite'] = remun[r][1]
278 else:
279 line[r] = remun[r][1]
280
281 line['id'] = employe.id
282 line['nom'] = employe.nom
283 line['prenom'] = employe.prenom
284
285
286 c = {
287 'title': 'Rapport de remuneration',
288 'employes': output,
9202c5db 289 'headers': list(h.headers()),
e2c0b1ac
PP
290 }
291
292 return render_to_response('rh/rapports/remuneration.html', c, RequestContext(request))
3ebc0952 293
783e077a
JPC
294@login_required
295@drh_or_admin_required
c8b22fd1
JPC
296def rapports_employe_sans_contrat(request):
297
298 lookup_params = dict(request.GET.items())
299 if 'ot' in lookup_params:
300 del lookup_params['ot']
301 if 'o' in lookup_params:
302 del lookup_params['o']
303
304 for key, value in lookup_params.items():
305 if not isinstance(key, str):
306 # 'key' will be used as a keyword argument later, so Python
307 # requires it to be a string.
308 del lookup_params[key]
309 lookup_params[smart_str(key)] = value
310
311 employes_query = rh.Employe.objects
312 if 'o' in request.GET:
313 employes_query = employes_query.order_by("%s%s" % ('-' if 'ot' in request.GET and request.GET['ot'] == "desc" else '', request.GET['o']))
314
7c5645f0 315 employes = {}
22343fe7 316
00c9d7c2
OL
317 dossiers_en_cours = rh.Dossier.objects.filter(Q(date_fin=None) | Q(date_fin__gt=date.today()))
318 tous_contrats_echus = rh.Contrat.objects.filter(date_fin__lt=date.today(), dossier__in=dossiers_en_cours)
319 contrats = tous_contrats_echus.filter(**lookup_params).all()
320 for c in contrats:
321 if c.dossier.employe.id not in employes.keys():
322 employes[c.dossier.employe.id] = {'employe': c.dossier.employe, 'dossiers': []}
323 employes[c.dossier.employe.id]['dossiers'] += [c.dossier,]
22343fe7 324
00c9d7c2 325
c8b22fd1
JPC
326
327 headers = [
1d2d4dc2
JPC
328 ("id", u"# de l'employé"),
329 ("nom", u"Nom"),
330 ("prenom", u"Prénom"),
80518280 331 ("dossier", u"Dossiers"),
c8b22fd1 332 ]
80518280 333 h = SortHeaders(request, headers, order_field_type="ot", order_field="o", not_sortable=('dossier',))
c8b22fd1
JPC
334
335 c = {
336 'title': u'Rapport des employés sans contrat',
337 'employes': employes,
338 'count': len(employes),
339 'headers': list(h.headers()),
340 }
341
342 return render_to_response('rh/rapports/employes_sans_contrat.html', c, RequestContext(request))
343
344@login_required
345@drh_or_admin_required
857b5c24
JPC
346def rapports_postes_modelisation(request):
347 c = {}
348 data = []
3c1ba807
JPC
349
350 for f in rh.FamilleEmploi.objects.all():
351 types = rh.TypePoste.objects.filter(famille_emploi=f)
352 data_types = []
353 for t in types.all():
354 postes = rh.Poste.objects.filter(type_poste=t)
355 data_types.append({
356 'num_postes': postes.count(),
357 'postes': postes.all(),
358 'type': f,
857b5c24 359 })
3c1ba807 360
857b5c24 361 data.append({
3c1ba807
JPC
362 'famille': f,
363 'nb_types': types.count(),
364 'types' : data_types
857b5c24
JPC
365 })
366
367 c['data'] = data
368
369
370 return render_to_response('rh/rapports/postes_modelisation.html', c, RequestContext(request))
371
372
373@login_required
374@drh_or_admin_required
783e077a
JPC
375def rapports_postes_implantation(request):
376 c = {}
377 data = []
378 for r in ref.Region.objects.all():
379 implantations = []
380 for i in ref.Implantation.objects.filter(region=r):
381 implantations.append({
382 'implantation': i,
383 'postes': rh.Poste.objects.filter(implantation=i),
384 'num_postes': rh.Poste.objects.filter(implantation=i).count(),
385 })
386 data.append({
387 'region': r,
388 'implantations': implantations
389 })
390
391 c['data'] = data
392
393
394 return render_to_response('rh/rapports/postes_implantation.html', c, RequestContext(request))
395
396
397@login_required
398@drh_or_admin_required
399def rapports_postes_service(request):
400 c = {}
9988aafb
JPC
401 data = []
402 for s in rh.Service.objects.all():
403 postes = rh.Poste.objects.filter(service=s).all()
404 num_postes = rh.Poste.objects.filter(service=s).count()
22343fe7 405 data.append({'service': s, 'num_postes': num_postes, 'postes': postes})
783e077a 406
9988aafb
JPC
407 c['data'] = data
408 return render_to_response('rh/rapports/postes_service.html', c, RequestContext(request))
783e077a
JPC
409
410
32373f2e
OL
411def region_protected(model):
412 def wrapper(func):
413 def wrapped(request, id):
32373f2e
OL
414 if request.user.is_superuser:
415 return func(request, id)
416 user_groups = request.user.groups.all()
417 if grp_drh in user_groups:
418 return func(request, id)
419 if grp_correspondants_rh in user_groups:
420 employe = get_employe_from_user(request.user)
421 q = Q(**{model.prefix_implantation: employe.implantation.region})
422 qs = model.objects.filter(q)
718abc4d 423 if int(id) in [o.id for o in qs]:
32373f2e
OL
424 return func(request, id)
425 return redirect_interdiction(request)
426 return wrapped
427 return wrapper
428
429
430@region_protected(rh.Dossier)
3ebc0952 431def dossier_apercu(request, dossier_id):
baf9b78c 432 d = get_object_or_404(rh.Dossier, pk=dossier_id)
3ebc0952
OL
433 c = {
434 'is_popup' : request.GET.get('_popup', False),
baf9b78c 435 'dossier' : d,
520ab455
JPC
436 'pieces' : rh.DossierPiece.objects.filter(dossier__exact=d),
437 'contrats' : rh.Contrat.objects.filter(dossier__exact=d),
2a36598b 438 'commentaires' : rh.DossierCommentaire.objects.filter(dossier__exact=d).all(),
abf91905 439 'media_url': settings.PRIVE_MEDIA_URL,
3ebc0952
OL
440 }
441 return render_to_response('admin/rh/dossier/apercu.html', c, RequestContext(request))
4a1f2ece 442
fbe60a9d
OL
443@region_protected(rh.Poste)
444def poste_apercu(request, poste_id):
445 c = {
446 'is_popup' : request.GET.get('_popup', False),
0dcfc806
JPC
447 'poste' : get_object_or_404(rh.Poste, pk=poste_id),
448 'financements' : rh.PosteFinancement.objects.filter(poste=poste_id).all(),
449 'pieces' : rh.PostePiece.objects.filter(poste=poste_id).all(),
450 'dossiers' : rh.Dossier.objects.filter(poste=poste_id).order_by("-date_debut").all(),
451 'comparaisons' : rh.PosteComparaison.objects.filter(poste=poste_id).all(),
452 'commentaires' : rh.PosteCommentaire.objects.filter(poste=poste_id).all(),
abf91905 453 'media_url': settings.PRIVE_MEDIA_URL,
fbe60a9d
OL
454 }
455 return render_to_response('admin/rh/poste/apercu.html', c, RequestContext(request))
456
4a1f2ece
OL
457def employe_apercu(request, employe_id):
458 employe = get_object_or_404(rh.Employe, pk=employe_id)
fbe60a9d 459 user_groups = request.user.groups.all()
fbe60a9d
OL
460 dossiers = None
461
462 if request.user.is_superuser or \
463 grp_drh in user_groups:
464 q = Q(employe=employe)
465 if grp_correspondants_rh in user_groups:
7eeafa57 466 regions = [d.poste.implantation.region for d in employe.rh_dossiers.all()]
fbe60a9d 467 q = Q(employe=employe) & Q(implantation__region__in=regions)
22343fe7
OL
468
469 dossiers = rh.Dossier.objects.filter(q).order_by('-date_debut')
470
4a1f2ece
OL
471 c = {
472 'is_popup' : request.GET.get('_popup', False),
473 'employe' : employe,
fbe60a9d 474 'dossiers' : dossiers,
abf91905 475 'media_url': settings.PRIVE_MEDIA_URL,
4a1f2ece
OL
476 }
477 return render_to_response('admin/rh/employe/apercu.html', c, RequestContext(request))
150d83ec 478
77bd83d1
JPC
479@login_required
480@drh_or_admin_required
08faf06e
JPC
481def organigrammes_employe(request, id):
482
483 poste = get_object_or_404(rh.Poste, pk=id)
5c0f1778
JPC
484 dossiers_by_poste = dict((d.poste_id, d) for d in rh.Dossier.objects.select_related('employe', 'poste').all())
485 postes_by_id = dict((p.id, p) for p in rh.Poste.objects.all())
486
487 e = dossiers_by_poste[poste.id].employe
488 name = u"Organigramme de [%s] %s %s" % (e.id, e.nom.upper(), e.prenom)
242b2ec7 489 graph = nx.DiGraph(name=name.encode('ascii', 'xmlcharrefreplace'))
5c0f1778 490
f187a10f 491 if rh.Poste.objects.filter(responsable=poste).count() > 0:
f187a10f 492 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()
08faf06e 493
f187a10f
JPC
494 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():
495 graph.add_node(p.id)
32373f2e 496
f187a10f
JPC
497 for p in postes:
498 if p.responsable_id != p.id:
499 graph.add_edge(dossiers_by_poste[p.responsable_id].poste_id, p.id)
13ad5ad5 500
f187a10f 501 graph = nx.bfs_tree(graph, poste.id)
f187a10f 502 else:
5c0f1778
JPC
503 graph.add_node(poste.id)
504
505 a = nx.to_agraph(graph)
506
507 poste_remontant = poste
508 while poste_remontant.responsable_id:
509 a.add_edge(poste_remontant.responsable_id, poste_remontant.id)
510 poste_remontant = poste_remontant.responsable
511
512 rh_graph.bind_poste_to_graph(a, postes_by_id)
513 #a.graph_attr['normalize'] = True
514 #a.graph_attr['level'] = 2
515 a.layout(prog='dot')
516
517 svg = a.draw(format='svg')
518
519 c = {
520 'svg': svg
521 }
a251ac8d
JPC
522
523 if 'forcer' in request.GET:
524 response = HttpResponse(svg, mimetype='image/svg+xml')
525 response['Content-Disposition'] = 'attachment; filename=organigramme.svg'
526 return response
527
c548bef6 528 return render_to_response('rh/organigrammes/employe.html', c, RequestContext(request), mimetype="image/svg+xml")
5c0f1778
JPC
529
530
531@login_required
532@drh_or_admin_required
533def organigrammes_service(request, id):
534
535 service = get_object_or_404(rh.Service, pk=id)
536
537 postes_by_id = dict((p.id, p) for p in rh.Poste.objects.all())
538
539 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)) ).filter(service=service).exclude(supprime=True, responsable=None).all()
540
242b2ec7
JPC
541 nom = u"Organigramme de « %s »" % (service.nom)
542 nom = nom.encode('ascii', 'xmlcharrefreplace')
543 graph = pgv.AGraph(directed=True, name=nom)
5c0f1778
JPC
544 graph_service = graph.subgraph(nbunch=[1,2], \
545 name="cluster1", \
546 style='filled', \
547 color='lightgrey', \
242b2ec7 548 label=service.nom.encode('ascii', 'xmlcharrefreplace'),
5c0f1778
JPC
549 labeljust="l")
550
551 for p in postes:
552 graph_service.add_node(p.id)
553 if p.responsable_id:
554 graph.add_edge(p.responsable_id, p.id)
555
556 for p_id in graph_service.nodes():
557 if postes_by_id[int(p_id)].responsable_id:
558 poste_remontant = postes_by_id[int(p_id)]
559 while poste_remontant.responsable_id and poste_remontant.responsable_id and poste_remontant.responsable_id != poste_remontant.id:
560 poste_remontant = postes_by_id[poste_remontant.responsable_id]
561 if poste_remontant.responsable_id:
562 graph.add_edge(poste_remontant.responsable_id, poste_remontant.id)
563
564 rh_graph.bind_poste_to_graph(graph, postes_by_id)
565
566 graph.layout(prog='dot')
567
568 svg = graph.draw(format='svg')
569
570 c = {
571 'svg': svg
572 }
573
574 if 'forcer' in request.GET:
575 response = HttpResponse(svg, mimetype='image/svg+xml')
576 response['Content-Disposition'] = 'attachment; filename=organigramme.svg'
577 return response
578
579 return render_to_response('rh/organigrammes/service.html', c, RequestContext(request), mimetype="image/svg+xml")
580
581