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