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