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