fix restore recherche temporelle
[auf_rh_dae.git] / project / rh / admin.py
CommitLineData
53ae644d
OL
1# -*- encoding: utf-8 -*-
2
53ae644d 3import datetime
6fb68b2f 4
d104b0ae
EMS
5import reversion
6from ajax_select import make_ajax_form
d104b0ae 7from auf.django.references import models as ref
45066657 8from django import forms
53ae644d 9from django.core.urlresolvers import reverse
50fa9bc1 10from django.contrib import admin
45066657 11from django.contrib.contenttypes.models import ContentType
53ae644d 12from django.conf import settings
f7badf51 13from django.db.models import Q, Count
5f36f262 14from django.template.defaultfilters import date
5db1c5a3 15from django.utils.formats import date_format
fc4bf968 16
018c8eaf 17from project.decorators import in_drh_or_admin
d41d8e47 18from project.groups import grp_correspondants_rh
afd3be54 19from project.groups import get_employe_from_user
d104b0ae 20from project.rh import models as rh
75f0e87b 21from project.rh.change_list import ChangeList
6fb68b2f
DB
22from project.rh.forms import ContratForm, AyantDroitForm, EmployeAdminForm, \
23 AjaxSelect, DossierForm, ResponsableInlineForm
fc4bf968 24
82af5c19 25
08a9b6fc
EMS
26class BaseAdmin(admin.ModelAdmin):
27
28 class Media:
dd6c0df2
EMS
29 css = {'screen': (
30 'css/admin_custom.css',
31 'jquery-autocomplete/jquery.autocomplete.css',
32 )}
33 js = (
34 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
35 'jquery-autocomplete/jquery.autocomplete.min.js',
36 )
08a9b6fc
EMS
37
38
45066657
EMS
39# Admin pour reversion
40
7013d234 41class ArchivableAdmin(admin.ModelAdmin):
7ba822a6 42 """
7013d234 43 Admin pour les modèles archivables
7ba822a6 44 """
7013d234 45 list_filter = ('archive', )
7ba822a6
OL
46
47 def queryset(self, request):
7013d234 48 return self.model.avec_archives.all()
7ba822a6
OL
49
50 def _archive(self, obj):
51 if obj.archive:
52 return "oui"
53 else:
54 return "non"
55 _archive.short_description = u'Archivé'
56 _archive.admin_order_field = 'archive'
57
fc4bf968 58
9da4c195
JPC
59class RegionProxy(ref.Region):
60 """ Proxy utilisé pour les organigrammes par région """
61 class Meta:
62 proxy = True
63 verbose_name = u"Organigramme par région"
64 verbose_name_plural = u"Organigramme par région"
65
66
82af5c19
JPC
67class ImplantationProxy(ref.Implantation):
68 """ Proxy utilisé pour les organigrammes par implantation """
69 class Meta:
70 proxy = True
71 verbose_name = u"Organigramme par implantations"
72 verbose_name_plural = u"Organigramme par implantations"
73
22343fe7 74
5c0f1778
JPC
75class ServiceProxy(rh.Service):
76 """ Proxy utilisé pour les organigrammes opar service """
f7badf51 77
5c0f1778
JPC
78 class Meta:
79 proxy = True
80 verbose_name = u"Organigramme par services"
81 verbose_name_plural = u"Organigramme par services"
82
22343fe7 83
5c0f1778
JPC
84class EmployeProxy(rh.Employe):
85 """ Proxy utilisé pour les organigrammes des employés """
22343fe7
OL
86 class Meta:
87 proxy = True
88 verbose_name = u"Organigramme des employés"
89 verbose_name_plural = u"Organigramme des employés"
90
f614ca5c 91
40b35603 92class DateRangeMixin(object):
a17e2236 93 prefixe_recherche_temporelle = ""
22343fe7 94
40b35603 95 def get_changelist(self, request, **kwargs):
22343fe7 96 if 'HTTP_REFERER' in request.META.keys():
910e39e5
OL
97 referer = request.META['HTTP_REFERER']
98 referer = "/".join(referer.split('/')[3:])
99 referer = "/%s" % referer.split('?')[0]
22343fe7
OL
100 change_list_view = 'admin:%s_%s_changelist' % (
101 self.model._meta.app_label,
102 self.model.__name__.lower(),)
910e39e5
OL
103 if referer != reverse(change_list_view):
104 params = request.GET.copy()
22343fe7 105 params.update({'statut': 'Actif'})
910e39e5 106 request.GET = params
40b35603 107 return ChangeList
3195667e 108
22343fe7 109
53ae644d
OL
110# Override of the InlineModelAdmin to support the link in the tabular inline
111class LinkedInline(admin.options.InlineModelAdmin):
112 template = "admin/linked.html"
113 admin_model_path = None
114
115 def __init__(self, *args):
116 super(LinkedInline, self).__init__(*args)
117 if self.admin_model_path is None:
118 self.admin_model_path = self.model.__name__.lower()
119
120
121class ProtectRegionMixin(object):
122
123 def queryset(self, request):
53ae644d
OL
124 qs = super(ProtectRegionMixin, self).queryset(request)
125
53ae644d 126 user_groups = request.user.groups.all()
a12ddd52 127 if in_drh_or_admin(request.user):
53ae644d
OL
128 return qs
129
130 if grp_correspondants_rh in user_groups:
131 employe = get_employe_from_user(request.user)
22343fe7
OL
132 q = Q(**{self.model.prefix_implantation: \
133 employe.implantation.region})
53ae644d
OL
134 qs = qs.filter(q).distinct()
135 return qs
136 return qs.none()
137
c0be8705
OL
138 def has_add_permission(self, request):
139 if not in_drh_or_admin(request.user):
140 return False
141 else:
142 return True
143
53ae644d 144 def has_change_permission(self, request, obj=None):
20b4867c 145 user_groups = request.user.groups.all()
a0d365ed 146
0309aeb4
DB
147 # Lock pour autoriser uniquement les DRH à utiliser RH
148 if not in_drh_or_admin(request.user):
149 return False
150
a18bc295 151 if len(user_groups) == 0 and not request.user.is_superuser:
20b4867c
OL
152 return False
153
53ae644d
OL
154 if obj is None:
155 return True
156 ids = [o.id for o in self.queryset(request)]
157 return obj.id in ids
158
159
45066657
EMS
160class DerniereModificationAdmin(admin.ModelAdmin):
161
162 def queryset(self, request):
163 qs = super(DerniereModificationAdmin, self).queryset(request)
164 ct = ContentType.objects.get_for_model(self.model)
165 db_table = self.model._meta.db_table
166 pk = self.model._meta.pk.column
167 return qs.extra(select={
168 'date_modification':
169 "SELECT action_time FROM django_admin_log "
170 "WHERE content_type_id = %d AND object_id = %s.%s "
171 "ORDER BY action_time DESC "
172 "LIMIT 1" % (ct.id, db_table, pk),
173 'user_modification':
174 "SELECT u.username "
175 "FROM auth_user u "
176 "INNER JOIN django_admin_log l ON l.user_id = u.id "
177 "WHERE l.content_type_id = %d AND object_id = %s.%s "
178 "ORDER BY action_time DESC "
179 "LIMIT 1" % (ct.id, db_table, pk),
180 })
181
182 def derniere_modification(self, obj):
183 text = ''
184 if obj.date_modification:
185 text += obj.date_modification.strftime('%d-%m-%Y %H:%M')
186 if obj.user_modification:
187 text += ' par ' + obj.user_modification
188 return text
189 derniere_modification.short_description = u'dernière modification'
190 derniere_modification.admin_order_field = 'date_modification'
191
192
53ae644d
OL
193# Inlines
194
45066657
EMS
195class CommentaireInlineForm(forms.ModelForm):
196
197 def save(self, commit=True):
198
199 # Hack: reversion.VersionAdmin ne sauvegarde pas les champs qui ne
200 # sont pas explicitement dans le formulaire. Il plante cependant
201 # leur valeur dans `self.initial`. Ceci est un peu fragile. Si
202 # c'est possible, il serait plus approprié que Reversion se rende
203 # compte qu'il manque des champs.
204 instance = super(CommentaireInlineForm, self).save(commit=False)
205 if instance.owner_id is None and 'owner' in self.initial:
206 instance.owner_id = self.initial['owner']
207 if instance.date_creation is None and 'date_creation' in self.initial:
208 instance.date_creation = self.initial['date_creation']
209 if commit:
210 instance.save()
211 self.save_m2m()
212 return instance
213
214
53ae644d 215class ReadOnlyInlineMixin(object):
22343fe7 216
53ae644d 217 def get_readonly_fields(self, request, obj=None):
45066657 218 return [f.name for f in self.model._meta.fields]
53ae644d
OL
219
220
45066657 221class AyantDroitInline(admin.StackedInline):
53ae644d
OL
222 model = rh.AyantDroit
223 form = AyantDroitForm
224 extra = 0
225
226 fieldsets = (
227 (None, {
22343fe7
OL
228 'fields': (
229 ('nom', 'prenom'),
230 ('nom_affichage', 'genre'),
231 'nationalite',
232 'date_naissance',
233 'lien_parente',
234 )}),
53ae644d
OL
235 )
236
237
45066657
EMS
238class AyantDroitCommentaireInline(admin.TabularInline):
239 readonly_fields = ('owner',)
53ae644d
OL
240 model = rh.AyantDroitCommentaire
241 extra = 1
45066657 242 form = CommentaireInlineForm
53ae644d
OL
243
244
45066657 245class ContratInline(admin.TabularInline):
53ae644d
OL
246 form = ContratForm
247 model = rh.Contrat
248 extra = 1
249
250
251class DossierROInline(ReadOnlyInlineMixin, LinkedInline):
252 template = "admin/rh/dossier/linked.html"
53ae644d
OL
253 model = rh.Dossier
254 extra = 0
255 can_delete = False
256
257 def has_add_permission(self, request=None):
258 return False
259
260 def has_change_permission(self, request, obj=None):
261 return False
262
263 def has_delete_permission(self, request, obj=None):
264 return False
265
266
45066657
EMS
267class DossierCommentaireInline(admin.TabularInline):
268 readonly_fields = ('owner',)
53ae644d
OL
269 model = rh.DossierCommentaire
270 extra = 1
45066657 271 form = CommentaireInlineForm
53ae644d
OL
272
273
274class DossierPieceInline(admin.TabularInline):
275 model = rh.DossierPiece
276 extra = 4
277
278
279class EmployeInline(admin.TabularInline):
280 model = rh.Employe
281
22343fe7 282
45066657
EMS
283class EmployeCommentaireInline(admin.TabularInline):
284 readonly_fields = ('owner',)
53ae644d
OL
285 model = rh.EmployeCommentaire
286 extra = 1
45066657 287 form = CommentaireInlineForm
53ae644d
OL
288
289
290class EmployePieceInline(admin.TabularInline):
291 model = rh.EmployePiece
292 extra = 4
293
294
45066657
EMS
295class PosteCommentaireInline(admin.TabularInline):
296 readonly_fields = ('owner',)
53ae644d
OL
297 model = rh.PosteCommentaire
298 extra = 1
45066657 299 form = CommentaireInlineForm
53ae644d
OL
300
301
302class PosteFinancementInline(admin.TabularInline):
303 model = rh.PosteFinancement
304
305
306class PostePieceInline(admin.TabularInline):
307 model = rh.PostePiece
308
309
45066657 310class RemunerationInline(admin.TabularInline):
53ae644d
OL
311 model = rh.Remuneration
312 extra = 1
313
314
315class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
316 pass
317
318
45066657 319class TypePosteInline(admin.TabularInline):
53ae644d
OL
320 model = rh.TypePoste
321
322
45066657 323class PosteComparaisonInline(admin.TabularInline):
6f037929
OL
324 model = rh.PosteComparaison
325
53ae644d 326
45066657
EMS
327class ClassementAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
328 BaseAdmin):
329 ignore_duplicate_revisions = True
330 list_display = ('_classement', 'derniere_modification')
331 fieldsets = (
332 (None, {'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
53ae644d
OL
333 )
334
c5964dc2
OL
335 def _classement(self, obj):
336 return unicode(obj)
337 _classement.short_description = u"Classement"
53ae644d 338
d104b0ae 339
7013d234 340class DeviseAdmin(reversion.VersionAdmin, ArchivableAdmin,
45066657
EMS
341 DerniereModificationAdmin, BaseAdmin):
342 ignore_duplicate_revisions = True
22343fe7 343 list_display = (
45066657
EMS
344 'code', 'nom', '_archive', 'derniere_modification',
345 )
edb35076 346 list_filter = ('archive', )
45066657
EMS
347 fieldsets = (
348 (None, {'fields': ('code', 'nom', 'archive', )}),
53ae644d
OL
349 )
350
22343fe7 351
45066657
EMS
352class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
353 AjaxSelect, DerniereModificationAdmin, BaseAdmin):
b2d1cc93 354 change_list_template = "admin/rh/dossier/change_list.html"
45066657 355 ignore_duplicate_revisions = True
53ae644d 356 alphabet_filter = 'employe__nom'
22343fe7 357 search_fields = (
35cff4a7
EMS
358 'id',
359 'employe__id',
360 'poste__id',
361 'employe__nom',
362 'employe__prenom',
363 'poste__nom',
364 'poste__nom_feminin',
365 'poste__implantation__nom',
366 )
53ae644d
OL
367 list_display = (
368 '_id',
e49ac947
JPC
369 '_apercu',
370 '_nom',
53ae644d 371 '_employe',
5db1c5a3
DB
372 '_poste',
373 '_region',
374 '_implantation',
53ae644d
OL
375 '_date_debut',
376 '_date_fin',
45066657 377 'derniere_modification',
a47ed016 378 '_dae',
53ae644d 379 )
e49ac947 380 list_display_links = ('_nom',)
53ae644d
OL
381 list_filter = (
382 'poste__implantation__region',
383 'poste__implantation',
7bf28694 384 'poste__type_poste__categorie_emploi',
7baa5523 385 'poste__type_poste',
53ae644d 386 'rh_contrats__type_contrat',
6bee05ff 387 'principal',
53ae644d
OL
388 )
389 inlines = (DossierPieceInline, ContratInline,
390 RemunerationInline,
53ae644d
OL
391 DossierCommentaireInline,
392 )
45066657 393 fieldsets = (
53ae644d 394 (None, {
22343fe7
OL
395 'fields': (
396 'employe',
397 'poste',
6bee05ff 398 'principal',
22343fe7
OL
399 'statut',
400 'organisme_bstg',)}),
53ae644d 401 ('Recrutement', {
22343fe7
OL
402 'fields': (
403 'statut_residence',
404 'remplacement',
405 'remplacement_de', )}),
53ae644d 406 ('Rémunération', {
22343fe7
OL
407 'fields': (
408 'classement',
409 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
53ae644d 410 ('Occupation du Poste par cet Employe', {
22343fe7
OL
411 'fields': (('date_debut', 'date_fin'), )}
412 ),
53ae644d 413 )
22343fe7
OL
414 form = make_ajax_form(rh.Dossier, {
415 'employe': 'employes',
416 'poste': 'postes',
417 'remplacement_de': 'dossiers',
6bee05ff 418 }, superclass=DossierForm)
53ae644d
OL
419
420 def lookup_allowed(self, key, value):
421 if key in (
422 'employe__nom__istartswith',
53ae644d
OL
423 'poste__implantation__region__id__exact',
424 'poste__implantation__id__exact',
425 'poste__type_poste__id__exact',
7bf28694 426 'poste__type_poste__categorie_emploi__id__exact',
53ae644d 427 'rh_contrats__type_contrat__id__exact',
6bee05ff
OL
428 'principal__exact',
429 'principal__isnull',
53ae644d
OL
430 ):
431 return True
432
e49ac947
JPC
433 def _id(self, obj):
434 return obj.id
435 _id.short_description = u"#"
436 _id.admin_order_field = "id"
437
e49ac947 438 def _apercu(self, d):
22343fe7
OL
439 apercu_link = u"""<a title="Aperçu du dossier"
440 onclick="return showAddAnotherPopup(this);"
441 href='%s'>
9533bd15 442 <img src="%simg/dossier-apercu.png" />
22343fe7 443 </a>""" % \
b10920ea 444 (reverse('dossier_apercu', args=(d.id,)),
822a2c33 445 settings.STATIC_URL,
b10920ea 446 )
e49ac947
JPC
447 return apercu_link
448 _apercu.allow_tags = True
449 _apercu.short_description = u""
53ae644d 450
5db1c5a3
DB
451 def _nom(self, obj):
452 return "Dossier"
453 _nom.allow_tags = True
454 _nom.short_description = u"Dossier"
53ae644d 455
5db1c5a3
DB
456 def _employe(self, obj):
457 employe = obj.employe
458 view_link = reverse('employe_apercu', args=(employe.id,))
459 edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
5db1c5a3
DB
460 style = ""
461 view = u"""<a href="%s"
462 title="Aperçu l'employé"
463 onclick="return showAddAnotherPopup(this);">
464 <img src="%simg/employe-apercu.png" />
465 </a>""" % (view_link, settings.STATIC_URL,)
466 return u"""%s<a href='%s' style="%s;">%s</a>""" % \
467 (view, edit_link, style, employe)
468 _employe.allow_tags = True
469 _employe.short_description = u"Employé"
470 _employe.admin_order_field = "employe__nom"
53ae644d
OL
471
472 def _poste(self, dossier):
22343fe7
OL
473 link = u"""<a title="Aperçu du poste"
474 onclick="return showAddAnotherPopup(this);"
9533bd15 475 href='%s'><img src="%simg/poste-apercu.png" />
22343fe7 476 </a>
5db1c5a3 477 <a href="%s" title="Modifier le poste">%s [%d]</a>""" % \
53ae644d 478 (reverse('poste_apercu', args=(dossier.poste.id,)),
822a2c33 479 settings.STATIC_URL,
211a0e56 480 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
5db1c5a3
DB
481 dossier.poste.nom,
482 dossier.poste.id,
53ae644d
OL
483 )
484 return link
485 _poste.allow_tags = True
486 _poste.short_description = u'Poste'
487 _poste.admin_order_field = 'poste__nom'
488
5db1c5a3
DB
489 def _region(self, obj):
490 return obj.poste.implantation.region.code
491 _region.short_description = u"Région"
492 _region.admin_order_field = 'poste__implantation__region__code'
53ae644d 493
5db1c5a3
DB
494 def _implantation(self, obj):
495 return obj.poste.implantation.nom
496 _implantation.short_description = u"Implantation"
497 _implantation.admin_order_field = 'poste__implantation__nom'
498
499 def _date_debut(self, obj):
500 return date(obj.date_debut)
501
502 _date_debut.short_description = u'Début'
503 _date_debut.admin_order_field = 'date_debut'
504
505 def _date_fin(self, obj):
506 return date(obj.date_fin)
507 _date_fin.short_description = u'Fin'
508 _date_fin.admin_order_field = 'date_fin'
509
510 def _date_modification(self, obj):
511 return date(obj.date_modification) \
512 if obj.date_modification is not None else "(aucune)"
513 _date_modification.short_description = u'date modification'
514 _date_modification.admin_order_field = 'date_modification'
515
516 def _dae(self, d):
517 apercu_link = ""
518 dossiers_dae = d.dossiers_dae.all()
519 if len(dossiers_dae) > 0:
520 dossier_dae = dossiers_dae[0]
521 apercu_link = u"""<a title="Aperçu du dossier"
522 onclick="return showAddAnotherPopup(this);"
523 href='%s'>
524 <img src="%simg/loupe.png" />
525 </a>""" % \
526 (reverse('embauche_consulter', args=(dossier_dae.id,)),
527 settings.STATIC_URL,
528 )
529 return apercu_link
530 _dae.allow_tags = True
531 _dae.short_description = u"DAE"
22343fe7 532
53ae644d
OL
533 def save_formset(self, request, form, formset, change):
534 instances = formset.save(commit=False)
535 for instance in instances:
536 if instance.__class__ == rh.DossierCommentaire:
537 instance.owner = request.user
02e69aa2 538 instance.date_creation = datetime.datetime.now()
53ae644d
OL
539 instance.save()
540
541
45066657
EMS
542class EmployeAdminBase(DateRangeMixin, ProtectRegionMixin,
543 DerniereModificationAdmin, BaseAdmin):
7eb6b687 544 prefixe_recherche_temporelle = "rh_dossiers__"
53ae644d
OL
545 alphabet_filter = 'nom'
546 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
e23da9c3
EMS
547 search_fields = (
548 'id', 'nom', 'prenom', 'nom_affichage',
549 'rh_dossiers__poste__nom',
550 'rh_dossiers__poste__nom_feminin'
551 )
53ae644d
OL
552 ordering = ('nom', )
553 form = EmployeAdminForm
22343fe7 554 list_display = (
f80b83c6
OL
555 '_id', '_apercu', '_nom', '_dossiers_postes',
556 #'_region',
557 #'_implantation',
558 'date_entree',
45066657
EMS
559 'derniere_modification'
560 )
e49ac947 561 list_display_links = ('_nom',)
22343fe7 562 list_filter = (
45066657
EMS
563 'rh_dossiers__poste__implantation__region',
564 'rh_dossiers__poste__implantation', 'nb_postes'
565 )
566 inlines = (
567 AyantDroitInline, DossierROInline, EmployePieceInline,
568 EmployeCommentaireInline
569 )
570 fieldsets = (
53ae644d 571 ('Identification', {
22343fe7
OL
572 'fields': (
573 ('nom', 'prenom'),
574 ('nom_affichage', 'genre'),
575 'nationalite',
576 'date_naissance',
45066657
EMS
577 )
578 }),
53ae644d 579 ('Informations personnelles', {
45066657
EMS
580 'fields': ('situation_famille', 'date_entree', )
581 }),
89a8df07 582 ('Coordonnées personnelles', {
22343fe7
OL
583 'fields': (
584 ('tel_domicile', 'tel_cellulaire'),
585 ('adresse', 'ville'),
586 ('code_postal', 'province'),
587 'pays',
89a8df07 588 'courriel_perso'
45066657
EMS
589 )
590 }),
591 )
53ae644d 592
5db1c5a3
DB
593 def _id(self, obj):
594 return obj.id
595 _id.short_description = u"#"
596 _id.admin_order_field = "id"
597
b10920ea 598 def _apercu(self, obj):
22343fe7
OL
599 return u"""<a title="Aperçu de l'employé"
600 onclick="return showAddAnotherPopup(this);"
601 href='%s'>
9533bd15 602 <img src="%simg/employe-apercu.png" />
22343fe7
OL
603 </a>""" % \
604 (reverse('employe_apercu', args=(obj.id,)), settings.STATIC_URL)
b10920ea
JPC
605 _apercu.allow_tags = True
606 _apercu.short_description = u""
b10920ea 607
53ae644d 608 def _nom(self, obj):
53ae644d 609 edit_link = reverse('admin:rh_employe_change', args=(obj.id,))
e6c107de 610 return u"""<a href='%s'><strong>%s</strong></a>""" % \
e49ac947 611 (edit_link, "%s %s" % (obj.nom.upper(), obj.prenom))
53ae644d 612 _nom.allow_tags = True
e49ac947 613 _nom.short_description = u"Employé"
53ae644d
OL
614 _nom.admin_order_field = "nom"
615
5db1c5a3
DB
616 def _region(self, obj):
617 try:
618 d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
619 region = d.poste.implantation.region.code
620 except:
621 region = None
622 return region
623 _region.short_description = u"Région"
e49ac947 624
5db1c5a3
DB
625 def _implantation(self, obj):
626 try:
627 d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
628 implantation = d.poste.implantation.nom
629 except:
630 implantation = None
631 return implantation
632 _implantation.short_description = u"Implantation"
33232787 633
a7f013f5 634 def _dossiers_postes(self, obj):
53ae644d
OL
635 l = []
636 for d in obj.rh_dossiers.all().order_by('-date_debut'):
5db1c5a3
DB
637 link_style = u''
638 list_style = u''
639 if d.date_fin is not None and d.date_fin < datetime.date.today():
5db1c5a3
DB
640 link_style = u' style="color:#666;"'
641 list_style = u' style="color:grey;"'
08ecf07e 642
22343fe7
OL
643 dossier = u"""<a title="Aperçu du dossier"
644 href="%s"
645 onclick="return showAddAnotherPopup(this);"
646 title="Aperçu du dossier">
9533bd15 647 <img src="%simg/dossier-apercu.png" />
22343fe7 648 </a>
5db1c5a3 649 <a href="%s"%s>Dossier</a>
22343fe7
OL
650 &nbsp;""" % \
651 (reverse('dossier_apercu', args=(d.id,)),
652 settings.STATIC_URL,
5db1c5a3
DB
653 reverse('admin:rh_dossier_change', args=(d.id,)),
654 link_style,)
22343fe7
OL
655
656 poste = u"""<a title="Aperçu du poste"
657 href="%s"
658 onclick="return showAddAnotherPopup(this);"
659 title="Aperçu du poste">
9533bd15 660 <img src="%simg/poste-apercu.png" />
22343fe7 661 </a>
5db1c5a3 662 <a href="%s"%s>%s [%d]</a>
22343fe7
OL
663 &nbsp;""" % \
664 (reverse('poste_apercu', args=(d.poste.id,)),
665 settings.STATIC_URL,
5db1c5a3
DB
666 reverse('admin:rh_poste_change', args=(d.poste.id,)),
667 link_style,
a7f013f5 668 d.poste.nom,
5db1c5a3 669 d.poste.id)
b5cc0357 670
5db1c5a3
DB
671 link = u"""<li%s>%s %s</li>""" % \
672 (list_style, dossier, poste)
b5cc0357 673
53ae644d
OL
674 l.append(link)
675 return "<ul>%s</ul>" % "\n".join(l)
a7f013f5
JPC
676 _dossiers_postes.allow_tags = True
677 _dossiers_postes.short_description = u"Dossiers et postes"
53ae644d 678
5db1c5a3
DB
679 def _date_modification(self, obj):
680 return date(obj.date_modification) \
681 if obj.date_modification is not None else "(aucune)"
682 _date_modification.short_description = u'date modification'
683 _date_modification.admin_order_field = 'date_modification'
684
53ae644d 685 def queryset(self, request):
45066657 686 qs = super(EmployeAdminBase, self).queryset(request)
53ae644d
OL
687 return qs.select_related(depth=1).order_by('nom')
688
689 def save_formset(self, request, form, formset, change):
690 instances = formset.save(commit=False)
691 for instance in instances:
692 if instance.__class__ == rh.EmployeCommentaire:
693 instance.owner = request.user
02e69aa2 694 instance.date_creation = datetime.datetime.now()
53ae644d
OL
695 instance.save()
696
22343fe7 697
45066657 698class EmployeAdmin(reversion.VersionAdmin, EmployeAdminBase):
b2d1cc93 699 change_list_template = "admin/rh/employe/change_list.html"
45066657 700 ignore_duplicate_revisions = True
d104b0ae
EMS
701
702
45066657 703class EmployeProxyAdmin(EmployeAdminBase):
22343fe7 704 list_display = ('_id', '_apercu', '_nom', '_organigramme')
664bdc2f 705 list_per_page = 500
bd917a45
JPC
706 actions = None
707
708 def __init__(self, *args, **kwargs):
709 super(EmployeProxyAdmin, self).__init__(*args, **kwargs)
710 self.list_display_links = (None, )
08faf06e 711
22343fe7
OL
712 def has_add_permission(self, obj):
713 return False
714
08faf06e
JPC
715 def _organigramme(self, obj):
716 l = []
fc4bf968
EMS
717 for d in rh.Dossier.objects.filter(
718 Q(date_fin__gt=datetime.date.today()) | Q(date_fin=None),
719 Q(date_debut__lt=datetime.date.today()) | Q(date_debut=None),
720 employe=obj.id
721 ):
722 organigramme = \
723 u'Organigramme, niveau: ' \
724 u'<input type="text" id="level_%s" ' \
725 u'style="width:30px;height:15px;" /> ' \
726 u'<input type="button" value="Générer" ' \
727 u"""onclick="window.location='%s' + """ \
728 u"""document.getElementById('level_%s').value" />""" % (
729 d.poste.id,
730 reverse('rho_employe_sans_niveau', args=(d.poste.id,)),
731 d.poste.id
732 )
e4fa851f 733 link = u"""<li>%s [%s]:<br />%s</li>""" % (
fc4bf968 734 d.poste.nom,
e4fa851f 735 d.poste.id,
fc4bf968
EMS
736 organigramme
737 )
08faf06e
JPC
738 l.append(link)
739 return "<ul>%s</ul>" % "\n".join(l)
740
741 _organigramme.allow_tags = True
742 _organigramme.short_description = "Organigramme"
743
53ae644d 744
45066657
EMS
745class CategorieEmploiAdmin(reversion.VersionAdmin,
746 DerniereModificationAdmin, BaseAdmin):
747 ignore_duplicate_revisions = True
748 list_display = ('nom', 'derniere_modification')
53ae644d 749 inlines = (TypePosteInline,)
45066657
EMS
750 fieldsets = (
751 (None, {'fields': ('nom', )}),
752 )
53ae644d 753
22343fe7 754
45066657 755class OrganismeBstgAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
d104b0ae 756 BaseAdmin):
45066657 757 ignore_duplicate_revisions = True
c5964dc2 758 search_fields = ('nom',)
45066657 759 list_display = ('nom', 'type', 'pays', 'derniere_modification')
c5964dc2 760 list_filter = ('type', )
53ae644d 761 inlines = (DossierROInline,)
45066657 762 fieldsets = (
22343fe7 763 (None, {'fields': ('nom', 'type', 'pays',)}),
45066657 764 )
33232787 765
53ae644d 766
45066657
EMS
767class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
768 AjaxSelect, DerniereModificationAdmin, BaseAdmin):
b2d1cc93 769 change_list_template = "admin/rh/poste/change_list.html"
45066657 770 ignore_duplicate_revisions = True
22343fe7
OL
771 form = make_ajax_form(rh.Poste, {
772 'implantation': 'implantations',
773 'type_poste': 'typepostes',
774 'responsable': 'postes',
775 'valeur_point_min': 'valeurpoints',
776 'valeur_point_max': 'valeurpoints',
53ae644d
OL
777 })
778 alphabet_filter = 'nom'
22343fe7 779 search_fields = (
45066657
EMS
780 'id',
781 'nom',
782 'implantation__nom',
783 'implantation__region__code',
784 'implantation__region__nom',
785 'rh_dossiers__employe__id',
786 'rh_dossiers__employe__nom',
787 'rh_dossiers__employe__prenom',
788 )
53ae644d 789 list_display = (
45066657
EMS
790 '_id', '_apercu', '_nom', '_occupe_par', 'implantation', '_service',
791 '_responsable', 'date_debut', 'date_fin', 'derniere_modification',
792 '_dae'
793 )
f614ca5c 794 list_filter = (
22343fe7 795 'implantation__region',
53ae644d 796 'implantation',
22343fe7 797 'service',
53ae644d 798 'type_poste',
7bf28694 799 'type_poste__categorie_emploi',
118efe7a 800 'type_poste__famille_professionnelle',
4c53dda4 801 'vacant',
45066657 802 )
e49ac947 803 list_display_links = ('_nom',)
45066657 804 fieldsets = (
22343fe7
OL
805 (None, {'fields': (
806 ('nom', 'nom_feminin'),
807 'implantation',
808 'type_poste',
809 'service',
810 'responsable',
811 )}
812 ),
53ae644d 813 ('Contrat', {
22343fe7
OL
814 'fields': ((
815 'regime_travail',
816 'regime_travail_nb_heure_semaine'),
817 )}
818 ),
53ae644d 819 ('Recrutement', {
22343fe7
OL
820 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
821 ),
53ae644d 822 ('Rémunération', {
22343fe7
OL
823 'fields': (('classement_min',
824 'valeur_point_min',
825 'devise_min',
826 'salaire_min',
827 'indemn_min',
828 'autre_min',),
829 ('classement_max',
830 'valeur_point_max',
831 'devise_max',
832 'salaire_max',
833 'indemn_max',
834 'autre_max',),
835 )}),
53ae644d
OL
836 ('Comparatifs de rémunération', {
837 'fields': ('devise_comparaison',
838 ('comp_locale_min', 'comp_locale_max'),
839 ('comp_universite_min', 'comp_universite_max'),
840 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
841 ('comp_ong_min', 'comp_ong_max'),
22343fe7
OL
842 ('comp_autre_min', 'comp_autre_max'))}
843 ),
53ae644d 844 ('Justification', {
22343fe7
OL
845 'fields': ('justification',)}
846 ),
48a6df80 847 ('Autres Méta-données', {
22343fe7
OL
848 'fields': ('date_debut', 'date_fin')}
849 ),
53ae644d
OL
850 )
851
852 inlines = (PosteFinancementInline,
853 PostePieceInline,
854 DossierROInline,
6f037929 855 PosteComparaisonInline,
53ae644d
OL
856 PosteCommentaireInline, )
857
f614ca5c 858 def lookup_allowed(self, key, value):
118efe7a
EMS
859 return key in (
860 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
861 'date_fin__isnull', 'implantation__region__id__exact',
862 'implantation__id__exact', 'type_poste__id__exact',
863 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
864 'service__isnull', 'vacant__exact', 'vacant__isnull',
865 ) or super(PosteAdmin, self).lookup_allowed(key, value)
f614ca5c 866
5db1c5a3
DB
867 def _id(self, obj):
868 return "%s" % obj.id
869 _id.short_description = '#'
870 _id.admin_order_field = 'id'
871
8f3ca727 872 def _apercu(self, poste):
22343fe7
OL
873 view_link = u"""<a onclick="return showAddAnotherPopup(this);"
874 title="Aperçu du poste"
875 href='%s'>
9533bd15 876 <img src="%simg/poste-apercu.png" />
22343fe7 877 </a>""" % \
8f3ca727 878 (reverse('poste_apercu', args=(poste.id,)),
22343fe7
OL
879 settings.STATIC_URL,)
880 return view_link
8f3ca727 881 _apercu.allow_tags = True
e49ac947
JPC
882 _apercu.short_description = ''
883
5db1c5a3
DB
884 def _nom(self, poste):
885 return """<a href="%s">%s</a>""" % \
886 (reverse('admin:rh_poste_change', args=(poste.id,)),
887 poste.nom)
888 _nom.allow_tags = True
889 _nom.short_description = u'Poste'
890 _nom.admin_order_field = 'nom'
a47ed016 891
5db1c5a3
DB
892 def _occupe_par(self, obj):
893 """Formatte la méthode Poste.occupe_par() pour l'admin"""
894 output = u"Vacant"
895 if obj.date_fin is not None and obj.date_fin < datetime.date.today():
896 return u"s/o"
897 employes = obj.occupe_par()
898 if employes:
899 l = []
900 for e in employes:
901 link = u"""<a href='%s'
902 title='Aperçu de l\'employé'
903 onclick='return showAddAnotherPopup(this)'>
904 <img src='%simg/employe-apercu.png' />
905 </a>
906 <a href='%s'>%s</a>""" % \
907 (reverse('employe_apercu', args=(e.id,)),
908 settings.STATIC_URL,
909 reverse('admin:rh_employe_change', args=(e.id,)),
910 e)
911 l.append(link)
912 output = "\n<br />".join(l)
913 return output
914 _occupe_par.allow_tags = True
915 _occupe_par.short_description = "Occupé par"
916
917 def _region(self, poste):
918 return poste.implantation.region.code
919 _region.short_description = 'Région'
920 _region.admin_order_field = 'implantation__region__code'
921
922 def _implantation(self, poste):
923 return poste.implantation.nom
924 _implantation.short_description = 'Implantation'
925 _implantation.admin_order_field = 'implantation'
8f3ca727 926
c5964dc2 927 def _service(self, obj):
45066657 928 return obj.service
6c2b1160 929 _service.short_description = 'Service'
1b130b25 930 _service.allow_tags = True
53ae644d 931
1ce2ddb9
JPC
932 def _responsable(self, obj):
933 try:
22343fe7
OL
934 responsable = u"""<a href="%s"
935 onclick="return showAddAnotherPopup(this)">
9533bd15 936 <img src="%simg/poste-apercu.png"
22343fe7
OL
937 title="Aperçu du poste" />
938 </a>
5db1c5a3 939 <a href="%s">%s [%d]</a>
22343fe7
OL
940 <br />""" % \
941 (reverse('poste_apercu', args=(obj.responsable.id,)),
942 settings.STATIC_URL,
943 reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
5db1c5a3
DB
944 obj.responsable.nom,
945 obj.responsable.id)
1ce2ddb9
JPC
946 except:
947 responsable = ''
948
949 try:
d104b0ae
EMS
950 dossier = obj.responsable.rh_dossiers.all() \
951 .order_by('-date_debut')[0]
60f34330 952 employe_id = dossier.employe.id
fc4bf968 953 employe_html = u"""<br />
22343fe7
OL
954 <a href="%s"
955 onclick="return showAddAnotherPopup(this)">
9533bd15 956 <img src="%simg/employe-apercu.png"
22343fe7
OL
957 title="Aperçu de l'employé">
958 </a>
959 <a href="%s">%s</a>""" % \
960 (reverse('employe_apercu', args=(employe_id,)),
961 settings.STATIC_URL,
962 reverse('admin:rh_employe_change', args=(employe_id,)),
60f34330 963 dossier.employe)
1ce2ddb9 964 except:
fc4bf968 965 employe_html = ""
1ce2ddb9 966
fc4bf968 967 return "%s %s" % (responsable, employe_html)
1ce2ddb9
JPC
968 _responsable.short_description = 'Responsable'
969 _responsable.allow_tags = True
970
5db1c5a3
DB
971 def _date_debut(self, obj):
972 return date_format(obj.date_debut)
973 _date_debut.short_description = u'Début'
974 _date_debut.admin_order_field = 'date_debut'
f3e3ac6f 975
5db1c5a3
DB
976 def _date_fin(self, obj):
977 return date_format(obj.date_fin)
978 _date_fin.short_description = u'Fin'
979 _date_fin.admin_order_field = 'date_fin'
53ae644d 980
5db1c5a3
DB
981 def _dae(self, poste):
982 apercu_link = ""
983 postes_dae = poste.postes_dae.all()
984 if len(postes_dae) > 0:
985 poste_dae = postes_dae[0]
986 apercu_link = \
987 u'<a title="Aperçu du dossier" href="%s" ' \
988 u'onclick="return showAddAnotherPopup(this);">' \
989 u'<img src="%simg/loupe.png" /></a>' % (reverse(
990 'poste_consulter', args=("dae-%s" % poste_dae.id,)
991 ), settings.STATIC_URL)
992 return apercu_link
993 _dae.allow_tags = True
994 _dae.short_description = u"DAE"
53ae644d
OL
995
996 def save_formset(self, request, form, formset, change):
997 instances = formset.save(commit=False)
998 for instance in instances:
999 if instance.__class__ == rh.PosteCommentaire:
1000 instance.owner = request.user
02e69aa2 1001 instance.date_creation = datetime.datetime.now()
53ae644d
OL
1002 instance.save()
1003 formset.save_m2m()
1004
1005
8c8ffc4f
OL
1006class ResponsableInline(admin.TabularInline):
1007 model = rh.ResponsableImplantation
1008 extra = 0
fc4bf968 1009 fk_name = "implantation"
6fb68b2f 1010 form = ResponsableInlineForm
fc4bf968 1011
22343fe7 1012
08a9b6fc 1013class ResponsableImplantationAdmin(BaseAdmin):
8c8ffc4f 1014 actions = None
6fb68b2f
DB
1015 fields = ('nom', )
1016 inlines = (ResponsableInline, )
8c8ffc4f 1017 list_filter = ('region', 'statut', )
30dabdc3 1018 list_display = ('_region', '_nom', 'statut', '_responsable', )
6fb68b2f 1019 list_display_links = ('_nom',)
664bdc2f 1020 list_per_page = 500
8c8ffc4f 1021 readonly_fields = ('nom', )
6fb68b2f
DB
1022 search_fields = (
1023 'nom',
1024 'responsable__employe__id',
1025 'responsable__employe__nom',
1026 'responsable__employe__prenom',
1027 )
1028 ordering = ('nom',)
d104b0ae 1029
30dabdc3
DB
1030 def _region(self, obj):
1031 return obj.region.code
1032 _region.short_description = u"Région"
1033 _region.admin_order_field = 'region__code'
d104b0ae 1034
30dabdc3
DB
1035 def _nom(self, obj):
1036 return obj.nom
1037 _nom.short_description = u"Implantation"
1038 _nom.admin_order_field = 'nom'
d104b0ae 1039
8c8ffc4f
OL
1040 def _responsable(self, obj):
1041 try:
1042 employe = obj.responsable.employe
1043 dossiers = employe.dossiers_encours()
1044 if len(dossiers) == 0:
1045 return u"<span style='color: red;'>%s %s </span>" % (
1046 employe, u"sans dossier actif")
1047 else:
1048 return employe
fc4bf968
EMS
1049 except Exception:
1050 if obj.statut in (1, 2): # ouverte, ouverture imminente
8c8ffc4f
OL
1051 css = "style='color: red;'"
1052 else:
1053 css = ""
1054 return u"<span %s>Pas de responsable</span>" % css
1055 _responsable.allow_tags = True
1056 _responsable.short_description = u"Responsable"
6fb68b2f 1057 _responsable.admin_order_field = 'responsable__employe__nom'
8c8ffc4f
OL
1058
1059 def has_add_permission(self, request=None):
1060 return False
1061
1062 def has_change_permission(self, request, obj=None):
1063 return in_drh_or_admin(request.user)
1064
1065 def has_delete_permission(self, request, obj=None):
1066 return False
53ae644d 1067
fc4bf968 1068
7013d234 1069class ServiceAdminBase(ArchivableAdmin, DerniereModificationAdmin, BaseAdmin):
45066657 1070 list_display = ('nom', '_archive', 'derniere_modification')
cbb0373e 1071 list_filter = ('archive', )
45066657
EMS
1072 fieldsets = (
1073 (None, {'fields': ('nom', 'archive')}),
1074 )
33232787 1075
fc4bf968 1076
45066657
EMS
1077class ServiceAdmin(reversion.VersionAdmin, ServiceAdminBase):
1078 ignore_duplicate_revisions = True
d104b0ae
EMS
1079
1080
45066657 1081class ServiceProxyAdmin(ServiceAdminBase):
cfd5ac68 1082 list_display = ('nom', '_organigramme', '_archive', )
8135fc65
JPC
1083 actions = None
1084
1085 def __init__(self, *args, **kwargs):
1086 super(ServiceProxyAdmin, self).__init__(*args, **kwargs)
1087 self.list_display_links = (None, )
5c0f1778 1088
f7badf51
EMS
1089 def queryset(self, request):
1090 return super(ServiceProxyAdmin, self).queryset(request) \
1091 .annotate(num_postes=Count('rh_postes')) \
1092 .filter(num_postes__gt=0)
1093
5c0f1778
JPC
1094 def has_add_permission(self, obj):
1095 return False
1096
aa2c508e
JPC
1097 def has_change_permission(self, request, obj=None):
1098 return in_drh_or_admin(request.user)
1099
5c0f1778 1100 def _organigramme(self, obj):
8135fc65
JPC
1101 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1102 (reverse('rho_service', args=(obj.id,)))
5c0f1778
JPC
1103 _organigramme.allow_tags = True
1104 _organigramme.short_description = "Organigramme"
1105
8135fc65 1106
45066657
EMS
1107class StatutAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
1108 BaseAdmin):
1109 ignore_duplicate_revisions = True
1110 list_display = ('code', 'nom', 'derniere_modification')
1111 fieldsets = (
53ae644d
OL
1112 (None, {
1113 'fields': ('code', 'nom', ),
1114 }),
45066657 1115 )
33232787 1116
22343fe7 1117
45066657
EMS
1118class TauxChangeAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
1119 BaseAdmin):
1120 ignore_duplicate_revisions = True
1121 list_display = ('taux', 'devise', 'annee', 'derniere_modification')
1122 list_filter = ('devise',)
1123 fieldsets = (
53ae644d
OL
1124 (None, {
1125 'fields': ('taux', 'devise', 'annee', ),
1126 }),
45066657 1127 )
33232787 1128
22343fe7 1129
45066657
EMS
1130class TypeContratAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
1131 BaseAdmin):
1132 ignore_duplicate_revisions = True
1133 list_display = ('nom', 'nom_long', 'derniere_modification')
1134 fieldsets = (
53ae644d
OL
1135 (None, {
1136 'fields': ('nom', 'nom_long', ),
1137 }),
45066657 1138 )
33232787 1139
53ae644d 1140
45066657 1141class TypePosteAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
d104b0ae 1142 BaseAdmin):
45066657 1143 ignore_duplicate_revisions = True
53ae644d 1144 search_fields = ('nom', 'nom_feminin', )
45066657 1145 list_display = ('nom', 'categorie_emploi', 'derniere_modification')
321fe481 1146 list_filter = ('categorie_emploi', 'famille_professionnelle')
45066657 1147 fieldsets = (
53ae644d 1148 (None, {
22343fe7 1149 'fields': (
45066657 1150 'nom', 'nom_feminin', 'is_responsable', 'categorie_emploi',
321fe481 1151 'famille_professionnelle',
45066657
EMS
1152 )
1153 }),
1154 )
33232787 1155
53ae644d 1156
7013d234 1157class TypeRemunerationAdmin(reversion.VersionAdmin, ArchivableAdmin,
45066657
EMS
1158 DerniereModificationAdmin, BaseAdmin):
1159 ignore_duplicate_revisions = True
22343fe7 1160 list_display = (
45066657
EMS
1161 'nom', 'type_paiement', 'nature_remuneration', '_archive',
1162 'derniere_modification'
1163 )
7ba822a6 1164 list_filter = ('archive', )
45066657
EMS
1165 fieldsets = (
1166 (None, {
1167 'fields': (
1168 'nom', 'type_paiement', 'nature_remuneration', 'archive'
1169 )
1170 }),
1171 )
53ae644d 1172
53ae644d 1173
45066657
EMS
1174class TypeRevalorisationAdmin(reversion.VersionAdmin,
1175 DerniereModificationAdmin, BaseAdmin):
1176 ignore_duplicate_revisions = True
1177 list_display = ('nom', 'derniere_modification')
1178 fieldsets = (
1179 (None, {'fields': ('nom',)}),
1180 )
33232787 1181
53ae644d 1182
45066657 1183class ValeurPointAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
d104b0ae 1184 BaseAdmin):
45066657 1185 ignore_duplicate_revisions = True
22343fe7 1186 list_display = (
45066657
EMS
1187 '_devise_code', '_devise_nom', 'annee', 'implantation',
1188 'valeur', 'derniere_modification'
1189 )
88202dc3 1190 list_filter = ('annee', 'devise', 'implantation__region', )
45066657
EMS
1191 fieldsets = (
1192 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee')}),
1193 )
33232787 1194
53ae644d
OL
1195 def _devise_code(self, obj):
1196 return obj.devise.code
1197 _devise_code.short_description = "Code de la devise"
1198
1199 def _devise_nom(self, obj):
1200 return obj.devise.nom
1201 _devise_nom.short_description = "Nom de la devise"
1202
fc4bf968 1203
08a9b6fc 1204class ImplantationProxyAdmin(BaseAdmin):
82af5c19 1205 list_display = ('nom', '_organigramme')
8135fc65
JPC
1206 actions = None
1207
1208 def __init__(self, *args, **kwargs):
1209 super(ImplantationProxyAdmin, self).__init__(*args, **kwargs)
1210 self.list_display_links = (None, )
82af5c19
JPC
1211
1212 def has_add_permission(self, obj):
1213 return False
1214
aa2c508e
JPC
1215 def has_change_permission(self, request, obj=None):
1216 return in_drh_or_admin(request.user)
1217
82af5c19 1218 def _organigramme(self, obj):
fc4bf968
EMS
1219 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1220 reverse('rho_implantation', args=(obj.id,))
1221 )
82af5c19
JPC
1222 _organigramme.allow_tags = True
1223 _organigramme.short_description = "Organigramme"
1224
fc4bf968 1225
08a9b6fc 1226class RegionProxyAdmin(BaseAdmin):
9da4c195 1227 list_display = ('nom', '_organigramme')
8135fc65
JPC
1228 actions = None
1229
1230 def __init__(self, *args, **kwargs):
1231 super(RegionProxyAdmin, self).__init__(*args, **kwargs)
1232 self.list_display_links = (None, )
9da4c195
JPC
1233
1234 def has_add_permission(self, obj):
1235 return False
1236
aa2c508e
JPC
1237 def has_change_permission(self, request, obj=None):
1238 return in_drh_or_admin(request.user)
1239
9da4c195 1240 def _organigramme(self, obj):
fc4bf968
EMS
1241 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1242 reverse('rho_region', args=(obj.id,))
1243 )
9da4c195
JPC
1244 _organigramme.allow_tags = True
1245 _organigramme.short_description = "Organigramme"
1246
1247
53ae644d
OL
1248admin.site.register(rh.Classement, ClassementAdmin)
1249admin.site.register(rh.Devise, DeviseAdmin)
1250admin.site.register(rh.Dossier, DossierAdmin)
22343fe7 1251admin.site.register(EmployeProxy, EmployeProxyAdmin)
5c0f1778 1252admin.site.register(ServiceProxy, ServiceProxyAdmin)
53ae644d 1253admin.site.register(rh.Employe, EmployeAdmin)
7bf28694 1254admin.site.register(rh.CategorieEmploi, CategorieEmploiAdmin)
321fe481 1255admin.site.register(rh.FamilleProfessionnelle)
53ae644d
OL
1256admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin)
1257admin.site.register(rh.Poste, PosteAdmin)
fc4bf968
EMS
1258admin.site.register(
1259 rh.ResponsableImplantationProxy, ResponsableImplantationAdmin
1260)
53ae644d 1261admin.site.register(rh.Service, ServiceAdmin)
c5964dc2 1262admin.site.register(rh.Statut, StatutAdmin)
53ae644d 1263admin.site.register(rh.TauxChange, TauxChangeAdmin)
c5964dc2 1264admin.site.register(rh.TypeContrat, TypeContratAdmin)
53ae644d
OL
1265admin.site.register(rh.TypePoste, TypePosteAdmin)
1266admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin)
1267admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin)
1268admin.site.register(rh.ValeurPoint, ValeurPointAdmin)
82af5c19 1269admin.site.register(ImplantationProxy, ImplantationProxyAdmin)
9da4c195 1270admin.site.register(RegionProxy, RegionProxyAdmin)