[#3812] Corrigé l'affichage de la liste des devises
[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
45066657
EMS
355class ClassementAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
356 BaseAdmin):
357 ignore_duplicate_revisions = True
358 list_display = ('_classement', 'derniere_modification')
359 fieldsets = (
360 (None, {'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
53ae644d
OL
361 )
362
c5964dc2
OL
363 def _classement(self, obj):
364 return unicode(obj)
365 _classement.short_description = u"Classement"
53ae644d 366
d104b0ae 367
7013d234 368class DeviseAdmin(reversion.VersionAdmin, ArchivableAdmin,
45066657
EMS
369 DerniereModificationAdmin, BaseAdmin):
370 ignore_duplicate_revisions = True
22343fe7 371 list_display = (
45066657
EMS
372 'code', 'nom', '_archive', 'derniere_modification',
373 )
edb35076 374 list_filter = ('archive', )
45066657
EMS
375 fieldsets = (
376 (None, {'fields': ('code', 'nom', 'archive', )}),
53ae644d
OL
377 )
378
22343fe7 379
45066657
EMS
380class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
381 AjaxSelect, DerniereModificationAdmin, BaseAdmin):
b2d1cc93 382 change_list_template = "admin/rh/dossier/change_list.html"
45066657 383 ignore_duplicate_revisions = True
53ae644d 384 alphabet_filter = 'employe__nom'
22343fe7 385 search_fields = (
35cff4a7
EMS
386 'id',
387 'employe__id',
388 'poste__id',
389 'employe__nom',
390 'employe__prenom',
391 'poste__nom',
392 'poste__nom_feminin',
393 'poste__implantation__nom',
394 )
53ae644d
OL
395 list_display = (
396 '_id',
e49ac947
JPC
397 '_apercu',
398 '_nom',
53ae644d 399 '_employe',
5db1c5a3 400 '_poste',
b0cf30b8 401 '_zone_administrative',
5db1c5a3 402 '_implantation',
53ae644d
OL
403 '_date_debut',
404 '_date_fin',
45066657 405 'derniere_modification',
a47ed016 406 '_dae',
53ae644d 407 )
e49ac947 408 list_display_links = ('_nom',)
53ae644d 409 list_filter = (
b0cf30b8 410 'poste__implantation__zone_administrative',
53ae644d 411 'poste__implantation',
7bf28694 412 'poste__type_poste__categorie_emploi',
7baa5523 413 'poste__type_poste',
53ae644d 414 'rh_contrats__type_contrat',
6bee05ff 415 'principal',
53ae644d
OL
416 )
417 inlines = (DossierPieceInline, ContratInline,
418 RemunerationInline,
53ae644d
OL
419 DossierCommentaireInline,
420 )
45066657 421 fieldsets = (
53ae644d 422 (None, {
22343fe7
OL
423 'fields': (
424 'employe',
425 'poste',
6bee05ff 426 'principal',
22343fe7
OL
427 'statut',
428 'organisme_bstg',)}),
53ae644d 429 ('Recrutement', {
22343fe7
OL
430 'fields': (
431 'statut_residence',
432 'remplacement',
433 'remplacement_de', )}),
53ae644d 434 ('Rémunération', {
22343fe7
OL
435 'fields': (
436 'classement',
437 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
53ae644d 438 ('Occupation du Poste par cet Employe', {
22343fe7
OL
439 'fields': (('date_debut', 'date_fin'), )}
440 ),
53ae644d 441 )
22343fe7
OL
442 form = make_ajax_form(rh.Dossier, {
443 'employe': 'employes',
444 'poste': 'postes',
445 'remplacement_de': 'dossiers',
6bee05ff 446 }, superclass=DossierForm)
53ae644d
OL
447
448 def lookup_allowed(self, key, value):
449 if key in (
450 'employe__nom__istartswith',
b0cf30b8 451 'poste__implantation__zone_administrative__code__exact',
53ae644d
OL
452 'poste__implantation__id__exact',
453 'poste__type_poste__id__exact',
7bf28694 454 'poste__type_poste__categorie_emploi__id__exact',
53ae644d 455 'rh_contrats__type_contrat__id__exact',
6bee05ff
OL
456 'principal__exact',
457 'principal__isnull',
53ae644d
OL
458 ):
459 return True
460
e49ac947
JPC
461 def _id(self, obj):
462 return obj.id
463 _id.short_description = u"#"
464 _id.admin_order_field = "id"
465
e49ac947 466 def _apercu(self, d):
22343fe7
OL
467 apercu_link = u"""<a title="Aperçu du dossier"
468 onclick="return showAddAnotherPopup(this);"
469 href='%s'>
9533bd15 470 <img src="%simg/dossier-apercu.png" />
22343fe7 471 </a>""" % \
b10920ea 472 (reverse('dossier_apercu', args=(d.id,)),
822a2c33 473 settings.STATIC_URL,
b10920ea 474 )
e49ac947
JPC
475 return apercu_link
476 _apercu.allow_tags = True
477 _apercu.short_description = u""
53ae644d 478
5db1c5a3
DB
479 def _nom(self, obj):
480 return "Dossier"
481 _nom.allow_tags = True
482 _nom.short_description = u"Dossier"
53ae644d 483
5db1c5a3
DB
484 def _employe(self, obj):
485 employe = obj.employe
486 view_link = reverse('employe_apercu', args=(employe.id,))
487 edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
5db1c5a3
DB
488 style = ""
489 view = u"""<a href="%s"
490 title="Aperçu l'employé"
491 onclick="return showAddAnotherPopup(this);">
492 <img src="%simg/employe-apercu.png" />
493 </a>""" % (view_link, settings.STATIC_URL,)
494 return u"""%s<a href='%s' style="%s;">%s</a>""" % \
495 (view, edit_link, style, employe)
496 _employe.allow_tags = True
497 _employe.short_description = u"Employé"
498 _employe.admin_order_field = "employe__nom"
53ae644d
OL
499
500 def _poste(self, dossier):
22343fe7
OL
501 link = u"""<a title="Aperçu du poste"
502 onclick="return showAddAnotherPopup(this);"
9533bd15 503 href='%s'><img src="%simg/poste-apercu.png" />
22343fe7 504 </a>
5db1c5a3 505 <a href="%s" title="Modifier le poste">%s [%d]</a>""" % \
53ae644d 506 (reverse('poste_apercu', args=(dossier.poste.id,)),
822a2c33 507 settings.STATIC_URL,
211a0e56 508 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
5db1c5a3
DB
509 dossier.poste.nom,
510 dossier.poste.id,
53ae644d
OL
511 )
512 return link
513 _poste.allow_tags = True
514 _poste.short_description = u'Poste'
515 _poste.admin_order_field = 'poste__nom'
516
b0cf30b8
EMS
517 def _zone_administrative(self, obj):
518 return obj.poste.implantation.zone_administrative.code
519 _zone_administrative.short_description = u"Zone administrative"
90440a65
EMS
520 _zone_administrative.admin_order_field = \
521 'poste__implantation__zone_administrative__code'
53ae644d 522
5db1c5a3
DB
523 def _implantation(self, obj):
524 return obj.poste.implantation.nom
525 _implantation.short_description = u"Implantation"
526 _implantation.admin_order_field = 'poste__implantation__nom'
527
528 def _date_debut(self, obj):
529 return date(obj.date_debut)
530
531 _date_debut.short_description = u'Début'
532 _date_debut.admin_order_field = 'date_debut'
533
534 def _date_fin(self, obj):
535 return date(obj.date_fin)
536 _date_fin.short_description = u'Fin'
537 _date_fin.admin_order_field = 'date_fin'
538
539 def _date_modification(self, obj):
540 return date(obj.date_modification) \
541 if obj.date_modification is not None else "(aucune)"
542 _date_modification.short_description = u'date modification'
543 _date_modification.admin_order_field = 'date_modification'
544
545 def _dae(self, d):
546 apercu_link = ""
547 dossiers_dae = d.dossiers_dae.all()
548 if len(dossiers_dae) > 0:
549 dossier_dae = dossiers_dae[0]
550 apercu_link = u"""<a title="Aperçu du dossier"
551 onclick="return showAddAnotherPopup(this);"
552 href='%s'>
553 <img src="%simg/loupe.png" />
554 </a>""" % \
555 (reverse('embauche_consulter', args=(dossier_dae.id,)),
556 settings.STATIC_URL,
557 )
558 return apercu_link
559 _dae.allow_tags = True
560 _dae.short_description = u"DAE"
22343fe7 561
53ae644d
OL
562 def save_formset(self, request, form, formset, change):
563 instances = formset.save(commit=False)
564 for instance in instances:
565 if instance.__class__ == rh.DossierCommentaire:
566 instance.owner = request.user
02e69aa2 567 instance.date_creation = datetime.datetime.now()
53ae644d
OL
568 instance.save()
569
570
45066657
EMS
571class EmployeAdminBase(DateRangeMixin, ProtectRegionMixin,
572 DerniereModificationAdmin, BaseAdmin):
7eb6b687 573 prefixe_recherche_temporelle = "rh_dossiers__"
53ae644d
OL
574 alphabet_filter = 'nom'
575 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
e23da9c3
EMS
576 search_fields = (
577 'id', 'nom', 'prenom', 'nom_affichage',
578 'rh_dossiers__poste__nom',
579 'rh_dossiers__poste__nom_feminin'
580 )
53ae644d
OL
581 ordering = ('nom', )
582 form = EmployeAdminForm
22343fe7 583 list_display = (
f80b83c6 584 '_id', '_apercu', '_nom', '_dossiers_postes',
b0cf30b8 585 #'_zone_administrative',
f80b83c6
OL
586 #'_implantation',
587 'date_entree',
45066657
EMS
588 'derniere_modification'
589 )
e49ac947 590 list_display_links = ('_nom',)
22343fe7 591 list_filter = (
b0cf30b8 592 'rh_dossiers__poste__implantation__zone_administrative',
45066657
EMS
593 'rh_dossiers__poste__implantation', 'nb_postes'
594 )
595 inlines = (
340307bd 596 AyantDroitInline, DossierROInline, EmployePieceInline,
45066657
EMS
597 EmployeCommentaireInline
598 )
599 fieldsets = (
53ae644d 600 ('Identification', {
22343fe7
OL
601 'fields': (
602 ('nom', 'prenom'),
603 ('nom_affichage', 'genre'),
604 'nationalite',
605 'date_naissance',
45066657
EMS
606 )
607 }),
53ae644d 608 ('Informations personnelles', {
45066657
EMS
609 'fields': ('situation_famille', 'date_entree', )
610 }),
89a8df07 611 ('Coordonnées personnelles', {
22343fe7
OL
612 'fields': (
613 ('tel_domicile', 'tel_cellulaire'),
614 ('adresse', 'ville'),
615 ('code_postal', 'province'),
616 'pays',
89a8df07 617 'courriel_perso'
45066657
EMS
618 )
619 }),
620 )
53ae644d 621
5db1c5a3
DB
622 def _id(self, obj):
623 return obj.id
624 _id.short_description = u"#"
625 _id.admin_order_field = "id"
626
b10920ea 627 def _apercu(self, obj):
22343fe7
OL
628 return u"""<a title="Aperçu de l'employé"
629 onclick="return showAddAnotherPopup(this);"
630 href='%s'>
9533bd15 631 <img src="%simg/employe-apercu.png" />
22343fe7
OL
632 </a>""" % \
633 (reverse('employe_apercu', args=(obj.id,)), settings.STATIC_URL)
b10920ea
JPC
634 _apercu.allow_tags = True
635 _apercu.short_description = u""
b10920ea 636
53ae644d 637 def _nom(self, obj):
53ae644d 638 edit_link = reverse('admin:rh_employe_change', args=(obj.id,))
e6c107de 639 return u"""<a href='%s'><strong>%s</strong></a>""" % \
e49ac947 640 (edit_link, "%s %s" % (obj.nom.upper(), obj.prenom))
53ae644d 641 _nom.allow_tags = True
e49ac947 642 _nom.short_description = u"Employé"
53ae644d
OL
643 _nom.admin_order_field = "nom"
644
b0cf30b8 645 def _zone_administrative(self, obj):
5db1c5a3
DB
646 try:
647 d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
b0cf30b8 648 zone = d.poste.implantation.zone_administrative.code
5db1c5a3 649 except:
b0cf30b8
EMS
650 zone = None
651 return zone
652 _zone_administrative.short_description = u"Zone administrative"
e49ac947 653
5db1c5a3
DB
654 def _implantation(self, obj):
655 try:
656 d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
657 implantation = d.poste.implantation.nom
658 except:
659 implantation = None
660 return implantation
661 _implantation.short_description = u"Implantation"
33232787 662
a7f013f5 663 def _dossiers_postes(self, obj):
53ae644d
OL
664 l = []
665 for d in obj.rh_dossiers.all().order_by('-date_debut'):
5db1c5a3
DB
666 link_style = u''
667 list_style = u''
668 if d.date_fin is not None and d.date_fin < datetime.date.today():
5db1c5a3
DB
669 link_style = u' style="color:#666;"'
670 list_style = u' style="color:grey;"'
08ecf07e 671
22343fe7
OL
672 dossier = u"""<a title="Aperçu du dossier"
673 href="%s"
674 onclick="return showAddAnotherPopup(this);"
675 title="Aperçu du dossier">
9533bd15 676 <img src="%simg/dossier-apercu.png" />
22343fe7 677 </a>
5db1c5a3 678 <a href="%s"%s>Dossier</a>
22343fe7
OL
679 &nbsp;""" % \
680 (reverse('dossier_apercu', args=(d.id,)),
681 settings.STATIC_URL,
5db1c5a3
DB
682 reverse('admin:rh_dossier_change', args=(d.id,)),
683 link_style,)
22343fe7
OL
684
685 poste = u"""<a title="Aperçu du poste"
686 href="%s"
687 onclick="return showAddAnotherPopup(this);"
688 title="Aperçu du poste">
9533bd15 689 <img src="%simg/poste-apercu.png" />
22343fe7 690 </a>
5db1c5a3 691 <a href="%s"%s>%s [%d]</a>
22343fe7
OL
692 &nbsp;""" % \
693 (reverse('poste_apercu', args=(d.poste.id,)),
694 settings.STATIC_URL,
5db1c5a3
DB
695 reverse('admin:rh_poste_change', args=(d.poste.id,)),
696 link_style,
a7f013f5 697 d.poste.nom,
5db1c5a3 698 d.poste.id)
b5cc0357 699
5db1c5a3
DB
700 link = u"""<li%s>%s %s</li>""" % \
701 (list_style, dossier, poste)
b5cc0357 702
53ae644d
OL
703 l.append(link)
704 return "<ul>%s</ul>" % "\n".join(l)
a7f013f5
JPC
705 _dossiers_postes.allow_tags = True
706 _dossiers_postes.short_description = u"Dossiers et postes"
53ae644d 707
5db1c5a3
DB
708 def _date_modification(self, obj):
709 return date(obj.date_modification) \
710 if obj.date_modification is not None else "(aucune)"
711 _date_modification.short_description = u'date modification'
712 _date_modification.admin_order_field = 'date_modification'
713
53ae644d 714 def queryset(self, request):
45066657 715 qs = super(EmployeAdminBase, self).queryset(request)
53ae644d
OL
716 return qs.select_related(depth=1).order_by('nom')
717
718 def save_formset(self, request, form, formset, change):
719 instances = formset.save(commit=False)
720 for instance in instances:
721 if instance.__class__ == rh.EmployeCommentaire:
722 instance.owner = request.user
02e69aa2 723 instance.date_creation = datetime.datetime.now()
53ae644d
OL
724 instance.save()
725
22343fe7 726
45066657 727class EmployeAdmin(reversion.VersionAdmin, EmployeAdminBase):
b2d1cc93 728 change_list_template = "admin/rh/employe/change_list.html"
45066657 729 ignore_duplicate_revisions = True
d104b0ae
EMS
730
731
45066657 732class EmployeProxyAdmin(EmployeAdminBase):
22343fe7 733 list_display = ('_id', '_apercu', '_nom', '_organigramme')
664bdc2f 734 list_per_page = 500
bd917a45
JPC
735 actions = None
736
737 def __init__(self, *args, **kwargs):
738 super(EmployeProxyAdmin, self).__init__(*args, **kwargs)
739 self.list_display_links = (None, )
08faf06e 740
8f7b2d7b
DB
741 def queryset(self, request):
742 qs = super(ProtectRegionMixin, self).queryset(request)
743
744 if in_drh_or_admin(request.user) or \
745 user_gere_obj_de_sa_region(request.user):
746 return qs
747
748 return qs.none()
749
22343fe7
OL
750 def has_add_permission(self, obj):
751 return False
752
c5dab350 753 def has_change_permission(self, request, obj=None):
3383b2d1
OL
754 user_groups = [g.name for g in request.user.groups.all()]
755 if groups.CORRESPONDANT_RH in user_groups or \
756 groups.ADMINISTRATEURS in user_groups or \
757 groups.DIRECTEUR_DE_BUREAU in user_groups or \
c5dab350
OL
758 in_drh_or_admin(request.user):
759 return True
760 return False
761
08faf06e
JPC
762 def _organigramme(self, obj):
763 l = []
fc4bf968
EMS
764 for d in rh.Dossier.objects.filter(
765 Q(date_fin__gt=datetime.date.today()) | Q(date_fin=None),
766 Q(date_debut__lt=datetime.date.today()) | Q(date_debut=None),
767 employe=obj.id
768 ):
769 organigramme = \
770 u'Organigramme, niveau: ' \
771 u'<input type="text" id="level_%s" ' \
772 u'style="width:30px;height:15px;" /> ' \
773 u'<input type="button" value="Générer" ' \
774 u"""onclick="window.location='%s' + """ \
775 u"""document.getElementById('level_%s').value" />""" % (
776 d.poste.id,
777 reverse('rho_employe_sans_niveau', args=(d.poste.id,)),
778 d.poste.id
779 )
e4fa851f 780 link = u"""<li>%s [%s]:<br />%s</li>""" % (
fc4bf968 781 d.poste.nom,
e4fa851f 782 d.poste.id,
fc4bf968
EMS
783 organigramme
784 )
08faf06e
JPC
785 l.append(link)
786 return "<ul>%s</ul>" % "\n".join(l)
787
788 _organigramme.allow_tags = True
789 _organigramme.short_description = "Organigramme"
790
53ae644d 791
45066657
EMS
792class CategorieEmploiAdmin(reversion.VersionAdmin,
793 DerniereModificationAdmin, BaseAdmin):
794 ignore_duplicate_revisions = True
795 list_display = ('nom', 'derniere_modification')
53ae644d 796 inlines = (TypePosteInline,)
45066657
EMS
797 fieldsets = (
798 (None, {'fields': ('nom', )}),
799 )
53ae644d 800
22343fe7 801
45066657 802class OrganismeBstgAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
d104b0ae 803 BaseAdmin):
45066657 804 ignore_duplicate_revisions = True
c5964dc2 805 search_fields = ('nom',)
45066657 806 list_display = ('nom', 'type', 'pays', 'derniere_modification')
c5964dc2 807 list_filter = ('type', )
340307bd 808 inlines = (DossierROInline,)
45066657 809 fieldsets = (
22343fe7 810 (None, {'fields': ('nom', 'type', 'pays',)}),
45066657 811 )
33232787 812
53ae644d 813
45066657
EMS
814class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
815 AjaxSelect, DerniereModificationAdmin, BaseAdmin):
b2d1cc93 816 change_list_template = "admin/rh/poste/change_list.html"
45066657 817 ignore_duplicate_revisions = True
22343fe7
OL
818 form = make_ajax_form(rh.Poste, {
819 'implantation': 'implantations',
820 'type_poste': 'typepostes',
821 'responsable': 'postes',
822 'valeur_point_min': 'valeurpoints',
823 'valeur_point_max': 'valeurpoints',
53ae644d
OL
824 })
825 alphabet_filter = 'nom'
22343fe7 826 search_fields = (
45066657
EMS
827 'id',
828 'nom',
829 'implantation__nom',
b0cf30b8
EMS
830 'implantation__zone_administrative__code',
831 'implantation__zone_administrative__nom',
45066657
EMS
832 'rh_dossiers__employe__id',
833 'rh_dossiers__employe__nom',
834 'rh_dossiers__employe__prenom',
835 )
53ae644d 836 list_display = (
45066657
EMS
837 '_id', '_apercu', '_nom', '_occupe_par', 'implantation', '_service',
838 '_responsable', 'date_debut', 'date_fin', 'derniere_modification',
839 '_dae'
840 )
f614ca5c 841 list_filter = (
b0cf30b8 842 'implantation__zone_administrative',
53ae644d 843 'implantation',
22343fe7 844 'service',
53ae644d 845 'type_poste',
7bf28694 846 'type_poste__categorie_emploi',
118efe7a 847 'type_poste__famille_professionnelle',
4c53dda4 848 'vacant',
45066657 849 )
e49ac947 850 list_display_links = ('_nom',)
45066657 851 fieldsets = (
22343fe7
OL
852 (None, {'fields': (
853 ('nom', 'nom_feminin'),
854 'implantation',
855 'type_poste',
856 'service',
857 'responsable',
858 )}
859 ),
53ae644d 860 ('Contrat', {
22343fe7
OL
861 'fields': ((
862 'regime_travail',
863 'regime_travail_nb_heure_semaine'),
864 )}
865 ),
53ae644d 866 ('Recrutement', {
22343fe7
OL
867 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
868 ),
53ae644d 869 ('Rémunération', {
22343fe7
OL
870 'fields': (('classement_min',
871 'valeur_point_min',
872 'devise_min',
873 'salaire_min',
874 'indemn_min',
875 'autre_min',),
876 ('classement_max',
877 'valeur_point_max',
878 'devise_max',
879 'salaire_max',
880 'indemn_max',
881 'autre_max',),
882 )}),
53ae644d
OL
883 ('Comparatifs de rémunération', {
884 'fields': ('devise_comparaison',
885 ('comp_locale_min', 'comp_locale_max'),
886 ('comp_universite_min', 'comp_universite_max'),
887 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
888 ('comp_ong_min', 'comp_ong_max'),
22343fe7
OL
889 ('comp_autre_min', 'comp_autre_max'))}
890 ),
53ae644d 891 ('Justification', {
22343fe7
OL
892 'fields': ('justification',)}
893 ),
48a6df80 894 ('Autres Méta-données', {
22343fe7
OL
895 'fields': ('date_debut', 'date_fin')}
896 ),
53ae644d
OL
897 )
898
899 inlines = (PosteFinancementInline,
900 PostePieceInline,
340307bd 901 DossierROInline,
6f037929 902 PosteComparaisonInline,
53ae644d
OL
903 PosteCommentaireInline, )
904
f614ca5c 905 def lookup_allowed(self, key, value):
118efe7a
EMS
906 return key in (
907 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
90440a65
EMS
908 'date_fin__isnull',
909 'implantation__zone_administrative__code__exact',
118efe7a
EMS
910 'implantation__id__exact', 'type_poste__id__exact',
911 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
90440a65 912 'service__isnull', 'vacant__exact', 'vacant__isnull'
118efe7a 913 ) or super(PosteAdmin, self).lookup_allowed(key, value)
f614ca5c 914
5db1c5a3
DB
915 def _id(self, obj):
916 return "%s" % obj.id
917 _id.short_description = '#'
918 _id.admin_order_field = 'id'
919
8f3ca727 920 def _apercu(self, poste):
22343fe7
OL
921 view_link = u"""<a onclick="return showAddAnotherPopup(this);"
922 title="Aperçu du poste"
923 href='%s'>
9533bd15 924 <img src="%simg/poste-apercu.png" />
22343fe7 925 </a>""" % \
8f3ca727 926 (reverse('poste_apercu', args=(poste.id,)),
22343fe7
OL
927 settings.STATIC_URL,)
928 return view_link
8f3ca727 929 _apercu.allow_tags = True
e49ac947
JPC
930 _apercu.short_description = ''
931
5db1c5a3
DB
932 def _nom(self, poste):
933 return """<a href="%s">%s</a>""" % \
934 (reverse('admin:rh_poste_change', args=(poste.id,)),
935 poste.nom)
936 _nom.allow_tags = True
937 _nom.short_description = u'Poste'
938 _nom.admin_order_field = 'nom'
a47ed016 939
5db1c5a3
DB
940 def _occupe_par(self, obj):
941 """Formatte la méthode Poste.occupe_par() pour l'admin"""
942 output = u"Vacant"
943 if obj.date_fin is not None and obj.date_fin < datetime.date.today():
944 return u"s/o"
945 employes = obj.occupe_par()
946 if employes:
947 l = []
948 for e in employes:
949 link = u"""<a href='%s'
950 title='Aperçu de l\'employé'
951 onclick='return showAddAnotherPopup(this)'>
952 <img src='%simg/employe-apercu.png' />
953 </a>
954 <a href='%s'>%s</a>""" % \
955 (reverse('employe_apercu', args=(e.id,)),
956 settings.STATIC_URL,
957 reverse('admin:rh_employe_change', args=(e.id,)),
958 e)
959 l.append(link)
960 output = "\n<br />".join(l)
961 return output
962 _occupe_par.allow_tags = True
963 _occupe_par.short_description = "Occupé par"
964
b0cf30b8
EMS
965 def _zone_administrative(self, poste):
966 return poste.implantation.zone_administrative.code
967 _zone_administrative.short_description = 'Zone administrative'
90440a65
EMS
968 _zone_administrative.admin_order_field = \
969 'implantation__zone_administrative__code'
5db1c5a3
DB
970
971 def _implantation(self, poste):
972 return poste.implantation.nom
973 _implantation.short_description = 'Implantation'
974 _implantation.admin_order_field = 'implantation'
8f3ca727 975
c5964dc2 976 def _service(self, obj):
45066657 977 return obj.service
6c2b1160 978 _service.short_description = 'Service'
1b130b25 979 _service.allow_tags = True
53ae644d 980
1ce2ddb9
JPC
981 def _responsable(self, obj):
982 try:
22343fe7
OL
983 responsable = u"""<a href="%s"
984 onclick="return showAddAnotherPopup(this)">
9533bd15 985 <img src="%simg/poste-apercu.png"
22343fe7
OL
986 title="Aperçu du poste" />
987 </a>
5db1c5a3 988 <a href="%s">%s [%d]</a>
22343fe7
OL
989 <br />""" % \
990 (reverse('poste_apercu', args=(obj.responsable.id,)),
991 settings.STATIC_URL,
992 reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
5db1c5a3
DB
993 obj.responsable.nom,
994 obj.responsable.id)
1ce2ddb9
JPC
995 except:
996 responsable = ''
997
998 try:
d104b0ae
EMS
999 dossier = obj.responsable.rh_dossiers.all() \
1000 .order_by('-date_debut')[0]
60f34330 1001 employe_id = dossier.employe.id
fc4bf968 1002 employe_html = u"""<br />
22343fe7
OL
1003 <a href="%s"
1004 onclick="return showAddAnotherPopup(this)">
9533bd15 1005 <img src="%simg/employe-apercu.png"
22343fe7
OL
1006 title="Aperçu de l'employé">
1007 </a>
1008 <a href="%s">%s</a>""" % \
1009 (reverse('employe_apercu', args=(employe_id,)),
1010 settings.STATIC_URL,
1011 reverse('admin:rh_employe_change', args=(employe_id,)),
60f34330 1012 dossier.employe)
1ce2ddb9 1013 except:
fc4bf968 1014 employe_html = ""
1ce2ddb9 1015
fc4bf968 1016 return "%s %s" % (responsable, employe_html)
1ce2ddb9
JPC
1017 _responsable.short_description = 'Responsable'
1018 _responsable.allow_tags = True
1019
5db1c5a3
DB
1020 def _date_debut(self, obj):
1021 return date_format(obj.date_debut)
1022 _date_debut.short_description = u'Début'
1023 _date_debut.admin_order_field = 'date_debut'
f3e3ac6f 1024
5db1c5a3
DB
1025 def _date_fin(self, obj):
1026 return date_format(obj.date_fin)
1027 _date_fin.short_description = u'Fin'
1028 _date_fin.admin_order_field = 'date_fin'
53ae644d 1029
5db1c5a3
DB
1030 def _dae(self, poste):
1031 apercu_link = ""
1032 postes_dae = poste.postes_dae.all()
1033 if len(postes_dae) > 0:
1034 poste_dae = postes_dae[0]
1035 apercu_link = \
1036 u'<a title="Aperçu du dossier" href="%s" ' \
1037 u'onclick="return showAddAnotherPopup(this);">' \
1038 u'<img src="%simg/loupe.png" /></a>' % (reverse(
1039 'poste_consulter', args=("dae-%s" % poste_dae.id,)
1040 ), settings.STATIC_URL)
1041 return apercu_link
1042 _dae.allow_tags = True
1043 _dae.short_description = u"DAE"
53ae644d
OL
1044
1045 def save_formset(self, request, form, formset, change):
1046 instances = formset.save(commit=False)
1047 for instance in instances:
1048 if instance.__class__ == rh.PosteCommentaire:
1049 instance.owner = request.user
02e69aa2 1050 instance.date_creation = datetime.datetime.now()
53ae644d
OL
1051 instance.save()
1052 formset.save_m2m()
1053
1054
8c8ffc4f
OL
1055class ResponsableInline(admin.TabularInline):
1056 model = rh.ResponsableImplantation
1057 extra = 0
fc4bf968 1058 fk_name = "implantation"
6fb68b2f 1059 form = ResponsableInlineForm
fc4bf968 1060
22343fe7 1061
08a9b6fc 1062class ResponsableImplantationAdmin(BaseAdmin):
8c8ffc4f 1063 actions = None
6fb68b2f
DB
1064 fields = ('nom', )
1065 inlines = (ResponsableInline, )
b0cf30b8
EMS
1066 list_filter = ('zone_administrative', 'statut', )
1067 list_display = ('_zone_administrative', '_nom', 'statut', '_responsable', )
6fb68b2f 1068 list_display_links = ('_nom',)
664bdc2f 1069 list_per_page = 500
8c8ffc4f 1070 readonly_fields = ('nom', )
6fb68b2f
DB
1071 search_fields = (
1072 'nom',
1073 'responsable__employe__id',
1074 'responsable__employe__nom',
1075 'responsable__employe__prenom',
1076 )
1077 ordering = ('nom',)
8c8ffc4f 1078 inlines = (ResponsableInline, )
d104b0ae 1079
b0cf30b8
EMS
1080 def _zone_administrative(self, obj):
1081 return obj.zone_administrative.code
1082 _zone_administrative.short_description = u"Zone administrative"
1083 _zone_administrative.admin_order_field = 'zone_administrative__code'
d104b0ae 1084
30dabdc3
DB
1085 def _nom(self, obj):
1086 return obj.nom
1087 _nom.short_description = u"Implantation"
1088 _nom.admin_order_field = 'nom'
d104b0ae 1089
8c8ffc4f
OL
1090 def _responsable(self, obj):
1091 try:
da202402
OL
1092 employe = employe = obj.responsable.employe
1093 except Exception, e:
90440a65
EMS
1094 return (
1095 u"<span style='color: red;'>"
1096 u"Pas de responsable</span><!-- %s -->" % e
1097 )
da202402 1098 try:
8c8ffc4f
OL
1099 dossiers = employe.dossiers_encours()
1100 if len(dossiers) == 0:
1101 return u"<span style='color: red;'>%s %s </span>" % (
1102 employe, u"sans dossier actif")
1103 else:
1104 return employe
da202402
OL
1105 except Exception, e:
1106 return u"<!-- %s -->" % e
8c8ffc4f
OL
1107 _responsable.allow_tags = True
1108 _responsable.short_description = u"Responsable"
6fb68b2f 1109 _responsable.admin_order_field = 'responsable__employe__nom'
8c8ffc4f
OL
1110
1111 def has_add_permission(self, request=None):
1112 return False
1113
1114 def has_change_permission(self, request, obj=None):
1115 return in_drh_or_admin(request.user)
1116
1117 def has_delete_permission(self, request, obj=None):
1118 return False
53ae644d 1119
fc4bf968 1120
7013d234 1121class ServiceAdminBase(ArchivableAdmin, DerniereModificationAdmin, BaseAdmin):
45066657 1122 list_display = ('nom', '_archive', 'derniere_modification')
cbb0373e 1123 list_filter = ('archive', )
45066657
EMS
1124 fieldsets = (
1125 (None, {'fields': ('nom', 'archive')}),
1126 )
33232787 1127
fc4bf968 1128
45066657
EMS
1129class ServiceAdmin(reversion.VersionAdmin, ServiceAdminBase):
1130 ignore_duplicate_revisions = True
d104b0ae
EMS
1131
1132
45066657 1133class ServiceProxyAdmin(ServiceAdminBase):
cfd5ac68 1134 list_display = ('nom', '_organigramme', '_archive', )
8135fc65
JPC
1135 actions = None
1136
1137 def __init__(self, *args, **kwargs):
1138 super(ServiceProxyAdmin, self).__init__(*args, **kwargs)
1139 self.list_display_links = (None, )
5c0f1778 1140
f7badf51
EMS
1141 def queryset(self, request):
1142 return super(ServiceProxyAdmin, self).queryset(request) \
1143 .annotate(num_postes=Count('rh_postes')) \
1144 .filter(num_postes__gt=0)
1145
5c0f1778
JPC
1146 def has_add_permission(self, obj):
1147 return False
1148
aa2c508e 1149 def has_change_permission(self, request, obj=None):
3383b2d1
OL
1150 user_groups = [g.name for g in request.user.groups.all()]
1151 if groups.CORRESPONDANT_RH in user_groups or \
1152 groups.ADMINISTRATEURS in user_groups or \
1153 groups.DIRECTEUR_DE_BUREAU in user_groups or \
c5dab350
OL
1154 in_drh_or_admin(request.user):
1155 return True
1156 return False
aa2c508e 1157
5c0f1778 1158 def _organigramme(self, obj):
8135fc65
JPC
1159 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1160 (reverse('rho_service', args=(obj.id,)))
5c0f1778
JPC
1161 _organigramme.allow_tags = True
1162 _organigramme.short_description = "Organigramme"
1163
8135fc65 1164
45066657
EMS
1165class StatutAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
1166 BaseAdmin):
1167 ignore_duplicate_revisions = True
1168 list_display = ('code', 'nom', 'derniere_modification')
1169 fieldsets = (
53ae644d
OL
1170 (None, {
1171 'fields': ('code', 'nom', ),
1172 }),
45066657 1173 )
33232787 1174
22343fe7 1175
45066657
EMS
1176class TauxChangeAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
1177 BaseAdmin):
1178 ignore_duplicate_revisions = True
1179 list_display = ('taux', 'devise', 'annee', 'derniere_modification')
1180 list_filter = ('devise',)
1181 fieldsets = (
53ae644d
OL
1182 (None, {
1183 'fields': ('taux', 'devise', 'annee', ),
1184 }),
45066657 1185 )
33232787 1186
22343fe7 1187
45066657
EMS
1188class TypeContratAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
1189 BaseAdmin):
1190 ignore_duplicate_revisions = True
1191 list_display = ('nom', 'nom_long', 'derniere_modification')
1192 fieldsets = (
53ae644d
OL
1193 (None, {
1194 'fields': ('nom', 'nom_long', ),
1195 }),
45066657 1196 )
33232787 1197
53ae644d 1198
45066657 1199class TypePosteAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
d104b0ae 1200 BaseAdmin):
45066657 1201 ignore_duplicate_revisions = True
53ae644d 1202 search_fields = ('nom', 'nom_feminin', )
45066657 1203 list_display = ('nom', 'categorie_emploi', 'derniere_modification')
321fe481 1204 list_filter = ('categorie_emploi', 'famille_professionnelle')
45066657 1205 fieldsets = (
53ae644d 1206 (None, {
22343fe7 1207 'fields': (
45066657 1208 'nom', 'nom_feminin', 'is_responsable', 'categorie_emploi',
321fe481 1209 'famille_professionnelle',
45066657
EMS
1210 )
1211 }),
1212 )
33232787 1213
53ae644d 1214
7013d234 1215class TypeRemunerationAdmin(reversion.VersionAdmin, ArchivableAdmin,
45066657
EMS
1216 DerniereModificationAdmin, BaseAdmin):
1217 ignore_duplicate_revisions = True
22343fe7 1218 list_display = (
45066657
EMS
1219 'nom', 'type_paiement', 'nature_remuneration', '_archive',
1220 'derniere_modification'
1221 )
7ba822a6 1222 list_filter = ('archive', )
45066657
EMS
1223 fieldsets = (
1224 (None, {
1225 'fields': (
1226 'nom', 'type_paiement', 'nature_remuneration', 'archive'
1227 )
1228 }),
1229 )
53ae644d 1230
53ae644d 1231
45066657
EMS
1232class TypeRevalorisationAdmin(reversion.VersionAdmin,
1233 DerniereModificationAdmin, BaseAdmin):
1234 ignore_duplicate_revisions = True
1235 list_display = ('nom', 'derniere_modification')
1236 fieldsets = (
1237 (None, {'fields': ('nom',)}),
1238 )
33232787 1239
53ae644d 1240
45066657 1241class ValeurPointAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
d104b0ae 1242 BaseAdmin):
45066657 1243 ignore_duplicate_revisions = True
22343fe7 1244 list_display = (
45066657
EMS
1245 '_devise_code', '_devise_nom', 'annee', 'implantation',
1246 'valeur', 'derniere_modification'
1247 )
b0cf30b8 1248 list_filter = ('annee', 'devise', 'implantation__zone_administrative', )
45066657
EMS
1249 fieldsets = (
1250 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee')}),
1251 )
33232787 1252
866bba57
EMS
1253 def queryset(self, request):
1254 return super(ValeurPointAdmin, self).queryset(request) \
1255 .select_related('devise', 'implantation')
1256
53ae644d
OL
1257 def _devise_code(self, obj):
1258 return obj.devise.code
1259 _devise_code.short_description = "Code de la devise"
1260
1261 def _devise_nom(self, obj):
1262 return obj.devise.nom
1263 _devise_nom.short_description = "Nom de la devise"
1264
fc4bf968 1265
08a9b6fc 1266class ImplantationProxyAdmin(BaseAdmin):
82af5c19 1267 list_display = ('nom', '_organigramme')
8135fc65
JPC
1268 actions = None
1269
1270 def __init__(self, *args, **kwargs):
1271 super(ImplantationProxyAdmin, self).__init__(*args, **kwargs)
1272 self.list_display_links = (None, )
82af5c19
JPC
1273
1274 def has_add_permission(self, obj):
1275 return False
1276
aa2c508e 1277 def has_change_permission(self, request, obj=None):
3383b2d1
OL
1278 user_groups = [g.name for g in request.user.groups.all()]
1279 if groups.CORRESPONDANT_RH in user_groups or \
1280 groups.ADMINISTRATEURS in user_groups or \
1281 groups.DIRECTEUR_DE_BUREAU in user_groups or \
c5dab350
OL
1282 in_drh_or_admin(request.user):
1283 return True
1284 return False
aa2c508e 1285
82af5c19 1286 def _organigramme(self, obj):
fc4bf968
EMS
1287 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1288 reverse('rho_implantation', args=(obj.id,))
1289 )
82af5c19
JPC
1290 _organigramme.allow_tags = True
1291 _organigramme.short_description = "Organigramme"
1292
fc4bf968 1293
08a9b6fc 1294class RegionProxyAdmin(BaseAdmin):
9da4c195 1295 list_display = ('nom', '_organigramme')
8135fc65
JPC
1296 actions = None
1297
1298 def __init__(self, *args, **kwargs):
1299 super(RegionProxyAdmin, self).__init__(*args, **kwargs)
1300 self.list_display_links = (None, )
9da4c195
JPC
1301
1302 def has_add_permission(self, obj):
1303 return False
1304
aa2c508e 1305 def has_change_permission(self, request, obj=None):
3383b2d1
OL
1306 user_groups = [g.name for g in request.user.groups.all()]
1307 if groups.CORRESPONDANT_RH in user_groups or \
1308 groups.ADMINISTRATEURS in user_groups or \
1309 groups.DIRECTEUR_DE_BUREAU in user_groups or \
c5dab350
OL
1310 in_drh_or_admin(request.user):
1311 return True
1312 return False
aa2c508e 1313
9da4c195 1314 def _organigramme(self, obj):
fc4bf968
EMS
1315 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1316 reverse('rho_region', args=(obj.id,))
1317 )
9da4c195
JPC
1318 _organigramme.allow_tags = True
1319 _organigramme.short_description = "Organigramme"
1320
1321
53ae644d
OL
1322admin.site.register(rh.Classement, ClassementAdmin)
1323admin.site.register(rh.Devise, DeviseAdmin)
1324admin.site.register(rh.Dossier, DossierAdmin)
22343fe7 1325admin.site.register(EmployeProxy, EmployeProxyAdmin)
5c0f1778 1326admin.site.register(ServiceProxy, ServiceProxyAdmin)
53ae644d 1327admin.site.register(rh.Employe, EmployeAdmin)
7bf28694 1328admin.site.register(rh.CategorieEmploi, CategorieEmploiAdmin)
321fe481 1329admin.site.register(rh.FamilleProfessionnelle)
53ae644d
OL
1330admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin)
1331admin.site.register(rh.Poste, PosteAdmin)
fc4bf968
EMS
1332admin.site.register(
1333 rh.ResponsableImplantationProxy, ResponsableImplantationAdmin
1334)
53ae644d 1335admin.site.register(rh.Service, ServiceAdmin)
c5964dc2 1336admin.site.register(rh.Statut, StatutAdmin)
53ae644d 1337admin.site.register(rh.TauxChange, TauxChangeAdmin)
c5964dc2 1338admin.site.register(rh.TypeContrat, TypeContratAdmin)
53ae644d
OL
1339admin.site.register(rh.TypePoste, TypePosteAdmin)
1340admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin)
1341admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin)
1342admin.site.register(rh.ValeurPoint, ValeurPointAdmin)
82af5c19 1343admin.site.register(ImplantationProxy, ImplantationProxyAdmin)
9da4c195 1344admin.site.register(RegionProxy, RegionProxyAdmin)