Merge branch 'refactoring' of git.auf.org:auf_rh_dae into refactoring
[auf_rh_dae.git] / project / rh / views.py
1 # -*- encoding: utf-8 -*-
2
3 import urllib
4 from datetime import date
5 from itertools import izip
6 import StringIO
7
8 import pygraphviz as pgv
9
10 from django import forms
11 from django.conf import settings
12 from django.contrib.auth.decorators import login_required
13 from django.core.servers.basehttp import FileWrapper
14 from django.core.urlresolvers import reverse
15 from django.db.models import Q
16 from django.http import HttpResponse
17 from django.shortcuts import render_to_response, get_object_or_404
18 from django.template import RequestContext
19 from django.utils.encoding import smart_str
20
21 from datamaster_modeles import models as ref
22
23 from project.rh import models as rh
24 from project.rh.lib import calc_remun
25 from project.rh.decorators import drh_or_admin_required
26 from project.rh.templatetags.rapports import SortHeaders
27 from project.rh.change_list import RechercheTemporelle
28 from project.rh import graph as rh_graph
29 from project.rh.masse_salariale import MasseSalariale
30
31 # pas de reference a DAE devrait etre refactorisé
32 from project.dae.utils import get_employe_from_user
33 from project.dae.decorators import redirect_interdiction
34 from project.dae.workflow import grp_drh, grp_correspondants_rh
35
36
37 @login_required
38 def profil(request):
39 """Profil personnel de l'employé - éditable"""
40 rc = RequestContext(request)
41 c = {}
42
43 employe = rc['this_employe']
44
45 c['user'] = request.user
46 c['employe'] = employe
47 return render_to_response('rh/profil.html', c, rc)
48
49
50 @login_required
51 def employes_liste(request):
52 """Liste des employés."""
53 today = date.today()
54 employes = rh.Employe.objects \
55 .exclude(dossiers__date_debut__gt=today) \
56 .exclude(dossiers__date_fin__lt=today) \
57 .order_by('nom')
58 c = {
59 'user': request.user,
60 'employes': employes,
61 }
62 return render_to_response('rh/employes_liste.html',
63 c,
64 RequestContext(request))
65
66
67 @login_required
68 def employe(request, id):
69 """Information publique sur un employé."""
70 try:
71 employe = rh.Employe.objects.get(pk=id)
72 except:
73 employe = rh.Employe.objects.none()
74 c = {
75 'user': request.user,
76 'employe': employe,
77 }
78 return render_to_response('rh/employe.html', c, RequestContext(request))
79
80
81 @login_required
82 @drh_or_admin_required
83 def rapports_poste(request):
84
85 lookup_params = dict(request.GET.items())
86
87 for key, value in lookup_params.items():
88 if key == 'o' or key == 'ot':
89 del lookup_params[key]
90 continue
91 if not isinstance(key, str):
92 # 'key' will be used as a keyword argument later, so Python
93 # requires it to be a string.
94 del lookup_params[key]
95 lookup_params[smart_str(key)] = value
96
97 if key == 'comble':
98 del lookup_params[key]
99
100 sort_order = 'ASC' if request.GET.get('ot') == 'asc' else 'DESC'
101
102 postes = rh.Poste.objects.select_related('implantation') \
103 .extra(select={
104 'employe_id':
105 'SELECT GROUP_CONCAT(employe SEPARATOR "|") '
106 'FROM rh_dossier '
107 'WHERE poste = rh_poste.id '
108 'AND rh_dossier.date_fin IS NULL ' + (
109 'ORDER BY employe ' + sort_order
110 if request.GET.get('o') == 'employe_id' else ''
111 )
112 }) \
113 .extra(select={
114 'employe_nom':
115 'SELECT GROUP_CONCAT(rh_employe.nom SEPARATOR "|") '
116 'FROM rh_dossier INNER JOIN rh_employe '
117 'ON rh_dossier.employe = rh_employe.id '
118 'WHERE poste = rh_poste.id '
119 'AND rh_dossier.date_fin IS NULL ' + (
120 'ORDER BY rh_employe.nom ' + sort_order
121 if request.GET.get('o') == 'employe_nom' else ''
122 )
123 }) \
124 .extra(select={
125 'employe_prenom':
126 'SELECT GROUP_CONCAT(rh_employe.prenom SEPARATOR "|") '
127 'FROM rh_dossier INNER JOIN rh_employe '
128 'ON rh_dossier.employe = rh_employe.id '
129 'WHERE poste = rh_poste.id '
130 'AND rh_dossier.date_fin IS NULL ' + (
131 'ORDER BY rh_employe.prenom ' + sort_order
132 if request.GET.get('o') == 'employe_prenom' else ''
133 )
134 })
135
136 postes = postes.filter(**lookup_params)
137 if 'o' in request.GET:
138 postes = postes.order_by(
139 ('-' if sort_order == "DESC" else '') + request.GET['o']
140 )
141
142 out = []
143 for p in postes:
144 out.append({
145 'id': p.id,
146 'nom': p.nom,
147 'implantation': p.implantation,
148 'employes': [] if not p.employe_id else [
149 {'id': id, 'nom': nom, 'prenom': prenom}
150 for id, nom, prenom in izip(
151 p.employe_id.split('|'),
152 p.employe_nom.split('|'),
153 p.employe_prenom.split('|')
154 )
155 ]
156 })
157
158 headers = [
159 ("id", u"# du poste"),
160 ("nom", u"Nom du poste"),
161 ("implantation__id", u"Implantation"),
162 ("employe_nom", u"Nom"),
163 ]
164 h = SortHeaders(request, headers, order_field_type="ot", order_field="o")
165 c = {
166 'title': 'Rapport des postes',
167 'postes': out,
168 'count': len(out),
169 'headers': list(h.headers()),
170 }
171
172 return render_to_response(
173 'rh/rapports/postes.html', c, RequestContext(request)
174 )
175
176
177 @login_required
178 @drh_or_admin_required
179 def rapports_contrat(request):
180 if 'HTTP_REFERER' in request.META.keys():
181 referer = request.META['HTTP_REFERER']
182 referer = "/".join(referer.split('/')[3:])
183 referer = "/%s" % referer.split('?')[0]
184 if referer != reverse('rhr_contrats'):
185 params = request.GET.copy()
186 params.update({'statut': 'Actif'})
187 request.GET = params
188
189 lookup_params = dict(request.GET.items())
190 if 'ot' in lookup_params:
191 del lookup_params['ot']
192 if 'o' in lookup_params:
193 del lookup_params['o']
194
195 for key, value in lookup_params.items():
196 if not isinstance(key, str):
197 # 'key' will be used as a keyword argument later, so Python
198 # requires it to be a string.
199 del lookup_params[key]
200 lookup_params[smart_str(key)] = value
201
202 contrats = rh.Contrat.objects.select_related(
203 'dossier', 'dossier__poste', 'dossier__poste__implantation',
204 'type_contrat', 'dossier__employe'
205 )
206
207 cl = RechercheTemporelle(dict(request.GET.items()), rh.Contrat)
208 lookup_params = cl.purge_params(lookup_params)
209 q_temporel = cl.get_q_temporel(contrats)
210 q = Q(**lookup_params) & q_temporel
211 contrats = contrats.filter(q).exclude(dossier__employe__supprime=1)
212
213 if 'o' in request.GET:
214 contrats = contrats.order_by(
215 ('-' if request.GET.get('ot') == "desc" else '') + request.GET['o']
216 )
217
218 employes = set([c.dossier.employe_id for c in contrats])
219
220 headers = [
221 ("dossier__employe__id", u"# de l'employé"),
222 ("dossier__employe__nom", u"Employé"),
223 ("type_contrat__nom", u"Poste"),
224 ("dossier__poste__implantation__region", u"Région"),
225 ("dossier__poste__implantation", u"Implantation"),
226 ("type_contrat__nom", u"Type de contrat"),
227 ("date_debut", u"Date début"),
228 ("date_fin", u"Date fin"),
229 ]
230 h = SortHeaders(request, headers, order_field_type="ot", order_field="o")
231
232 c = {
233 'cl': cl,
234 'title': 'Rapport des contrats',
235 'contrats': contrats,
236 'count': len(contrats),
237 'count_employe': len(employes),
238 'headers': list(h.headers()),
239 }
240
241 return render_to_response(
242 'rh/rapports/contrats.html', c, RequestContext(request)
243 )
244
245
246 @login_required
247 @drh_or_admin_required
248 def rapports_masse_salariale(request):
249
250 class RechercheTemporelle(forms.Form):
251 CHOICE_ANNEES = range(
252 rh.Remuneration.objects.exclude(date_debut=None)
253 .order_by('date_debut')[0].date_debut.year,
254 date.today().year + 1
255 )
256
257 annee = forms.CharField(
258 initial=date.today().year,
259 widget=forms.Select(
260 choices=((a, a) for a in reversed(CHOICE_ANNEES))
261 )
262 )
263
264 region = forms.CharField(
265 widget=forms.Select(choices=[('', '')] +
266 [(i.id, i) for i in ref.Region.objects.all()]
267 )
268 )
269
270 implantation = forms.CharField(
271 widget=forms.Select(choices=[('', '')] +
272 [(i.id, i) for i in ref.Implantation.objects.all()]
273 )
274 )
275
276 #date_debut = forms.DateField(widget=adminwidgets.AdminDateWidget)
277 #date_fin = forms.DateField(widget=adminwidgets.AdminDateWidget)
278
279 form = RechercheTemporelle(request.GET)
280 get_filtre = [
281 (k, v) for k, v in request.GET.items()
282 if k not in ('date_debut', 'date_fin', 'implantation')
283 ]
284 query_string = urllib.urlencode(get_filtre)
285
286 date_debut = None
287 date_fin = None
288 if request.GET.get('annee', None):
289 date_debut = "01-01-%s" % request.GET.get('annee', None)
290 date_fin = "31-12-%s" % request.GET.get('annee', None)
291
292 implantation = request.GET.get('implantation')
293 region = request.GET.get('region')
294
295 custom_filter = {}
296 if implantation:
297 custom_filter['dossier__poste__implantation'] = implantation
298 if region:
299 custom_filter['dossier__poste__implantation__region'] = region
300
301 c = {
302 'title': 'Rapport de masse salariale',
303 'form': form,
304 'headers': [],
305 'query_string': query_string,
306 }
307 if date_debut or date_fin:
308 masse = MasseSalariale(date_debut, date_fin, custom_filter,
309 request.GET.get('ne_pas_grouper', False))
310 if masse.rapport:
311 if request.GET.get('ods'):
312 for h in (
313 h for h in masse.headers if 'background-color' in h[2]
314 ):
315 del h[2]['background-color']
316 masse.ods()
317 output = StringIO.StringIO()
318 masse.doc.save(output)
319 output.seek(0)
320
321 response = HttpResponse(
322 FileWrapper(output),
323 content_type=(
324 'application/vnd.oasis.opendocument.spreadsheet'
325 )
326 )
327 response['Content-Disposition'] = \
328 'attachment; filename=Masse Salariale %s.ods' % \
329 masse.annee
330 return response
331 else:
332 c['rapport'] = masse.rapport
333 c['header_keys'] = [h[0] for h in masse.headers]
334 #on enleve le background pour le header
335 for h in (
336 h for h in masse.headers if 'background-color' in h[2]
337 ):
338 h[2]['background'] = 'none'
339 h = SortHeaders(request, masse.headers, order_field_type="ot",
340 not_sortable=c['header_keys'], order_field="o")
341 c['headers'] = list(h.headers())
342 for key, nom, opts in masse.headers:
343 c['headers']
344 c['total'] = masse.grand_totaux[0]
345 c['total_euro'] = masse.grand_totaux[1]
346 c['colspan'] = len(c['header_keys']) - 1
347 get_filtre.append(('ods', True))
348 query_string = urllib.urlencode(get_filtre)
349 c['url_ods'] = "%s?%s" % (
350 reverse('rhr_masse_salariale'), query_string)
351
352 return render_to_response(
353 'rh/rapports/masse_salariale.html', c, RequestContext(request)
354 )
355
356
357 @login_required
358 @drh_or_admin_required
359 def rapports_remuneration(request):
360
361 lookup_params = dict(request.GET.items())
362 if 'ot' in lookup_params:
363 del lookup_params['ot']
364 if 'o' in lookup_params:
365 del lookup_params['o']
366
367 for key, value in lookup_params.items():
368 if not isinstance(key, str):
369 # 'key' will be used as a keyword argument later, so Python
370 # requires it to be a string.
371 del lookup_params[key]
372 lookup_params[smart_str(key)] = value
373
374 employes = rh.Employe.objects.all()
375 if 'o' in request.GET:
376 employes = employes.order_by(
377 ('-' if request.GET.get('ot') == "desc" else '') + request.GET['o']
378 )
379
380 employes = employes.filter(**lookup_params)
381
382 output = []
383 headers = [
384 ("id", u"# de l'employé"),
385 ("nom", u"Nom"),
386 ("prenom", u"Prénom"),
387 ("", u"Salaire"),
388 ("", u"RAS"),
389 ("", u"Indemnités"),
390 ("", u"Accessoire"),
391 ("", u"Charges patronales"),
392 ("", u"Total"),
393 ]
394 h = SortHeaders(request, headers, order_field_type="ot", order_field="o")
395
396 for employe in employes:
397 line = {}
398 output.append(line)
399
400 dossiers = employe.rh_dossiers.all()
401
402 remun = {}
403 remun_sum_euro = 0
404
405 for dossier in dossiers:
406 this_remun, this_remun_sum, this_remun_sum_euro = \
407 calc_remun(dossier)
408
409 for item in this_remun:
410 if item not in remun:
411 remun[item] = this_remun[item]
412 else:
413 remun[item][0] += this_remun[item][0]
414 remun[item][1] += this_remun[item][1]
415
416 remun_sum_euro += this_remun_sum_euro
417
418 line['remun_sum_euro'] = remun_sum_euro
419
420 for r in remun:
421 if r == u'Indemnité':
422 line['Indemnite'] = remun[r][1]
423 else:
424 line[r] = remun[r][1]
425
426 line['id'] = employe.id
427 line['nom'] = employe.nom
428 line['prenom'] = employe.prenom
429
430 c = {
431 'title': 'Rapport de remuneration',
432 'employes': output,
433 'headers': list(h.headers()),
434 }
435
436 return render_to_response(
437 'rh/rapports/remuneration.html', c, RequestContext(request)
438 )
439
440
441 @login_required
442 @drh_or_admin_required
443 def rapports_employe_sans_contrat(request):
444
445 lookup_params = dict(request.GET.items())
446 if 'ot' in lookup_params:
447 del lookup_params['ot']
448 if 'o' in lookup_params:
449 del lookup_params['o']
450
451 for key, value in lookup_params.items():
452 if not isinstance(key, str):
453 # 'key' will be used as a keyword argument later, so Python
454 # requires it to be a string.
455 del lookup_params[key]
456 lookup_params[smart_str(key)] = value
457
458 employes_query = rh.Employe.objects
459 if 'o' in request.GET:
460 employes_query = employes_query.order_by(
461 ('-' if request.GET.get('ot') == "desc" else '') + request.GET['o']
462 )
463
464 employes = {}
465
466 dossiers_en_cours = rh.Dossier.objects.filter(
467 Q(date_fin=None) | Q(date_fin__gt=date.today())
468 )
469 tous_contrats_echus = rh.Contrat.objects.filter(
470 date_fin__lt=date.today(), dossier__in=dossiers_en_cours
471 )
472 contrats = tous_contrats_echus.filter(**lookup_params).all()
473 for c in contrats:
474 if c.dossier.employe.id not in employes.keys():
475 employes[c.dossier.employe.id] = {
476 'employe': c.dossier.employe,
477 'dossiers': []
478 }
479 employes[c.dossier.employe.id]['dossiers'] += [c.dossier]
480
481 headers = [
482 ("id", u"# de l'employé"),
483 ("nom", u"Nom"),
484 ("prenom", u"Prénom"),
485 ("dossier", u"Dossiers"),
486 ]
487 h = SortHeaders(
488 request, headers, order_field_type="ot", order_field="o",
489 not_sortable=('dossier',)
490 )
491
492 c = {
493 'title': u'Rapport des employés sans contrat',
494 'employes': employes,
495 'count': len(employes),
496 'headers': list(h.headers()),
497 }
498
499 return render_to_response(
500 'rh/rapports/employes_sans_contrat.html', c, RequestContext(request)
501 )
502
503
504 @login_required
505 @drh_or_admin_required
506 def rapports_postes_modelisation(request):
507 c = {}
508 data = []
509
510 for categorie in rh.CategorieEmploi.objects.all():
511 types = rh.TypePoste.objects.filter(categorie_emploi=categorie)
512 data_types = []
513 for t in types.all():
514 postes = rh.Poste.objects.filter(type_poste=t)
515 data_types.append({
516 'num_postes': postes.count(),
517 'postes': postes.all(),
518 'type': categorie,
519 })
520
521 data.append({
522 'categorie': categorie,
523 'nb_types': types.count(),
524 'types': data_types
525 })
526
527 c['data'] = data
528
529 return render_to_response(
530 'rh/rapports/postes_modelisation.html', c, RequestContext(request)
531 )
532
533
534 @login_required
535 @drh_or_admin_required
536 def rapports_postes_implantation(request):
537 c = {}
538 data = []
539 for r in ref.Region.objects.all():
540 implantations = []
541 for i in ref.Implantation.objects.filter(region=r):
542 implantations.append({
543 'implantation': i,
544 'postes': rh.Poste.objects.filter(implantation=i),
545 'num_postes': rh.Poste.objects.filter(implantation=i).count(),
546 })
547 data.append({
548 'region': r,
549 'implantations': implantations
550 })
551
552 c['data'] = data
553
554 return render_to_response(
555 'rh/rapports/postes_implantation.html', c, RequestContext(request)
556 )
557
558
559 @login_required
560 @drh_or_admin_required
561 def rapports_postes_service(request):
562 c = {}
563 data = []
564 for s in rh.Service.objects.all():
565 postes = rh.Poste.objects.filter(service=s).all()
566 num_postes = rh.Poste.objects.filter(service=s).count()
567 data.append({'service': s, 'num_postes': num_postes, 'postes': postes})
568
569 c['data'] = data
570 return render_to_response(
571 'rh/rapports/postes_service.html', c, RequestContext(request)
572 )
573
574
575 def region_protected(model):
576 def wrapper(func):
577 def wrapped(request, id):
578 if request.user.is_superuser:
579 return func(request, id)
580 user_groups = request.user.groups.all()
581 if grp_drh in user_groups:
582 return func(request, id)
583 if grp_correspondants_rh in user_groups:
584 employe = get_employe_from_user(request.user)
585 q = Q(**{
586 model.prefix_implantation: employe.implantation.region
587 })
588 qs = model.objects.filter(q)
589 if int(id) in [o.id for o in qs]:
590 return func(request, id)
591 return redirect_interdiction(request)
592 return wrapped
593 return wrapper
594
595
596 @region_protected(rh.Dossier)
597 def dossier_apercu(request, dossier_id):
598 d = get_object_or_404(rh.Dossier, pk=dossier_id)
599 c = {
600 'title': u"Dossier %s" % (d, ),
601 'is_popup': request.GET.get('_popup', False),
602 'dossier': d,
603 'pieces': rh.DossierPiece.objects.filter(dossier__exact=d),
604 'contrats': rh.Contrat.objects.filter(dossier__exact=d),
605 'commentaires': rh.DossierCommentaire.objects.filter(dossier=d).all(),
606 'media_url': settings.PRIVE_MEDIA_URL,
607 }
608 return render_to_response(
609 'admin/rh/dossier/apercu.html', c, RequestContext(request)
610 )
611
612
613 @region_protected(rh.Poste)
614 def poste_apercu(request, poste_id):
615 p = get_object_or_404(rh.Poste, pk=poste_id)
616 c = {
617 'title': u"Poste %s" % (p, ),
618 'is_popup': request.GET.get('_popup', False),
619 'poste': p,
620 'financements': (
621 rh.PosteFinancement.objects.filter(poste=poste_id).all()
622 ),
623 'pieces': rh.PostePiece.objects.filter(poste=poste_id).all(),
624 'dossiers': (
625 rh.Dossier.objects.filter(poste=poste_id)
626 .order_by("-date_debut").all()
627 ),
628 'comparaisons': (
629 rh.PosteComparaison.objects.filter(poste=poste_id).all()
630 ),
631 'commentaires': (
632 rh.PosteCommentaire.objects.filter(poste=poste_id).all()
633 ),
634 'media_url': settings.PRIVE_MEDIA_URL,
635 }
636 return render_to_response(
637 'admin/rh/poste/apercu.html', c, RequestContext(request)
638 )
639
640
641 def employe_apercu(request, employe_id):
642 employe = get_object_or_404(rh.Employe, pk=employe_id)
643 user_groups = request.user.groups.all()
644 dossiers = None
645
646 if request.user.is_superuser or \
647 grp_drh in user_groups:
648 q = Q(employe=employe)
649 if grp_correspondants_rh in user_groups:
650 regions = [
651 d.poste.implantation.region for d in employe.rh_dossiers.all()
652 ]
653 q = Q(employe=employe) & Q(implantation__region__in=regions)
654
655 dossiers = rh.Dossier.objects.filter(q).order_by('-date_debut')
656
657 c = {
658 'title': u"Employe %s" % (employe, ),
659 'is_popup': request.GET.get('_popup', False),
660 'employe': employe,
661 'dossiers': dossiers,
662 'media_url': settings.PRIVE_MEDIA_URL,
663 }
664 return render_to_response(
665 'admin/rh/employe/apercu.html', c, RequestContext(request)
666 )
667
668
669 @login_required
670 @drh_or_admin_required
671 def organigrammes_employe(request, id, level="all"):
672
673 poste = get_object_or_404(rh.Poste, pk=id)
674 dossiers_by_poste = dict(
675 (d.poste_id, d)
676 for d in rh.Dossier.objects.select_related('employe', 'poste').all()
677 )
678 postes_by_id = dict((p.id, p) for p in rh.Poste.objects.all())
679
680 e = dossiers_by_poste[poste.id].employe
681 name = u"Organigramme de [%s] %s %s" % (e.id, e.nom.upper(), e.prenom)
682 graph = pgv.AGraph()
683
684 if rh.Poste.objects.filter(responsable=poste).count() > 0:
685 postes_handle = [poste]
686 while postes_handle:
687 postes_handle = rh.Poste.objects.select_related('implantation') \
688 .filter(
689 Q(date_fin__gt=date.today()) | Q(date_fin=None),
690 Q(date_debut__lt=date.today()) | Q(date_debut=None),
691 responsable__in=postes_handle
692 ).exclude(supprime=True).exclude(responsable=None).all()
693
694 for p in postes_handle:
695 if p.responsable_id != p.id:
696 graph.add_edge(
697 dossiers_by_poste[p.responsable_id].poste_id, p.id
698 )
699
700 else:
701 graph.add_node(poste.id)
702
703 if level != "all":
704 postes_niveau = [poste.id]
705 for niveau in range(int(level)):
706 postes_niveau = [
707 p.id for p in
708 rh.Poste.objects.filter(responsable__in=postes_niveau).all()
709 ]
710
711 while postes_niveau:
712 postes_niveau = [
713 p.id for p in
714 rh.Poste.objects.filter(responsable__in=postes_niveau).all()
715 ]
716 if postes_niveau:
717 for p in postes_niveau:
718 if graph.has_node(p):
719 graph.delete_node(p)
720
721 a = graph
722 a.name = name.encode('ascii', 'xmlcharrefreplace')
723
724 poste_remontant = poste
725 while poste_remontant.responsable_id:
726 a.add_edge(poste_remontant.responsable_id, poste_remontant.id)
727 poste_remontant = poste_remontant.responsable
728
729 rh_graph.bind_poste_to_graph(a, postes_by_id)
730 #a.graph_attr['normalize'] = True
731 #a.graph_attr['level'] = 2
732 a.layout(prog='dot')
733
734 svg = a.draw(format='svg')
735
736 c = {
737 'svg': svg
738 }
739
740 if 'forcer' in request.GET:
741 response = HttpResponse(svg, mimetype='image/svg+xml')
742 response['Content-Disposition'] = \
743 'attachment; filename=organigramme.svg'
744 return response
745
746 return render_to_response(
747 'rh/organigrammes/employe.html', c, RequestContext(request),
748 mimetype="image/svg+xml"
749 )
750
751
752 @login_required
753 @drh_or_admin_required
754 def organigrammes_service(request, id):
755
756 service = get_object_or_404(rh.Service, pk=id)
757 svg = rh_graph.organigramme_postes_cluster( \
758 cluster_filter={"service": service}, \
759 titre=u"Organigramme du service %s" % service.nom,
760 cluster_titre=service.nom)
761
762 c = {
763 'svg': svg
764 }
765
766 return render_to_response(
767 'rh/organigrammes/vide.html', c, RequestContext(request),
768 mimetype="image/svg+xml"
769 )
770
771
772 @login_required
773 @drh_or_admin_required
774 def organigrammes_implantation(request, id):
775
776 implantation = get_object_or_404(ref.Implantation, pk=id)
777 svg = rh_graph.organigramme_postes_cluster( \
778 cluster_filter={"implantation": implantation}, \
779 titre=u"Organigramme de l'implantation %s" % implantation.nom,
780 cluster_titre=implantation.nom)
781
782 c = {
783 'svg': svg
784 }
785
786 return render_to_response(
787 'rh/organigrammes/vide.html', c, RequestContext(request),
788 mimetype="image/svg+xml"
789 )
790
791
792 @login_required
793 @drh_or_admin_required
794 def organigrammes_region(request, id):
795
796 region = get_object_or_404(ref.Region, pk=id)
797 svg = rh_graph.organigramme_postes_cluster( \
798 cluster_filter={"implantation__region": region}, \
799 titre=u"Organigramme du bureau de %s" % region.nom,
800 cluster_titre=region.nom)
801
802 c = {
803 'svg': svg
804 }
805
806 return render_to_response(
807 'rh/organigrammes/vide.html', c, RequestContext(request),
808 mimetype="image/svg+xml"
809 )