1 # -*- encoding: utf-8 -*-
5 from ajax_select
import make_ajax_form
6 from auf
.django
.metadata
.admin
import \
7 AUFMetadataAdminMixin
, AUFMetadataInlineAdminMixin
, \
8 AUF_METADATA_READONLY_FIELDS
9 from django
.core
.urlresolvers
import reverse
10 from django
.contrib
import admin
11 from django
.conf
import settings
12 from django
.db
.models
import Q
, Count
13 from django
.template
.defaultfilters
import date
15 import auf
.django
.references
.models
as ref
18 ContratForm
, AyantDroitForm
, EmployeAdminForm
, AjaxSelect
, DossierForm
19 from dae
.utils
import get_employe_from_user
20 from change_list
import ChangeList
21 from groups
import grp_correspondants_rh
22 from decorators
import in_drh_or_admin
25 class BaseAdmin(admin
.ModelAdmin
):
28 css
= {'screen': ('css/admin_custom.css',)}
31 class ArchiveMixin(object):
33 Archive Mixin pour gérer le queryset et le display
34 NON COMPRIS : list_filter, et list_display, field à setter dans la classe.
37 def queryset(self
, request
):
38 return self
.model
._base_manager
40 def _archive(self
, obj
):
45 _archive
.short_description
= u
'Archivé'
46 _archive
.admin_order_field
= 'archive'
49 class RegionProxy(ref
.Region
):
50 """ Proxy utilisé pour les organigrammes par région """
53 verbose_name
= u
"Organigramme par région"
54 verbose_name_plural
= u
"Organigramme par région"
57 class ImplantationProxy(ref
.Implantation
):
58 """ Proxy utilisé pour les organigrammes par implantation """
61 verbose_name
= u
"Organigramme par implantations"
62 verbose_name_plural
= u
"Organigramme par implantations"
65 class ServiceProxy(rh
.Service
):
66 """ Proxy utilisé pour les organigrammes opar service """
70 verbose_name
= u
"Organigramme par services"
71 verbose_name_plural
= u
"Organigramme par services"
74 class EmployeProxy(rh
.Employe
):
75 """ Proxy utilisé pour les organigrammes des employés """
78 verbose_name
= u
"Organigramme des employés"
79 verbose_name_plural
= u
"Organigramme des employés"
82 class DateRangeMixin(object):
83 prefixe_recherche_temporelle
= ""
85 def get_changelist(self
, request
, **kwargs
):
86 if 'HTTP_REFERER' in request
.META
.keys():
87 referer
= request
.META
['HTTP_REFERER']
88 referer
= "/".join(referer
.split('/')[3:])
89 referer
= "/%s" % referer
.split('?')[0]
90 change_list_view
= 'admin:%s_%s_changelist' % (
91 self
.model
._meta
.app_label
,
92 self
.model
.__name__
.lower(),)
93 if referer
!= reverse(change_list_view
):
94 params
= request
.GET
.copy()
95 params
.update({'statut': 'Actif'})
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 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
116 user_groups
= request
.user
.groups
.all()
117 if in_drh_or_admin(request
.user
):
120 if grp_correspondants_rh
in user_groups
:
121 employe
= get_employe_from_user(request
.user
)
122 q
= Q(**{self
.model
.prefix_implantation
: \
123 employe
.implantation
.region
})
124 qs
= qs
.filter(q
).distinct()
128 def has_add_permission(self
, request
):
129 if not in_drh_or_admin(request
.user
):
134 def has_change_permission(self
, request
, obj
=None):
135 user_groups
= request
.user
.groups
.all()
137 # Lock pour autoriser uniquement les DRH à utiliser RH
138 if not in_drh_or_admin(request
.user
):
141 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
146 ids
= [o
.id for o
in self
.queryset(request
)]
152 class ReadOnlyInlineMixin(object):
154 def get_readonly_fields(self
, request
, obj
=None):
155 return [f
.name
for f
in self
.model
._meta
.fields \
156 if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
159 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
160 model
= rh
.AyantDroit
161 form
= AyantDroitForm
168 ('nom_affichage', 'genre'),
176 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, \
177 admin
.TabularInline
):
178 readonly_fields
= ('owner', )
179 model
= rh
.AyantDroitCommentaire
183 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
189 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
190 template
= "admin/rh/dossier/linked.html"
191 exclude
= AUF_METADATA_READONLY_FIELDS
196 def has_add_permission(self
, request
=None):
199 def has_change_permission(self
, request
, obj
=None):
202 def has_delete_permission(self
, request
, obj
=None):
206 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, \
207 admin
.TabularInline
):
208 readonly_fields
= ('owner', )
209 model
= rh
.DossierCommentaire
213 class DossierPieceInline(admin
.TabularInline
):
214 model
= rh
.DossierPiece
218 class EmployeInline(admin
.TabularInline
):
222 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, \
223 admin
.TabularInline
):
224 readonly_fields
= ('owner', )
225 model
= rh
.EmployeCommentaire
229 class EmployePieceInline(admin
.TabularInline
):
230 model
= rh
.EmployePiece
234 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
235 readonly_fields
= ('owner', )
236 model
= rh
.PosteCommentaire
240 class PosteFinancementInline(admin
.TabularInline
):
241 model
= rh
.PosteFinancement
244 class PostePieceInline(admin
.TabularInline
):
245 model
= rh
.PostePiece
248 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
249 model
= rh
.Remuneration
253 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
257 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
261 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
262 model
= rh
.PosteComparaison
265 class ClassementAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
266 list_display
= ('_classement', '_date_modification', 'user_modification', )
267 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
269 'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
272 def _classement(self
, obj
):
274 _classement
.short_description
= u
"Classement"
276 def _date_modification(self
, obj
):
277 return date(obj
.date_modification
) \
278 if obj
.date_modification
is not None else "(aucune)"
279 _date_modification
.short_description
= u
'date modification'
280 _date_modification
.admin_order_field
= 'date_modification'
283 class DeviseAdmin(AUFMetadataAdminMixin
, BaseAdmin
, ArchiveMixin
):
288 '_date_modification',
291 list_filter
= ('archive', )
292 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
294 'fields': ('code', 'nom', 'archive', ),
298 def _date_modification(self
, obj
):
299 return date(obj
.date_modification
) \
300 if obj
.date_modification
is not None else "(aucune)"
301 _date_modification
.short_description
= u
'date modification'
302 _date_modification
.admin_order_field
= 'date_modification'
305 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
306 ProtectRegionMixin
, BaseAdmin
, AjaxSelect
):
307 alphabet_filter
= 'employe__nom'
315 'poste__nom_feminin',
316 'poste__implantation__nom',
326 '_date_modification',
330 list_display_links
= ('_nom',)
332 'poste__implantation__region',
333 'poste__implantation',
334 'poste__type_poste__categorie_emploi',
336 'rh_contrats__type_contrat',
339 inlines
= (DossierPieceInline
, ContratInline
,
341 DossierCommentaireInline
,
343 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
350 'organisme_bstg',)}),
355 'remplacement_de', )}),
359 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
360 ('Occupation du Poste par cet Employe', {
361 'fields': (('date_debut', 'date_fin'), )}
364 form
= make_ajax_form(rh
.Dossier
, {
365 'employe': 'employes',
367 'remplacement_de': 'dossiers',
368 }, superclass
=DossierForm
)
370 def lookup_allowed(self
, key
, value
):
372 'employe__nom__istartswith',
373 'poste__implantation__region__id__exact',
374 'poste__implantation__id__exact',
375 'poste__type_poste__id__exact',
376 'poste__type_poste__categorie_emploi__id__exact',
377 'rh_contrats__type_contrat__id__exact',
385 _id
.short_description
= u
"#"
386 _id
.admin_order_field
= "id"
389 return "%d : %s %s" % (
391 obj
.employe
.nom
.upper(),
393 _nom
.allow_tags
= True
394 _nom
.short_description
= u
"Dossier"
396 def _apercu(self
, d
):
397 apercu_link
= u
"""<a title="Aperçu du dossier"
398 onclick="return showAddAnotherPopup(this);"
400 <img src="%simg/loupe.png" />
402 (reverse('dossier_apercu', args
=(d
.id,)),
406 _apercu
.allow_tags
= True
407 _apercu
.short_description
= u
""
411 dossiers_dae
= d
.dossiers_dae
.all()
412 if len(dossiers_dae
) > 0:
413 dossier_dae
= dossiers_dae
[0]
414 apercu_link
= u
"""<a title="Aperçu du dossier"
415 onclick="return showAddAnotherPopup(this);"
417 <img src="%simg/loupe.png" />
419 (reverse('embauche_consulter', args
=(dossier_dae
.id,)),
423 _dae
.allow_tags
= True
424 _dae
.short_description
= u
"DAE"
426 def _date_debut(self
, obj
):
427 return date(obj
.date_debut
)
429 _date_debut
.short_description
= u
'Occupation début'
430 _date_debut
.admin_order_field
= 'date_debut'
432 def _date_fin(self
, obj
):
433 return date(obj
.date_fin
)
434 _date_fin
.short_description
= u
'Occupation fin'
435 _date_fin
.admin_order_field
= 'date_fin'
437 def _date_modification(self
, obj
):
438 return date(obj
.date_modification
) \
439 if obj
.date_modification
is not None else "(aucune)"
440 _date_modification
.short_description
= u
'date modification'
441 _date_modification
.admin_order_field
= 'date_modification'
443 def _poste(self
, dossier
):
444 link
= u
"""<a title="Aperçu du poste"
445 onclick="return showAddAnotherPopup(this);"
446 href='%s'><img src="%simg/loupe.png" />
448 <a href="%s" title="Modifier le poste">%s</a>""" % \
449 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
451 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
455 _poste
.allow_tags
= True
456 _poste
.short_description
= u
'Poste'
457 _poste
.admin_order_field
= 'poste__nom'
459 def _employe(self
, obj
):
460 employe
= obj
.employe
461 view_link
= reverse('employe_apercu', args
=(employe
.id,))
462 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
465 view
= u
"""<a href="%s"
466 title="Aperçu l'employé"
467 onclick="return showAddAnotherPopup(this);">
468 <img src="%simg/loupe.png" />
469 </a>""" % (view_link
, settings
.STATIC_URL
,)
470 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
471 (view
, edit_link
, style
, employe
)
472 _employe
.allow_tags
= True
473 _employe
.short_description
= u
"Employé"
474 _employe
.admin_order_field
= "employe__nom"
476 def save_formset(self
, request
, form
, formset
, change
):
477 instances
= formset
.save(commit
=False)
478 for instance
in instances
:
479 if instance
.__class__
== rh
.DossierCommentaire
:
480 instance
.owner
= request
.user
481 instance
.date_creation
= datetime
.datetime
.now()
485 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
486 ProtectRegionMixin
, BaseAdmin
):
487 prefixe_recherche_temporelle
= "rh_dossiers__"
488 alphabet_filter
= 'nom'
489 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
491 'id', 'nom', 'prenom', 'nom_affichage',
492 'rh_dossiers__poste__nom',
493 'rh_dossiers__poste__nom_feminin'
496 form
= EmployeAdminForm
502 '_date_modification',
505 list_display_links
= ('_nom',)
507 'rh_dossiers__poste__implantation__region',
508 'rh_dossiers__poste__implantation',
511 inlines
= (AyantDroitInline
,
514 EmployeCommentaireInline
)
515 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
519 ('nom_affichage', 'genre'),
524 ('Informations personnelles', {
525 'fields': ('situation_famille', 'date_entree', )}
527 ('Coordonnées personnelles', {
529 ('tel_domicile', 'tel_cellulaire'),
530 ('adresse', 'ville'),
531 ('code_postal', 'province'),
538 def _apercu(self
, obj
):
539 return u
"""<a title="Aperçu de l'employé"
540 onclick="return showAddAnotherPopup(this);"
542 <img src="%simg/loupe.png" />
544 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
545 _apercu
.allow_tags
= True
546 _apercu
.short_description
= u
""
549 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
550 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
551 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
552 _nom
.allow_tags
= True
553 _nom
.short_description
= u
"Employé"
554 _nom
.admin_order_field
= "nom"
558 _id
.short_description
= u
"#"
559 _id
.admin_order_field
= "id"
561 def _date_modification(self
, obj
):
562 return date(obj
.date_modification
) \
563 if obj
.date_modification
is not None else "(aucune)"
564 _date_modification
.short_description
= u
'date modification'
565 _date_modification
.admin_order_field
= 'date_modification'
567 def _dossiers_postes(self
, obj
):
569 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
570 dossier
= u
"""<a title="Aperçu du dossier"
572 onclick="return showAddAnotherPopup(this);"
573 title="Aperçu du dossier">
574 <img src="%simg/loupe.png" />
576 <a href="%s">Dossier</a>
578 (reverse('dossier_apercu', args
=(d
.id,)),
580 reverse('admin:rh_dossier_change', args
=(d
.id,)))
582 poste
= u
"""<a title="Aperçu du poste"
584 onclick="return showAddAnotherPopup(this);"
585 title="Aperçu du poste">
586 <img src="%simg/loupe.png" />
588 <a href="%s">Poste</a>
590 (reverse('poste_apercu', args
=(d
.poste
.id,)),
592 reverse('admin:rh_poste_change', args
=(d
.poste
.id,)))
593 link
= u
"""<li>%s %s - %s : [%s] %s</li>""" % \
600 # Dossier terminé en gris non cliquable
601 if d
.date_fin
is not None and d
.date_fin
< datetime
.date
.today():
602 link
= u
"""<li style="color: grey">%s : [%s] %s</li>""" % \
609 return "<ul>%s</ul>" % "\n".join(l
)
610 _dossiers_postes
.allow_tags
= True
611 _dossiers_postes
.short_description
= u
"Dossiers et postes"
613 def queryset(self
, request
):
614 qs
= super(EmployeAdmin
, self
).queryset(request
)
615 return qs
.select_related(depth
=1).order_by('nom')
617 def save_formset(self
, request
, form
, formset
, change
):
618 instances
= formset
.save(commit
=False)
619 for instance
in instances
:
620 if instance
.__class__
== rh
.EmployeCommentaire
:
621 instance
.owner
= request
.user
622 instance
.date_creation
= datetime
.datetime
.now()
626 class EmployeProxyAdmin(EmployeAdmin
):
627 list_display
= ('_id', '_apercu', '_nom', '_organigramme')
630 def __init__(self
, *args
, **kwargs
):
631 super(EmployeProxyAdmin
, self
).__init__(*args
, **kwargs
)
632 self
.list_display_links
= (None, )
634 def has_add_permission(self
, obj
):
637 def _organigramme(self
, obj
):
639 for d
in rh
.Dossier
.objects
.filter(
640 Q(date_fin__gt
=datetime
.date
.today()) |
Q(date_fin
=None),
641 Q(date_debut__lt
=datetime
.date
.today()) |
Q(date_debut
=None),
645 u
'Organigramme, niveau: ' \
646 u
'<input type="text" id="level_%s" ' \
647 u
'style="width:30px;height:15px;" /> ' \
648 u
'<input type="button" value="Générer" ' \
649 u
"""onclick="window.location='%s' + """ \
650 u
"""document.getElementById('level_%s').value" />""" % (
652 reverse('rho_employe_sans_niveau', args
=(d
.poste
.id,)),
655 link
= u
"""<li>%s - [%s] %s : %s</li>""" % (
662 return "<ul>%s</ul>" % "\n".join(l
)
664 _organigramme
.allow_tags
= True
665 _organigramme
.short_description
= "Organigramme"
668 class CategorieEmploiAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
669 list_display
= ('nom', '_date_modification', 'user_modification', )
670 inlines
= (TypePosteInline
,)
671 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
672 (None, {'fields': ('nom', )}),)
674 def _date_modification(self
, obj
):
675 return date(obj
.date_modification
) \
676 if obj
.date_modification
is not None else "(aucune)"
677 _date_modification
.short_description
= u
'date modification'
678 _date_modification
.admin_order_field
= 'date_modification'
681 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
682 search_fields
= ('nom',)
687 '_date_modification',
690 list_filter
= ('type', )
691 inlines
= (DossierROInline
,)
692 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
693 (None, {'fields': ('nom', 'type', 'pays',)}),
696 def _date_modification(self
, obj
):
697 return date(obj
.date_modification
) \
698 if obj
.date_modification
is not None else "(aucune)"
699 _date_modification
.short_description
= u
'date modification'
700 _date_modification
.admin_order_field
= 'date_modification'
703 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
704 ProtectRegionMixin
, BaseAdmin
, AjaxSelect
):
705 form
= make_ajax_form(rh
.Poste
, {
706 'implantation': 'implantations',
707 'type_poste': 'typepostes',
708 'responsable': 'postes',
709 'valeur_point_min': 'valeurpoints',
710 'valeur_point_max': 'valeurpoints',
712 alphabet_filter
= 'nom'
717 'implantation__region__code',
718 'implantation__region__nom',
719 'rh_dossiers__employe__nom',
720 'rh_dossiers__employe__prenom',
732 '_date_modification',
737 'implantation__region',
741 'type_poste__categorie_emploi',
742 'type_poste__famille_professionnelle',
745 list_display_links
= ('_nom',)
746 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
748 ('nom', 'nom_feminin'),
758 'regime_travail_nb_heure_semaine'),
762 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
765 'fields': (('classement_min',
778 ('Comparatifs de rémunération', {
779 'fields': ('devise_comparaison',
780 ('comp_locale_min', 'comp_locale_max'),
781 ('comp_universite_min', 'comp_universite_max'),
782 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
783 ('comp_ong_min', 'comp_ong_max'),
784 ('comp_autre_min', 'comp_autre_max'))}
787 'fields': ('justification',)}
789 ('Autres Méta-données', {
790 'fields': ('date_debut', 'date_fin')}
794 inlines
= (PosteFinancementInline
,
797 PosteComparaisonInline
,
798 PosteCommentaireInline
, )
800 def lookup_allowed(self
, key
, value
):
802 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
803 'date_fin__isnull', 'implantation__region__id__exact',
804 'implantation__id__exact', 'type_poste__id__exact',
805 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
806 'service__isnull', 'vacant__exact', 'vacant__isnull',
807 ) or super(PosteAdmin
, self
).lookup_allowed(key
, value
)
809 def _apercu(self
, poste
):
810 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);"
811 title="Aperçu du poste"
813 <img src="%simg/loupe.png" />
815 (reverse('poste_apercu', args
=(poste
.id,)),
816 settings
.STATIC_URL
,)
818 _apercu
.allow_tags
= True
819 _apercu
.short_description
= ''
821 def _dae(self
, poste
):
823 postes_dae
= poste
.postes_dae
.all()
824 if len(postes_dae
) > 0:
825 poste_dae
= postes_dae
[0]
827 u
'<a title="Aperçu du dossier" href="%s" ' \
828 u
'onclick="return showAddAnotherPopup(this);">' \
829 u
'<img src="%simg/loupe.png" /></a>' % (reverse(
830 'poste_consulter', args
=("dae-%s" % poste_dae
.id,)
831 ), settings
.STATIC_URL
)
833 _dae
.allow_tags
= True
834 _dae
.short_description
= u
"DAE"
838 _id
.short_description
= '#'
839 _id
.admin_order_field
= 'id'
841 def _service(self
, obj
):
842 if obj
.service
.supprime
:
843 return """<span style="color:red">%s</span>""" % obj
.service
846 _service
.short_description
= 'Service'
847 _service
.allow_tags
= True
849 def _responsable(self
, obj
):
851 responsable
= u
"""<a href="%s"
852 onclick="return showAddAnotherPopup(this)">
853 <img src="%simg/loupe.png"
854 title="Aperçu du poste" />
858 (reverse('poste_apercu', args
=(obj
.responsable
.id,)),
860 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
866 employe
= obj
.responsable
.rh_dossiers
.all()[0]
867 employe_id
= obj
.responsable
.rh_dossiers
.all()[0].id
868 employe_html
= u
"""<br />
870 onclick="return showAddAnotherPopup(this)">
871 <img src="%simg/loupe.png"
872 title="Aperçu de l'employé">
874 <a href="%s">%s</a>""" % \
875 (reverse('employe_apercu', args
=(employe_id
,)),
877 reverse('admin:rh_employe_change', args
=(employe_id
,)),
882 return "%s %s" % (responsable
, employe_html
)
883 _responsable
.short_description
= 'Responsable'
884 _responsable
.allow_tags
= True
886 def _implantation(self
, poste
):
887 return poste
.implantation
.nom
888 _implantation
.short_description
= 'Implantation'
889 _implantation
.admin_order_field
= 'implantation'
891 def _nom(self
, poste
):
892 return """<a href="%s">%s</a>""" % \
893 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
895 _nom
.allow_tags
= True
896 _nom
.short_description
= u
'Poste'
897 _nom
.admin_order_field
= 'nom'
899 def _date_modification(self
, obj
):
900 return date(obj
.date_modification
)
901 _date_modification
.short_description
= u
'date modification'
902 _date_modification
.admin_order_field
= 'date_modification'
904 def _occupe_par(self
, obj
):
905 """Formatte la méthode Poste.occupe_par() pour l'admin"""
907 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.today():
909 employes
= obj
.occupe_par()
913 link
= u
"""<a href='%s'
914 title='Aperçu de l\'employer'
915 onclick='return showAddAnotherPopup(this)'>
916 <img src='%simg/loupe.png' />
918 <a href='%s'>%s</a>""" % \
919 (reverse('employe_apercu', args
=(e
.id,)),
921 reverse('admin:rh_employe_change', args
=(e
.id,)),
924 output
= "\n<br />".join(l
)
926 _occupe_par
.allow_tags
= True
927 _occupe_par
.short_description
= "Occupé par"
929 def save_formset(self
, request
, form
, formset
, change
):
930 instances
= formset
.save(commit
=False)
931 for instance
in instances
:
932 if instance
.__class__
== rh
.PosteCommentaire
:
933 instance
.owner
= request
.user
934 instance
.date_creation
= datetime
.datetime
.now()
939 class ResponsableInline(admin
.TabularInline
):
940 model
= rh
.ResponsableImplantation
942 fk_name
= "implantation"
945 class ResponsableImplantationAdmin(BaseAdmin
):
947 list_filter
= ('region', 'statut', )
948 list_display
= ('nom', 'statut', '_responsable', )
949 readonly_fields
= ('nom', )
951 inlines
= (ResponsableInline
, )
953 def _responsable(self
, obj
):
955 employe
= obj
.responsable
.employe
956 dossiers
= employe
.dossiers_encours()
957 if len(dossiers
) == 0:
958 return u
"<span style='color: red;'>%s %s </span>" % (
959 employe
, u
"sans dossier actif")
963 if obj
.statut
in (1, 2): # ouverte, ouverture imminente
964 css
= "style='color: red;'"
967 return u
"<span %s>Pas de responsable</span>" % css
968 _responsable
.allow_tags
= True
969 _responsable
.short_description
= u
"Responsable"
971 def has_add_permission(self
, request
=None):
974 def has_change_permission(self
, request
, obj
=None):
975 return in_drh_or_admin(request
.user
)
977 def has_delete_permission(self
, request
, obj
=None):
981 class ServiceAdmin(AUFMetadataAdminMixin
, BaseAdmin
, ArchiveMixin
):
985 '_date_modification',
988 list_filter
= ('archive', )
989 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
991 'fields': ('nom', 'archive', ),
995 def _date_modification(self
, obj
):
996 return date(obj
.date_modification
) \
997 if obj
.date_modification
is not None else "(aucune)"
998 _date_modification
.short_description
= u
'date modification'
999 _date_modification
.admin_order_field
= 'date_modification'
1002 class ServiceProxyAdmin(ServiceAdmin
):
1003 list_display
= ('nom', '_organigramme', '_archive', )
1006 def __init__(self
, *args
, **kwargs
):
1007 super(ServiceProxyAdmin
, self
).__init__(*args
, **kwargs
)
1008 self
.list_display_links
= (None, )
1010 def queryset(self
, request
):
1011 return super(ServiceProxyAdmin
, self
).queryset(request
) \
1012 .annotate(num_postes
=Count('rh_postes')) \
1013 .filter(num_postes__gt
=0)
1015 def has_add_permission(self
, obj
):
1018 def has_change_permission(self
, request
, obj
=None):
1019 return in_drh_or_admin(request
.user
)
1021 def _organigramme(self
, obj
):
1022 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1023 (reverse('rho_service', args
=(obj
.id,)))
1024 _organigramme
.allow_tags
= True
1025 _organigramme
.short_description
= "Organigramme"
1028 class StatutAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1029 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
1030 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1032 'fields': ('code', 'nom', ),
1036 def _date_modification(self
, obj
):
1037 return date(obj
.date_modification
) \
1038 if obj
.date_modification
is not None else "(aucune)"
1039 _date_modification
.short_description
= u
'date modification'
1040 _date_modification
.admin_order_field
= 'date_modification'
1043 class TauxChangeAdmin(BaseAdmin
):
1048 '_date_modification',
1049 'user_modification',
1051 list_filter
= ('devise', )
1052 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1054 'fields': ('taux', 'devise', 'annee', ),
1058 def _date_modification(self
, obj
):
1059 return date(obj
.date_modification
) \
1060 if obj
.date_modification
is not None else "(aucune)"
1061 _date_modification
.short_description
= u
'date modification'
1062 _date_modification
.admin_order_field
= 'date_modification'
1065 class TypeContratAdmin(BaseAdmin
):
1069 '_date_modification',
1070 'user_modification',
1072 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1074 'fields': ('nom', 'nom_long', ),
1078 def _date_modification(self
, obj
):
1079 return date(obj
.date_modification
) \
1080 if obj
.date_modification
is not None else "(aucune)"
1081 _date_modification
.short_description
= u
'date modification'
1082 _date_modification
.admin_order_field
= 'date_modification'
1085 class TypePosteAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1086 search_fields
= ('nom', 'nom_feminin', )
1090 '_date_modification',
1091 'user_modification',
1093 list_filter
= ('categorie_emploi', 'famille_professionnelle')
1094 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1101 'famille_professionnelle',
1106 def _date_modification(self
, obj
):
1107 return date(obj
.date_modification
) \
1108 if obj
.date_modification
is not None else "(aucune)"
1109 _date_modification
.short_description
= u
'date modification'
1110 _date_modification
.admin_order_field
= 'date_modification'
1113 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, BaseAdmin
,
1118 'nature_remuneration',
1120 '_date_modification',
1121 'user_modification',)
1122 list_filter
= ('archive', )
1123 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1124 (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration',
1128 def _date_modification(self
, obj
):
1129 return date(obj
.date_modification
) \
1130 if obj
.date_modification
is not None else "(aucune)"
1131 _date_modification
.short_description
= u
'date modification'
1132 _date_modification
.admin_order_field
= 'date_modification'
1135 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1136 list_display
= ('nom', '_date_modification', 'user_modification', )
1137 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1138 (None, {'fields': ('nom', )}),
1141 def _date_modification(self
, obj
):
1142 return date(obj
.date_modification
) \
1143 if obj
.date_modification
is not None else "(aucune)"
1144 _date_modification
.short_description
= u
'date modification'
1145 _date_modification
.admin_order_field
= 'date_modification'
1148 class ValeurPointAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1155 '_date_modification',
1156 'user_modification',
1158 list_filter
= ('annee', 'devise', 'implantation__region', )
1159 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1160 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}),
1163 def _date_modification(self
, obj
):
1164 return date(obj
.date_modification
) \
1165 if obj
.date_modification
is not None else "(aucune)"
1166 _date_modification
.short_description
= u
'date modification'
1167 _date_modification
.admin_order_field
= 'date_modification'
1169 def _devise_code(self
, obj
):
1170 return obj
.devise
.code
1171 _devise_code
.short_description
= "Code de la devise"
1173 def _devise_nom(self
, obj
):
1174 return obj
.devise
.nom
1175 _devise_nom
.short_description
= "Nom de la devise"
1178 class ImplantationProxyAdmin(BaseAdmin
):
1179 list_display
= ('nom', '_organigramme')
1182 def __init__(self
, *args
, **kwargs
):
1183 super(ImplantationProxyAdmin
, self
).__init__(*args
, **kwargs
)
1184 self
.list_display_links
= (None, )
1186 def has_add_permission(self
, obj
):
1189 def has_change_permission(self
, request
, obj
=None):
1190 return in_drh_or_admin(request
.user
)
1192 def _organigramme(self
, obj
):
1193 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1194 reverse('rho_implantation', args
=(obj
.id,))
1196 _organigramme
.allow_tags
= True
1197 _organigramme
.short_description
= "Organigramme"
1200 class RegionProxyAdmin(BaseAdmin
):
1201 list_display
= ('nom', '_organigramme')
1204 def __init__(self
, *args
, **kwargs
):
1205 super(RegionProxyAdmin
, self
).__init__(*args
, **kwargs
)
1206 self
.list_display_links
= (None, )
1208 def has_add_permission(self
, obj
):
1211 def has_change_permission(self
, request
, obj
=None):
1212 return in_drh_or_admin(request
.user
)
1214 def _organigramme(self
, obj
):
1215 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1216 reverse('rho_region', args
=(obj
.id,))
1218 _organigramme
.allow_tags
= True
1219 _organigramme
.short_description
= "Organigramme"
1222 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
1223 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
1224 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
1225 admin
.site
.register(EmployeProxy
, EmployeProxyAdmin
)
1226 admin
.site
.register(ServiceProxy
, ServiceProxyAdmin
)
1227 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
1228 admin
.site
.register(rh
.CategorieEmploi
, CategorieEmploiAdmin
)
1229 admin
.site
.register(rh
.FamilleProfessionnelle
)
1230 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
1231 admin
.site
.register(rh
.Poste
, PosteAdmin
)
1232 admin
.site
.register(
1233 rh
.ResponsableImplantationProxy
, ResponsableImplantationAdmin
1235 admin
.site
.register(rh
.Service
, ServiceAdmin
)
1236 admin
.site
.register(rh
.Statut
, StatutAdmin
)
1237 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
1238 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
1239 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
1240 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
1241 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
1242 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)
1243 admin
.site
.register(ImplantationProxy
, ImplantationProxyAdmin
)
1244 admin
.site
.register(RegionProxy
, RegionProxyAdmin
)