fix selector tous toutes
[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', '_date_modification', 'user_modification',)
212 list_filter = ('archive', )
213 fieldsets = AUFMetadataAdminMixin.fieldsets + (
214 (None, {
215 'fields': ('code', 'nom', 'archive', ),
216 }),
217 )
218
219 def _date_modification(self, obj):
220 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
221 _date_modification.short_description = u'date modification'
222 _date_modification.admin_order_field = 'date_modification'
223
224 class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect,):
225 alphabet_filter = 'employe__nom'
226 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
227 list_display = (
228 '_id',
229 '_apercu',
230 '_nom',
231 '_poste',
232 '_employe',
233 '_date_debut',
234 '_date_fin',
235 '_date_modification',
236 'user_modification',
237 )
238 list_display_links = ('_nom',)
239 list_filter = (
240 'poste__implantation__region',
241 'poste__implantation',
242 'poste__type_poste__famille_emploi',
243 'poste__type_poste',
244 'rh_contrats__type_contrat',
245 )
246 inlines = (DossierPieceInline, ContratInline,
247 RemunerationInline,
248 DossierCommentaireInline,
249 )
250 fieldsets = AUFMetadataAdminMixin.fieldsets + (
251 (None, {
252 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
253 }),
254 ('Recrutement', {
255 'fields': ('statut_residence', 'remplacement', 'remplacement_de', )
256 }),
257 ('Rémunération', {
258 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),)
259 }),
260 ('Occupation du Poste par cet Employe', {
261 'fields': (('date_debut', 'date_fin'), )
262 }),
263 )
264 form = make_ajax_form(rh.Dossier, {
265 'employe' : 'employes',
266 'poste' : 'postes',
267 'remplacement_de' : 'dossiers',
268 })
269
270 def lookup_allowed(self, key, value):
271 if key in (
272 'employe__nom__istartswith',
273 'poste__implantation__region__id__exact',
274 'poste__implantation__id__exact',
275 'poste__type_poste__id__exact',
276 'poste__type_poste__famille_emploi__id__exact',
277 'rh_contrats__type_contrat__id__exact',
278 ):
279 return True
280
281 def _id(self, obj):
282 return obj.id
283 _id.short_description = u"#"
284 _id.admin_order_field = "id"
285
286 def _nom(self, obj):
287 return "%d : %s %s" % \
288 (obj.date_debut.year, obj.employe.nom.upper(), obj.employe.prenom)
289 _nom.allow_tags = True
290 _nom.short_description = u"Dossier"
291
292
293 def _apercu(self, d):
294 apercu_link = u"""<a title="Aperçu du dossier" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
295 (reverse('dossier_apercu', args=(d.id,)),
296 settings.STATIC_URL,
297 )
298 return apercu_link
299 _apercu.allow_tags = True
300 _apercu.short_description = u""
301
302
303 def _date_debut(self, obj):
304 return date(obj.date_debut)
305
306 _date_debut.short_description = u'Occupation début'
307 _date_debut.admin_order_field = 'date_debut'
308
309 def _date_fin(self, obj):
310 return date(obj.date_fin)
311 _date_fin.short_description = u'Occupation fin'
312 _date_fin.admin_order_field = 'date_fin'
313
314
315 def _date_modification(self, obj):
316 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
317 _date_modification.short_description = u'date modification'
318 _date_modification.admin_order_field = 'date_modification'
319
320 def _poste(self, dossier):
321 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>""" % \
322 (reverse('poste_apercu', args=(dossier.poste.id,)),
323 settings.STATIC_URL,
324 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
325 dossier.poste,
326 )
327 return link
328 _poste.allow_tags = True
329 _poste.short_description = u'Poste'
330 _poste.admin_order_field = 'poste__nom'
331
332 def _employe(self, obj):
333 employe = obj.employe
334 view_link = reverse('employe_apercu', args=(employe.id,))
335 edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
336
337 style = ""
338 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,)
339 return u"""%s<a href='%s' style="%s;">%s</a>""" % \
340 (view, edit_link, style, employe)
341 _employe.allow_tags = True
342 _employe.short_description = u"Employé"
343 _employe.admin_order_field = "employe__nom"
344
345 def save_formset(self, request, form, formset, change):
346 instances = formset.save(commit=False)
347 for instance in instances:
348 if instance.__class__ == rh.DossierCommentaire:
349 instance.owner = request.user
350 instance.date_creation = datetime.datetime.now()
351 instance.save()
352
353
354 class DossierPieceAdmin(admin.ModelAdmin):
355 pass
356
357
358 class DossierCommentaireAdmin(admin.ModelAdmin):
359 pass
360
361
362 class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin,):
363 prefixe_recherche_temporelle = "rh_dossiers__"
364 alphabet_filter = 'nom'
365 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
366 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
367 ordering = ('nom', )
368 form = EmployeAdminForm
369 list_display = ('_id', '_apercu', '_nom', '_dossiers_postes', '_date_modification', 'user_modification', )
370 list_display_links = ('_nom',)
371 list_filter = ('rh_dossiers__poste__implantation__region', 'rh_dossiers__poste__implantation', 'nb_postes', )
372 inlines = (AyantDroitInline,
373 DossierROInline,
374 EmployePieceInline,
375 EmployeCommentaireInline)
376 fieldsets = AUFMetadataAdminMixin.fieldsets + (
377 ('Identification', {
378 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
379 }),
380 ('Informations personnelles', {
381 'fields': ('situation_famille', 'date_entree', )
382 }),
383 ('Coordonnées', {
384 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', )
385 }),
386 )
387
388 def _apercu(self, obj):
389 return u"""<a title="Aperçu de l'employé" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
390 (reverse('employe_apercu', args=(obj.id,)), settings.STATIC_URL)
391 _apercu.allow_tags = True
392 _apercu.short_description = u""
393
394 def _nom(self, obj):
395 edit_link = reverse('admin:rh_employe_change', args=(obj.id,))
396 return u"""<a href='%s'><strong>%s</strong></a>""" % \
397 (edit_link, "%s %s" % (obj.nom.upper(), obj.prenom))
398 _nom.allow_tags = True
399 _nom.short_description = u"Employé"
400 _nom.admin_order_field = "nom"
401
402 def _id(self, obj):
403 return obj.id
404 _id.short_description = u"#"
405 _id.admin_order_field = "id"
406
407 def _date_modification(self, obj):
408 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
409 _date_modification.short_description = u'date modification'
410 _date_modification.admin_order_field = 'date_modification'
411
412 def _dossiers_postes(self, obj):
413 l = []
414 for d in obj.rh_dossiers.all().order_by('-date_debut'):
415 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;""" % \
416 ( reverse('dossier_apercu', args=(d.id,)),
417 settings.STATIC_URL,
418 reverse('admin:rh_dossier_change', args=(d.id,))
419 )
420
421 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;""" % \
422 ( reverse('poste_apercu', args=(d.poste.id,)),
423 settings.STATIC_URL,
424 reverse('admin:rh_poste_change', args=(d.poste.id,))
425 )
426 link = u"""<li>%s %s - %s : [%s] %s</li>""" % \
427 (dossier, poste,
428 d.date_debut.year,
429 d.poste.id,
430 d.poste.nom,
431 )
432
433 # Dossier terminé en gris non cliquable
434 if d.date_fin is not None:
435 link = u"""<li style="color: grey">%s : [%s] %s</li>""" % \
436 (d.date_debut.year,
437 d.poste.id,
438 d.poste.nom,
439 )
440
441 l.append(link)
442 return "<ul>%s</ul>" % "\n".join(l)
443 _dossiers_postes.allow_tags = True
444 _dossiers_postes.short_description = u"Dossiers et postes"
445
446 def queryset(self, request):
447 qs = super(EmployeAdmin, self).queryset(request)
448 return qs.select_related(depth=1).order_by('nom')
449
450 def save_formset(self, request, form, formset, change):
451 instances = formset.save(commit=False)
452 for instance in instances:
453 if instance.__class__ == rh.EmployeCommentaire:
454 instance.owner = request.user
455 instance.date_creation = datetime.datetime.now()
456 instance.save()
457
458
459
460 class EmployeCommentaireAdmin(admin.ModelAdmin):
461 pass
462
463
464 class EmployePieceAdmin(admin.ModelAdmin):
465 pass
466
467
468 class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
469 list_display = ('nom', '_date_modification', 'user_modification', )
470 inlines = (TypePosteInline,)
471 fieldsets = AUFMetadataAdminMixin.fieldsets + (
472 (None, {
473 'fields': ('nom', )
474 }),
475 )
476
477 def _date_modification(self, obj):
478 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
479 _date_modification.short_description = u'date modification'
480 _date_modification.admin_order_field = 'date_modification'
481
482 class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
483 search_fields = ('nom',)
484 list_display = ('nom', 'type', 'pays', '_date_modification', 'user_modification', )
485 list_filter = ('type', )
486 inlines = (DossierROInline,)
487 fieldsets = AUFMetadataAdminMixin.fieldsets + (
488 (None, {
489 'fields': ('nom', 'type', 'pays', )
490 }),
491 )
492
493 def _date_modification(self, obj):
494 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
495 _date_modification.short_description = u'date modification'
496 _date_modification.admin_order_field = 'date_modification'
497
498
499 class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect,):
500 form = make_ajax_form(rh.Poste, {
501 'implantation' : 'implantations',
502 'type_poste' : 'typepostes',
503 'responsable' : 'postes',
504 'valeur_point_min' : 'valeurpoints',
505 'valeur_point_max' : 'valeurpoints',
506 })
507 alphabet_filter = 'nom'
508 search_fields = ('nom',
509 'implantation__code',
510 'implantation__nom',
511 'implantation__region__code',
512 'implantation__region__nom',
513 'rh_dossiers__employe__nom',
514 'rh_dossiers__employe__prenom',
515 )
516 list_display = (
517 '_id',
518 '_apercu',
519 '_nom',
520 '_occupe_par',
521 'implantation',
522 '_service',
523 '_responsable',
524 '_date_modification',
525 'user_modification',
526 )
527 list_filter = (
528 'implantation__region',
529 'implantation',
530 'service',
531 'type_poste',
532 'type_poste__famille_emploi',
533 'vacant',
534 )
535 list_display_links = ('_nom',)
536 fieldsets = AUFMetadataAdminMixin.fieldsets + (
537 (None, {
538 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
539 'service', 'responsable')
540 }),
541 ('Contrat', {
542 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
543 }),
544 ('Recrutement', {
545 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
546 }),
547 ('Rémunération', {
548 'fields': (('classement_min', 'valeur_point_min', 'devise_min', 'salaire_min', 'indemn_min', 'autre_min', ),
549 ('classement_max', 'valeur_point_max' ,'devise_max', 'salaire_max', 'indemn_max', 'autre_max', ),
550 )
551 }),
552 ('Comparatifs de rémunération', {
553 'fields': ('devise_comparaison',
554 ('comp_locale_min', 'comp_locale_max'),
555 ('comp_universite_min', 'comp_universite_max'),
556 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
557 ('comp_ong_min', 'comp_ong_max'),
558 ('comp_autre_min', 'comp_autre_max'))
559 }),
560 ('Justification', {
561 'fields': ('justification',)
562 }),
563 ('Autres Méta-données', {
564 'fields': ('date_debut', 'date_fin')
565 }),
566 )
567
568 inlines = (PosteFinancementInline,
569 PostePieceInline,
570 DossierROInline,
571 PosteComparaisonInline,
572 PosteCommentaireInline, )
573
574
575 def lookup_allowed(self, key, value):
576 if key in (
577 'date_debut__gte',
578 'date_debut__isnull',
579 'date_fin__lte',
580 'date_fin__isnull',
581 'implantation__region__id__exact',
582 'implantation__id__exact',
583 'type_poste__id__exact',
584 'type_poste__famille_emploi__id__exact',
585 'service__id__exact',
586 'service__isnull',
587 'vacant__exact',
588 ):
589 return True
590
591
592 def _apercu(self, poste):
593 view_link = u"""<a onclick="return showAddAnotherPopup(this);" title="Aperçu du poste" href='%s'><img src="%simg/loupe.png" /></a>""" % \
594 (reverse('poste_apercu', args=(poste.id,)),
595 settings.STATIC_URL,
596 )
597 return view_link
598 _apercu.allow_tags = True
599 _apercu.short_description = ''
600
601 def _id(self, obj):
602 return "%s" % obj.id
603 _id.short_description = '#'
604 _id.admin_order_field = 'id'
605
606 def _service(self, obj):
607 return obj.service
608 _service.short_description = 'Service'
609
610 def _responsable(self, obj):
611 try:
612 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 />""" % \
613 (
614 reverse('poste_apercu', args=(obj.responsable.id,)),
615 settings.STATIC_URL,
616 reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
617 obj.responsable.nom
618 )
619 except:
620 responsable = ''
621
622 try:
623 employe = "%s %s" % (obj.responsable.rh_dossiers.all()[0].employe.nom.upper(), obj.responsable.rh_dossiers.all()[0].employe.prenom)
624 employe_id = obj.responsable.rh_dossiers.all()[0].id
625 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>""" % \
626 (
627 reverse('employe_apercu', args=(employe_id,)),
628 settings.STATIC_URL,
629 reverse('admin:rh_employe_change', args=(employe_id,)),
630 employe
631 )
632 except:
633 employe = ""
634
635 return "%s %s" % (responsable, employe)
636 _responsable.short_description = 'Responsable'
637 _responsable.allow_tags = True
638
639 def _nom(self, poste):
640 return """<a href="%s">%s</a>""" % \
641 (reverse('admin:rh_poste_change', args=(poste.id,)),
642 poste.nom
643 )
644 _nom.allow_tags = True
645 _nom.short_description = u'Nom'
646 _nom.admin_order_field = 'nom'
647
648 def _date_modification(self, obj):
649 return date(obj.date_modification)
650 _date_modification.short_description = u'date modification'
651 _date_modification.admin_order_field = 'date_modification'
652
653 def _occupe_par(self, obj):
654 """Formatte la méthode Poste.occupe_par() pour l'admin"""
655 output = u"Vacant"
656 if obj.date_fin is not None and obj.date_fin < datetime.date.now():
657 return u"s/o"
658 employes = obj.occupe_par()
659 if employes:
660 l = []
661 for e in employes:
662 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>" % \
663 (reverse('employe_apercu', args=(e.id,)),
664 settings.STATIC_URL,
665 reverse('admin:rh_employe_change', args=(e.id,)),
666 e
667 )
668 l.append(link)
669 output = "\n<br />".join(l)
670 return output
671 _occupe_par.allow_tags = True
672 _occupe_par.short_description = "Occupé par"
673
674 def save_formset(self, request, form, formset, change):
675 instances = formset.save(commit=False)
676 for instance in instances:
677 if instance.__class__ == rh.PosteCommentaire:
678 instance.owner = request.user
679 instance.date_creation = datetime.datetime.now()
680 instance.save()
681 formset.save_m2m()
682
683
684 class PosteCommentaireAdmin(admin.ModelAdmin):
685 pass
686
687
688 class PosteFinancementAdmin(admin.ModelAdmin):
689 pass
690
691
692 class PostePieceAdmin(admin.ModelAdmin):
693 fk_name = 'poste'
694
695
696 class RemunerationAdmin(admin.ModelAdmin):
697 pass
698
699
700 class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701 fieldsets = AUFMetadataAdminMixin.fieldsets + (
702 (None, {
703 'fields': ('employe', 'implantation', ),
704 }),
705 )
706
707
708 class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
709 list_display = ('nom', '_date_modification', 'user_modification', )
710 fieldsets = AUFMetadataAdminMixin.fieldsets + (
711 (None, {
712 'fields': ('nom', ),
713 }),
714 )
715
716 def _date_modification(self, obj):
717 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
718 _date_modification.short_description = u'date modification'
719 _date_modification.admin_order_field = 'date_modification'
720
721
722 class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
723 list_display = ('code', 'nom', '_date_modification', 'user_modification', )
724 fieldsets = AUFMetadataAdminMixin.fieldsets + (
725 (None, {
726 'fields': ('code', 'nom', ),
727 }),
728 )
729
730 def _date_modification(self, obj):
731 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
732 _date_modification.short_description = u'date modification'
733 _date_modification.admin_order_field = 'date_modification'
734
735 class TauxChangeAdmin(admin.ModelAdmin):
736 list_display = ('taux', 'devise', 'annee', '_date_modification', 'user_modification', )
737 list_filter = ('devise', )
738 fieldsets = AUFMetadataAdminMixin.fieldsets + (
739 (None, {
740 'fields': ('taux', 'devise', 'annee', ),
741 }),
742 )
743
744 def _date_modification(self, obj):
745 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
746 _date_modification.short_description = u'date modification'
747 _date_modification.admin_order_field = 'date_modification'
748
749 class TypeContratAdmin(admin.ModelAdmin):
750 list_display = ('nom', 'nom_long', '_date_modification', 'user_modification', )
751 fieldsets = AUFMetadataAdminMixin.fieldsets + (
752 (None, {
753 'fields': ('nom', 'nom_long', ),
754 }),
755 )
756
757 def _date_modification(self, obj):
758 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
759 _date_modification.short_description = u'date modification'
760 _date_modification.admin_order_field = 'date_modification'
761
762
763 class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
764 search_fields = ('nom', 'nom_feminin', )
765 list_display = ('nom', 'famille_emploi', '_date_modification', 'user_modification', )
766 list_filter = ('famille_emploi', )
767 fieldsets = AUFMetadataAdminMixin.fieldsets + (
768 (None, {
769 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
770 }),
771 )
772
773 def _date_modification(self, obj):
774 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
775 _date_modification.short_description = u'date modification'
776 _date_modification.admin_order_field = 'date_modification'
777
778
779 class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
780 list_display = ('nom', 'type_paiement', 'nature_remuneration', '_date_modification', 'user_modification', )
781 fieldsets = AUFMetadataAdminMixin.fieldsets + (
782 (None, {
783 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
784 }),
785 )
786
787 def _date_modification(self, obj):
788 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
789 _date_modification.short_description = u'date modification'
790 _date_modification.admin_order_field = 'date_modification'
791
792
793 class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
794 list_display = ('nom', '_date_modification', 'user_modification', )
795 fieldsets = AUFMetadataAdminMixin.fieldsets + (
796 (None, {
797 'fields': ('nom', )
798 }),
799 )
800
801 def _date_modification(self, obj):
802 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
803 _date_modification.short_description = u'date modification'
804 _date_modification.admin_order_field = 'date_modification'
805
806
807 class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
808 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', '_date_modification', 'user_modification', )
809 list_filter = ('annee', 'devise', )
810 fieldsets = AUFMetadataAdminMixin.fieldsets + (
811 (None, {
812 'fields': ('valeur', 'devise', 'implantation', 'annee', )
813 }),
814 )
815
816 def _date_modification(self, obj):
817 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
818 _date_modification.short_description = u'date modification'
819 _date_modification.admin_order_field = 'date_modification'
820
821 def _devise_code(self, obj):
822 return obj.devise.code
823 _devise_code.short_description = "Code de la devise"
824
825 def _devise_nom(self, obj):
826 return obj.devise.nom
827 _devise_nom.short_description = "Nom de la devise"
828
829
830 admin.site.register(rh.Classement, ClassementAdmin)
831 admin.site.register(rh.Devise, DeviseAdmin)
832 admin.site.register(rh.Dossier, DossierAdmin)
833 admin.site.register(rh.Employe, EmployeAdmin)
834 admin.site.register(rh.FamilleEmploi, FamilleEmploiAdmin)
835 admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin)
836 admin.site.register(rh.Poste, PosteAdmin)
837 admin.site.register(rh.ResponsableImplantation, ResponsableImplantationAdmin)
838 admin.site.register(rh.Service, ServiceAdmin)
839 admin.site.register(rh.Statut, StatutAdmin)
840 admin.site.register(rh.TauxChange, TauxChangeAdmin)
841 admin.site.register(rh.TypeContrat, TypeContratAdmin)
842 admin.site.register(rh.TypePoste, TypePosteAdmin)
843 admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin)
844 admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin)
845 admin.site.register(rh.ValeurPoint, ValeurPointAdmin)