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