1 # -*- encoding: utf-8 -*-
3 from collections
import defaultdict
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
.contrib
.admin
.views
.main
import ChangeList
as DjangoChangeList
11 from django
.conf
import settings
12 from django
.db
.models
import Q
13 from django
.template
.defaultfilters
import date
14 from ajax_select
import make_ajax_form
15 from auf
.django
.metadata
.admin
import AUFMetadataAdminMixin
, AUFMetadataInlineAdminMixin
, AUF_METADATA_READONLY_FIELDS
16 from forms
import ContratForm
, AyantDroitForm
, EmployeAdminForm
, AjaxSelect
17 from dae
.utils
import get_employe_from_user
18 from groups
import grp_drh
22 ################################################################################
24 ################################################################################
25 class DateRangeMixin(object):
27 Mixin pour que le model admin utilise le changelist trafiqué permettant de filter par range
29 Par défaut, le filtrage est configuré sur aujourd'hui, soit les actifs
31 date_borne_gauche
= 'date_debut'
32 date_borne_droite
= 'date_fin'
33 def get_changelist(self
, request
, **kwargs
):
34 if request
.META
.has_key('HTTP_REFERER'):
35 referer
= request
.META
['HTTP_REFERER']
36 referer
= "/".join(referer
.split('/')[3:])
37 referer
= "/%s" % referer
.split('?')[0]
38 change_list_view
= 'admin:%s_%s_changelist' % (self
.model
._meta
.app_label
, self
.model
.__name__
.lower())
39 if referer
!= reverse(change_list_view
):
40 params
= request
.GET
.copy()
41 today
= datetime
.date
.today()
42 params
.update({'%s__gte' % self
.date_borne_gauche
: str(today
), '%s__lte' % self
.date_borne_droite
: str(today
) })
46 class ChangeList(DjangoChangeList
):
47 PERIODE_CHOICE
= ('', 'actuelle', 'passee', 'future')
49 def __init__(self
, *args
, **kwargs
):
50 self
.annees
= {'actuelle': 'actuelle', 'passee': 'passee', 'future': 'future'}
51 super(ChangeList
, self
).__init__(*args
, **kwargs
)
53 def get_query_set(self
):
54 old
= self
.params
.copy()
59 today
= datetime
.date
.today()
60 for k
, v
in self
.params
.items():
62 periode
= self
.params
[k
]
65 annee
= self
.params
[k
]
68 date_debut
= self
.params
[k
]
71 date_fin
= self
.params
[k
]
74 qs
= super(ChangeList
, self
).get_query_set()
75 if periode
== 'actuelle':
76 qs
= qs
.filter(date_fin__exact
=today
, date_debut__exact
=today
).distinct()
77 elif periode
== 'passee':
78 qs
= qs
.filter(date_fin__lt
=today
)
79 elif periode
== 'future':
80 qs
= qs
.filter(date_debut__gt
=today
)
82 date_debut
= datetime
.date(int(annee
), 01, 01)
83 date_fin
= datetime
.date(int(annee
), 12, 31)
85 if date_debut
and date_fin
:
86 prefix_debut
= 'date_debut'
87 prefix_fin
= 'date_fin'
88 q_left
= (Q(**{'%s__isnull' % prefix_debut
: True}) |
Q(**{'%s__lte' % prefix_debut
: date_debut
})) & (Q(**{'%s__gte' % prefix_fin
: date_debut
}) & Q(**{'%s__lte' % prefix_fin
: date_fin
}))
89 q_right
= (Q(**{'%s__isnull' % prefix_fin
: True}) |
Q(**{'%s__gte' % prefix_fin
: date_fin
})) & (Q(**{'%s__gte' % prefix_debut
: date_debut
}) & Q(**{'%s__lte' % prefix_debut
: date_fin
}))
90 q_both
= Q(**{'%s__isnull' % prefix_fin
: True}) |
Q(**{'%s__lte' % prefix_fin
: date_fin
}) & (Q(**{'%s__isnull' % prefix_debut
: True}) |
Q(**{'%s__gte' % prefix_debut
: date_debut
}))
91 q_non_supprime
= Q(**{'%s__exact' % prefix_debut
.replace('date_debut', 'supprime') : False})
92 q
= (q_left | q_right | q_both
) & q_non_supprime
93 qs
= qs
.filter(q
).distinct()
98 ################################################################################
100 # Override of the InlineModelAdmin to support the link in the tabular inline
101 class LinkedInline(admin
.options
.InlineModelAdmin
):
102 template
= "admin/linked.html"
103 admin_model_path
= None
105 def __init__(self
, *args
):
106 super(LinkedInline
, self
).__init__(*args
)
107 if self
.admin_model_path
is None:
108 self
.admin_model_path
= self
.model
.__name__
.lower()
111 class ProtectRegionMixin(object):
113 def queryset(self
, request
):
114 from dae
.workflow
import grp_drh
, grp_correspondants_rh
115 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
117 if request
.user
.is_superuser
:
120 user_groups
= request
.user
.groups
.all()
122 if grp_drh
in user_groups
:
125 if grp_correspondants_rh
in user_groups
:
126 employe
= get_employe_from_user(request
.user
)
127 q
= Q(**{self
.model
.prefix_implantation
: employe
.implantation
.region
})
128 qs
= qs
.filter(q
).distinct()
132 def has_change_permission(self
, request
, obj
=None):
133 user_groups
= request
.user
.groups
.all()
135 # Lock pour autoriser uniquement les DRH à utiliser RH
136 if not request
.user
.is_superuser
and not grp_drh
in user_groups
:
139 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
144 ids
= [o
.id for o
in self
.queryset(request
)]
150 class ReadOnlyInlineMixin(object):
151 def get_readonly_fields(self
, request
, obj
=None):
152 return [f
.name
for f
in self
.model
._meta
.fields
if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
155 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
156 model
= rh
.AyantDroit
157 form
= AyantDroitForm
162 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', 'lien_parente', )
167 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
168 readonly_fields
= ('owner', )
169 model
= rh
.AyantDroitCommentaire
173 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
179 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
180 template
= "admin/rh/dossier/linked.html"
181 exclude
= AUF_METADATA_READONLY_FIELDS
186 def has_add_permission(self
, request
=None):
189 def has_change_permission(self
, request
, obj
=None):
192 def has_delete_permission(self
, request
, obj
=None):
196 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
197 readonly_fields
= ('owner', )
198 model
= rh
.DossierCommentaire
202 class DossierPieceInline(admin
.TabularInline
):
203 model
= rh
.DossierPiece
207 class EmployeInline(admin
.TabularInline
):
210 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
211 readonly_fields
= ('owner', )
212 model
= rh
.EmployeCommentaire
216 class EmployePieceInline(admin
.TabularInline
):
217 model
= rh
.EmployePiece
221 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
222 readonly_fields
= ('owner', )
223 model
= rh
.PosteCommentaire
227 class PosteFinancementInline(admin
.TabularInline
):
228 model
= rh
.PosteFinancement
231 class PostePieceInline(admin
.TabularInline
):
232 model
= rh
.PostePiece
235 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
236 model
= rh
.Remuneration
240 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
244 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
248 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
249 model
= rh
.PosteComparaison
252 class ClassementAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
253 list_display
= ('_classement', '_date_modification', 'user_modification', )
254 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
256 'fields': ('type', 'echelon', 'degre', 'coefficient', )
260 def _classement(self
, obj
):
262 _classement
.short_description
= u
"Classement"
264 def _date_modification(self
, obj
):
265 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
266 _date_modification
.short_description
= u
'date modification'
267 _date_modification
.admin_order_field
= 'date_modification'
269 class CommentaireAdmin(admin
.ModelAdmin
):
273 class DeviseAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
274 list_display
= ('code', 'nom', '_date_modification', 'user_modification',)
275 list_filter
= ('archive', )
276 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
278 'fields': ('code', 'nom', 'archive', ),
282 def _date_modification(self
, obj
):
283 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
284 _date_modification
.short_description
= u
'date modification'
285 _date_modification
.admin_order_field
= 'date_modification'
287 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
288 alphabet_filter
= 'employe__nom'
289 search_fields
= ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
298 '_date_modification',
301 list_display_links
= ('_nom',)
303 'poste__implantation__region',
304 'poste__implantation',
305 'poste__type_poste__famille_emploi',
307 'rh_contrats__type_contrat',
311 inlines
= (DossierPieceInline
, ContratInline
,
313 DossierCommentaireInline
,
315 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
317 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
320 'fields': ('statut_residence', 'remplacement', 'remplacement_de', )
323 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),)
325 ('Occupation du Poste par cet Employe', {
326 'fields': (('date_debut', 'date_fin'), )
329 form
= make_ajax_form(rh
.Dossier
, {
330 'employe' : 'employes',
332 'remplacement_de' : 'dossiers',
335 def lookup_allowed(self
, key
, value
):
337 'employe__nom__istartswith',
338 'poste__implantation__region__id__exact',
339 'poste__implantation__id__exact',
340 'poste__type_poste__id__exact',
341 'poste__type_poste__famille_emploi__id__exact',
342 'rh_contrats__type_contrat__id__exact',
344 'date_debut__isnull',
352 _id
.short_description
= u
"#"
353 _id
.admin_order_field
= "id"
356 return "%d : %s %s" % \
357 (obj
.date_debut
.year
, obj
.employe
.nom
.upper(), obj
.employe
.prenom
)
358 _nom
.allow_tags
= True
359 _nom
.short_description
= u
"Dossier"
362 def _apercu(self
, d
):
363 apercu_link
= u
"""<a title="Aperçu du dossier" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
364 (reverse('dossier_apercu', args
=(d
.id,)),
368 _apercu
.allow_tags
= True
369 _apercu
.short_description
= u
""
372 def _date_debut(self
, obj
):
373 return date(obj
.date_debut
)
375 _date_debut
.short_description
= u
'Occupation début'
376 _date_debut
.admin_order_field
= 'date_debut'
378 def _date_fin(self
, obj
):
379 return date(obj
.date_fin
)
380 _date_fin
.short_description
= u
'Occupation fin'
381 _date_fin
.admin_order_field
= 'date_fin'
384 def _date_modification(self
, obj
):
385 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
386 _date_modification
.short_description
= u
'date modification'
387 _date_modification
.admin_order_field
= 'date_modification'
389 def _poste(self
, dossier
):
390 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>""" % \
391 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
393 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
397 _poste
.allow_tags
= True
398 _poste
.short_description
= u
'Poste'
399 _poste
.admin_order_field
= 'poste__nom'
401 def _employe(self
, obj
):
402 employe
= obj
.employe
403 view_link
= reverse('employe_apercu', args
=(employe
.id,))
404 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
407 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
,)
408 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
409 (view
, edit_link
, style
, employe
)
410 _employe
.allow_tags
= True
411 _employe
.short_description
= u
"Employé"
412 _employe
.admin_order_field
= "employe__nom"
414 def save_formset(self
, request
, form
, formset
, change
):
415 instances
= formset
.save(commit
=False)
416 for instance
in instances
:
417 if instance
.__class__
== rh
.DossierCommentaire
:
418 instance
.owner
= request
.user
419 instance
.date_creation
= datetime
.datetime
.now()
423 class DossierPieceAdmin(admin
.ModelAdmin
):
427 class DossierCommentaireAdmin(admin
.ModelAdmin
):
431 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, ProtectRegionMixin
, admin
.ModelAdmin
,):
432 alphabet_filter
= 'nom'
433 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
434 search_fields
= ('id', 'nom', 'prenom', 'nom_affichage', )
436 form
= EmployeAdminForm
437 list_display
= ('_id', '_apercu', '_nom', '_dossiers_postes', '_date_modification', 'user_modification', )
438 list_display_links
= ('_nom',)
439 list_filter
= ('rh_dossiers__poste__implantation__region', 'rh_dossiers__poste__implantation', 'nb_postes', 'rh_dossiers__date_debut', 'rh_dossiers__date_fin')
440 date_borne_gauche
= 'rh_dossiers__date_debut'
441 date_borne_droite
= 'rh_dossiers__date_fin'
442 inlines
= (AyantDroitInline
,
445 EmployeCommentaireInline
)
446 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
448 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
450 ('Informations personnelles', {
451 'fields': ('situation_famille', 'date_entree', )
454 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', )
458 def _apercu(self
, obj
):
459 return u
"""<a title="Aperçu de l'employé" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
460 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
461 _apercu
.allow_tags
= True
462 _apercu
.short_description
= u
""
465 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
466 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
467 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
468 _nom
.allow_tags
= True
469 _nom
.short_description
= u
"Employé"
470 _nom
.admin_order_field
= "nom"
474 _id
.short_description
= u
"#"
475 _id
.admin_order_field
= "id"
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'
482 def _dossiers_postes(self
, obj
):
484 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
485 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> """ % \
486 ( reverse('dossier_apercu', args
=(d
.id,)),
488 reverse('admin:rh_dossier_change', args
=(d
.id,))
491 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> """ % \
492 ( reverse('poste_apercu', args
=(d
.poste
.id,)),
494 reverse('admin:rh_poste_change', args
=(d
.poste
.id,))
496 link
= u
"""<li>%s %s - %s : [%s] %s</li>""" % \
503 # Dossier terminé en gris non cliquable
504 if d
.date_fin
is not None:
505 link
= u
"""<li style="color: grey">%s : [%s] %s</li>""" % \
512 return "<ul>%s</ul>" % "\n".join(l
)
513 _dossiers_postes
.allow_tags
= True
514 _dossiers_postes
.short_description
= u
"Dossiers et postes"
516 def queryset(self
, request
):
517 qs
= super(EmployeAdmin
, self
).queryset(request
)
518 return qs
.select_related(depth
=1).order_by('nom')
520 def save_formset(self
, request
, form
, formset
, change
):
521 instances
= formset
.save(commit
=False)
522 for instance
in instances
:
523 if instance
.__class__
== rh
.EmployeCommentaire
:
524 instance
.owner
= request
.user
525 instance
.date_creation
= datetime
.datetime
.now()
530 class EmployeCommentaireAdmin(admin
.ModelAdmin
):
534 class EmployePieceAdmin(admin
.ModelAdmin
):
538 class FamilleEmploiAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
539 list_display
= ('nom', '_date_modification', 'user_modification', )
540 inlines
= (TypePosteInline
,)
541 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
547 def _date_modification(self
, obj
):
548 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
549 _date_modification
.short_description
= u
'date modification'
550 _date_modification
.admin_order_field
= 'date_modification'
552 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
553 search_fields
= ('nom',)
554 list_display
= ('nom', 'type', 'pays', '_date_modification', 'user_modification', )
555 list_filter
= ('type', )
556 inlines
= (DossierROInline
,)
557 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
559 'fields': ('nom', 'type', 'pays', )
563 def _date_modification(self
, obj
):
564 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
565 _date_modification
.short_description
= u
'date modification'
566 _date_modification
.admin_order_field
= 'date_modification'
569 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
570 form
= make_ajax_form(rh
.Poste
, {
571 'implantation' : 'implantations',
572 'type_poste' : 'typepostes',
573 'responsable' : 'postes',
574 'valeur_point_min' : 'valeurpoints',
575 'valeur_point_max' : 'valeurpoints',
577 alphabet_filter
= 'nom'
578 search_fields
= ('nom',
579 'implantation__code',
581 'implantation__region__code',
582 'implantation__region__nom',
583 'rh_dossiers__employe__nom',
584 'rh_dossiers__employe__prenom',
596 '_date_modification',
600 'implantation__region',
604 'type_poste__famille_emploi',
609 list_display_links
= ('_nom',)
610 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
612 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
613 'service', 'responsable')
616 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
619 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
622 'fields': (('classement_min', 'valeur_point_min', 'devise_min', 'salaire_min', 'indemn_min', 'autre_min', ),
623 ('classement_max', 'valeur_point_max' ,'devise_max', 'salaire_max', 'indemn_max', 'autre_max', ),
626 ('Comparatifs de rémunération', {
627 'fields': ('devise_comparaison',
628 ('comp_locale_min', 'comp_locale_max'),
629 ('comp_universite_min', 'comp_universite_max'),
630 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
631 ('comp_ong_min', 'comp_ong_max'),
632 ('comp_autre_min', 'comp_autre_max'))
635 'fields': ('justification',)
637 ('Autres Méta-données', {
638 'fields': ('date_debut', 'date_fin')
642 inlines
= (PosteFinancementInline
,
645 PosteComparaisonInline
,
646 PosteCommentaireInline
, )
649 def lookup_allowed(self
, key
, value
):
652 'date_debut__isnull',
655 'implantation__region__id__exact',
656 'implantation__id__exact',
657 'type_poste__id__exact',
658 'type_poste__famille_emploi__id__exact',
659 'service__id__exact',
666 def _apercu(self
, poste
):
667 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);" title="Aperçu du poste" href='%s'><img src="%simg/loupe.png" /></a>""" % \
668 (reverse('poste_apercu', args
=(poste
.id,)),
672 _apercu
.allow_tags
= True
673 _apercu
.short_description
= ''
677 _id
.short_description
= '#'
678 _id
.admin_order_field
= 'id'
680 def _service(self
, obj
):
682 _service
.short_description
= 'Service'
684 def _responsable(self
, obj
):
686 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 />""" % \
688 reverse('poste_apercu', args
=(obj
.responsable
.id,)),
690 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
697 employe
= "%s %s" % (obj
.responsable
.rh_dossiers
.all()[0].employe
.nom
.upper(), obj
.responsable
.rh_dossiers
.all()[0].employe
.prenom
)
698 employe_id
= obj
.responsable
.rh_dossiers
.all()[0].id
699 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>""" % \
701 reverse('employe_apercu', args
=(employe_id
,)),
703 reverse('admin:rh_employe_change', args
=(employe_id
,)),
709 return "%s %s" % (responsable
, employe
)
710 _responsable
.short_description
= 'Responsable'
711 _responsable
.allow_tags
= True
713 def _nom(self
, poste
):
714 return """<a href="%s">%s</a>""" % \
715 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
718 _nom
.allow_tags
= True
719 _nom
.short_description
= u
'Nom'
720 _nom
.admin_order_field
= 'nom'
722 def _date_modification(self
, obj
):
723 return date(obj
.date_modification
)
724 _date_modification
.short_description
= u
'date modification'
725 _date_modification
.admin_order_field
= 'date_modification'
727 def _occupe_par(self
, obj
):
728 """Formatte la méthode Poste.occupe_par() pour l'admin"""
730 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.now():
732 employes
= obj
.occupe_par()
736 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>" % \
737 (reverse('employe_apercu', args
=(e
.id,)),
739 reverse('admin:rh_employe_change', args
=(e
.id,)),
743 output
= "\n<br />".join(l
)
745 _occupe_par
.allow_tags
= True
746 _occupe_par
.short_description
= "Occupé par"
748 def save_formset(self
, request
, form
, formset
, change
):
749 instances
= formset
.save(commit
=False)
750 for instance
in instances
:
751 if instance
.__class__
== rh
.PosteCommentaire
:
752 instance
.owner
= request
.user
753 instance
.date_creation
= datetime
.datetime
.now()
758 class PosteCommentaireAdmin(admin
.ModelAdmin
):
762 class PosteFinancementAdmin(admin
.ModelAdmin
):
766 class PostePieceAdmin(admin
.ModelAdmin
):
770 class RemunerationAdmin(admin
.ModelAdmin
):
774 class ResponsableImplantationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
775 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
777 'fields': ('employe', 'implantation', ),
782 class ServiceAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
783 list_display
= ('nom', '_date_modification', 'user_modification', )
784 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
790 def _date_modification(self
, obj
):
791 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
792 _date_modification
.short_description
= u
'date modification'
793 _date_modification
.admin_order_field
= 'date_modification'
796 class StatutAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
797 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
798 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
800 'fields': ('code', 'nom', ),
804 def _date_modification(self
, obj
):
805 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
806 _date_modification
.short_description
= u
'date modification'
807 _date_modification
.admin_order_field
= 'date_modification'
809 class TauxChangeAdmin(admin
.ModelAdmin
):
810 list_display
= ('taux', 'devise', 'annee', '_date_modification', 'user_modification', )
811 list_filter
= ('devise', )
812 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
814 'fields': ('taux', 'devise', 'annee', ),
818 def _date_modification(self
, obj
):
819 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
820 _date_modification
.short_description
= u
'date modification'
821 _date_modification
.admin_order_field
= 'date_modification'
823 class TypeContratAdmin(admin
.ModelAdmin
):
824 list_display
= ('nom', 'nom_long', '_date_modification', 'user_modification', )
825 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
827 'fields': ('nom', 'nom_long', ),
831 def _date_modification(self
, obj
):
832 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
833 _date_modification
.short_description
= u
'date modification'
834 _date_modification
.admin_order_field
= 'date_modification'
837 class TypePosteAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
838 search_fields
= ('nom', 'nom_feminin', )
839 list_display
= ('nom', 'famille_emploi', '_date_modification', 'user_modification', )
840 list_filter
= ('famille_emploi', )
841 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
843 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
847 def _date_modification(self
, obj
):
848 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
849 _date_modification
.short_description
= u
'date modification'
850 _date_modification
.admin_order_field
= 'date_modification'
853 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
854 list_display
= ('nom', 'type_paiement', 'nature_remuneration', '_date_modification', 'user_modification', )
855 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
857 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
861 def _date_modification(self
, obj
):
862 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
863 _date_modification
.short_description
= u
'date modification'
864 _date_modification
.admin_order_field
= 'date_modification'
867 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
868 list_display
= ('nom', '_date_modification', 'user_modification', )
869 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
875 def _date_modification(self
, obj
):
876 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
877 _date_modification
.short_description
= u
'date modification'
878 _date_modification
.admin_order_field
= 'date_modification'
881 class ValeurPointAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
882 list_display
= ('_devise_code', '_devise_nom', 'annee', 'valeur', '_date_modification', 'user_modification', )
883 list_filter
= ('annee', 'devise', )
884 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
886 'fields': ('valeur', 'devise', 'implantation', 'annee', )
890 def _date_modification(self
, obj
):
891 return date(obj
.date_modification
) if obj
.date_modification
is not None else "(aucune)"
892 _date_modification
.short_description
= u
'date modification'
893 _date_modification
.admin_order_field
= 'date_modification'
895 def _devise_code(self
, obj
):
896 return obj
.devise
.code
897 _devise_code
.short_description
= "Code de la devise"
899 def _devise_nom(self
, obj
):
900 return obj
.devise
.nom
901 _devise_nom
.short_description
= "Nom de la devise"
904 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
905 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
906 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
907 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
908 admin
.site
.register(rh
.FamilleEmploi
, FamilleEmploiAdmin
)
909 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
910 admin
.site
.register(rh
.Poste
, PosteAdmin
)
911 admin
.site
.register(rh
.ResponsableImplantation
, ResponsableImplantationAdmin
)
912 admin
.site
.register(rh
.Service
, ServiceAdmin
)
913 admin
.site
.register(rh
.Statut
, StatutAdmin
)
914 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
915 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
916 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
917 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
918 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
919 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)