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