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