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