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