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 ArchiveMixin(object):
27 Archive Mixin pour gérer le queryset et le display
28 NON COMPRIS : list_filter, et list_display, field à setter dans la classe.
31 def queryset(self
, request
):
32 return self
.model
._base_manager
34 def _archive(self
, obj
):
39 _archive
.short_description
= u
'Archivé'
40 _archive
.admin_order_field
= 'archive'
43 class RegionProxy(ref
.Region
):
44 """ Proxy utilisé pour les organigrammes par région """
47 verbose_name
= u
"Organigramme par région"
48 verbose_name_plural
= u
"Organigramme par région"
51 class ImplantationProxy(ref
.Implantation
):
52 """ Proxy utilisé pour les organigrammes par implantation """
55 verbose_name
= u
"Organigramme par implantations"
56 verbose_name_plural
= u
"Organigramme par implantations"
59 class ServiceProxy(rh
.Service
):
60 """ Proxy utilisé pour les organigrammes opar service """
64 verbose_name
= u
"Organigramme par services"
65 verbose_name_plural
= u
"Organigramme par services"
68 class EmployeProxy(rh
.Employe
):
69 """ Proxy utilisé pour les organigrammes des employés """
72 verbose_name
= u
"Organigramme des employés"
73 verbose_name_plural
= u
"Organigramme des employés"
76 class DateRangeMixin(object):
77 prefixe_recherche_temporelle
= ""
79 def get_changelist(self
, request
, **kwargs
):
80 if 'HTTP_REFERER' in request
.META
.keys():
81 referer
= request
.META
['HTTP_REFERER']
82 referer
= "/".join(referer
.split('/')[3:])
83 referer
= "/%s" % referer
.split('?')[0]
84 change_list_view
= 'admin:%s_%s_changelist' % (
85 self
.model
._meta
.app_label
,
86 self
.model
.__name__
.lower(),)
87 if referer
!= reverse(change_list_view
):
88 params
= request
.GET
.copy()
89 params
.update({'statut': 'Actif'})
94 # Override of the InlineModelAdmin to support the link in the tabular inline
95 class LinkedInline(admin
.options
.InlineModelAdmin
):
96 template
= "admin/linked.html"
97 admin_model_path
= None
99 def __init__(self
, *args
):
100 super(LinkedInline
, self
).__init__(*args
)
101 if self
.admin_model_path
is None:
102 self
.admin_model_path
= self
.model
.__name__
.lower()
105 class ProtectRegionMixin(object):
107 def queryset(self
, request
):
108 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
110 user_groups
= request
.user
.groups
.all()
111 if in_drh_or_admin(request
.user
):
114 if grp_correspondants_rh
in user_groups
:
115 employe
= get_employe_from_user(request
.user
)
116 q
= Q(**{self
.model
.prefix_implantation
: \
117 employe
.implantation
.region
})
118 qs
= qs
.filter(q
).distinct()
122 def has_add_permission(self
, request
):
123 if not in_drh_or_admin(request
.user
):
128 def has_change_permission(self
, request
, obj
=None):
129 user_groups
= request
.user
.groups
.all()
131 # Lock pour autoriser uniquement les DRH à utiliser RH
132 if not in_drh_or_admin(request
.user
):
135 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
140 ids
= [o
.id for o
in self
.queryset(request
)]
146 class ReadOnlyInlineMixin(object):
148 def get_readonly_fields(self
, request
, obj
=None):
149 return [f
.name
for f
in self
.model
._meta
.fields \
150 if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
153 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
154 model
= rh
.AyantDroit
155 form
= AyantDroitForm
162 ('nom_affichage', 'genre'),
170 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, \
171 admin
.TabularInline
):
172 readonly_fields
= ('owner', )
173 model
= rh
.AyantDroitCommentaire
177 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
183 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
184 template
= "admin/rh/dossier/linked.html"
185 exclude
= AUF_METADATA_READONLY_FIELDS
190 def has_add_permission(self
, request
=None):
193 def has_change_permission(self
, request
, obj
=None):
196 def has_delete_permission(self
, request
, obj
=None):
200 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, \
201 admin
.TabularInline
):
202 readonly_fields
= ('owner', )
203 model
= rh
.DossierCommentaire
207 class DossierPieceInline(admin
.TabularInline
):
208 model
= rh
.DossierPiece
212 class EmployeInline(admin
.TabularInline
):
216 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, \
217 admin
.TabularInline
):
218 readonly_fields
= ('owner', )
219 model
= rh
.EmployeCommentaire
223 class EmployePieceInline(admin
.TabularInline
):
224 model
= rh
.EmployePiece
228 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
229 readonly_fields
= ('owner', )
230 model
= rh
.PosteCommentaire
234 class PosteFinancementInline(admin
.TabularInline
):
235 model
= rh
.PosteFinancement
238 class PostePieceInline(admin
.TabularInline
):
239 model
= rh
.PostePiece
242 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
243 model
= rh
.Remuneration
247 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
251 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
255 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
256 model
= rh
.PosteComparaison
259 class ClassementAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
260 list_display
= ('_classement', '_date_modification', 'user_modification', )
261 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
263 'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
266 def _classement(self
, obj
):
268 _classement
.short_description
= u
"Classement"
270 def _date_modification(self
, obj
):
271 return date(obj
.date_modification
) \
272 if obj
.date_modification
is not None else "(aucune)"
273 _date_modification
.short_description
= u
'date modification'
274 _date_modification
.admin_order_field
= 'date_modification'
277 class CommentaireAdmin(admin
.ModelAdmin
):
281 class DeviseAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
286 '_date_modification',
289 list_filter
= ('archive', )
290 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
292 'fields': ('code', 'nom', 'archive', ),
296 def _date_modification(self
, obj
):
297 return date(obj
.date_modification
) \
298 if obj
.date_modification
is not None else "(aucune)"
299 _date_modification
.short_description
= u
'date modification'
300 _date_modification
.admin_order_field
= 'date_modification'
303 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
304 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
305 alphabet_filter
= 'employe__nom'
313 'poste__nom_feminin',
314 'poste__implantation__nom',
324 '_date_modification',
328 list_display_links
= ('_nom',)
330 'poste__implantation__region',
331 'poste__implantation',
332 'poste__type_poste__categorie_emploi',
334 'rh_contrats__type_contrat',
337 inlines
= (DossierPieceInline
, ContratInline
,
339 DossierCommentaireInline
,
341 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
348 'organisme_bstg',)}),
353 'remplacement_de', )}),
357 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
358 ('Occupation du Poste par cet Employe', {
359 'fields': (('date_debut', 'date_fin'), )}
362 form
= make_ajax_form(rh
.Dossier
, {
363 'employe': 'employes',
365 'remplacement_de': 'dossiers',
366 }, superclass
=DossierForm
)
368 def lookup_allowed(self
, key
, value
):
370 'employe__nom__istartswith',
371 'poste__implantation__region__id__exact',
372 'poste__implantation__id__exact',
373 'poste__type_poste__id__exact',
374 'poste__type_poste__categorie_emploi__id__exact',
375 'rh_contrats__type_contrat__id__exact',
383 _id
.short_description
= u
"#"
384 _id
.admin_order_field
= "id"
387 return "%d : %s %s" % (
389 obj
.employe
.nom
.upper(),
391 _nom
.allow_tags
= True
392 _nom
.short_description
= u
"Dossier"
394 def _apercu(self
, d
):
395 apercu_link
= u
"""<a title="Aperçu du dossier"
396 onclick="return showAddAnotherPopup(this);"
398 <img src="%simg/loupe.png" />
400 (reverse('dossier_apercu', args
=(d
.id,)),
404 _apercu
.allow_tags
= True
405 _apercu
.short_description
= u
""
409 dossiers_dae
= d
.dossiers_dae
.all()
410 if len(dossiers_dae
) > 0:
411 dossier_dae
= dossiers_dae
[0]
412 apercu_link
= u
"""<a title="Aperçu du dossier"
413 onclick="return showAddAnotherPopup(this);"
415 <img src="%simg/loupe.png" />
417 (reverse('embauche_consulter', args
=(dossier_dae
.id,)),
421 _dae
.allow_tags
= True
422 _dae
.short_description
= u
"DAE"
424 def _date_debut(self
, obj
):
425 return date(obj
.date_debut
)
427 _date_debut
.short_description
= u
'Occupation début'
428 _date_debut
.admin_order_field
= 'date_debut'
430 def _date_fin(self
, obj
):
431 return date(obj
.date_fin
)
432 _date_fin
.short_description
= u
'Occupation fin'
433 _date_fin
.admin_order_field
= 'date_fin'
435 def _date_modification(self
, obj
):
436 return date(obj
.date_modification
) \
437 if obj
.date_modification
is not None else "(aucune)"
438 _date_modification
.short_description
= u
'date modification'
439 _date_modification
.admin_order_field
= 'date_modification'
441 def _poste(self
, dossier
):
442 link
= u
"""<a title="Aperçu du poste"
443 onclick="return showAddAnotherPopup(this);"
444 href='%s'><img src="%simg/loupe.png" />
446 <a href="%s" title="Modifier le poste">%s</a>""" % \
447 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
449 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
453 _poste
.allow_tags
= True
454 _poste
.short_description
= u
'Poste'
455 _poste
.admin_order_field
= 'poste__nom'
457 def _employe(self
, obj
):
458 employe
= obj
.employe
459 view_link
= reverse('employe_apercu', args
=(employe
.id,))
460 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
463 view
= u
"""<a href="%s"
464 title="Aperçu l'employé"
465 onclick="return showAddAnotherPopup(this);">
466 <img src="%simg/loupe.png" />
467 </a>""" % (view_link
, settings
.STATIC_URL
,)
468 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
469 (view
, edit_link
, style
, employe
)
470 _employe
.allow_tags
= True
471 _employe
.short_description
= u
"Employé"
472 _employe
.admin_order_field
= "employe__nom"
474 def save_formset(self
, request
, form
, formset
, change
):
475 instances
= formset
.save(commit
=False)
476 for instance
in instances
:
477 if instance
.__class__
== rh
.DossierCommentaire
:
478 instance
.owner
= request
.user
479 instance
.date_creation
= datetime
.datetime
.now()
483 class DossierPieceAdmin(admin
.ModelAdmin
):
487 class DossierCommentaireAdmin(admin
.ModelAdmin
):
491 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
492 ProtectRegionMixin
, admin
.ModelAdmin
,):
493 prefixe_recherche_temporelle
= "rh_dossiers__"
494 alphabet_filter
= 'nom'
495 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
497 'id', 'nom', 'prenom', 'nom_affichage',
498 'rh_dossiers__poste__nom',
499 'rh_dossiers__poste__nom_feminin'
502 form
= EmployeAdminForm
509 '_date_modification',
512 list_display_links
= ('_nom',)
514 'rh_dossiers__poste__implantation__region',
515 'rh_dossiers__poste__implantation',
518 inlines
= (AyantDroitInline
,
521 EmployeCommentaireInline
)
522 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
526 ('nom_affichage', 'genre'),
531 ('Informations personnelles', {
532 'fields': ('situation_famille', 'date_entree', )}
534 ('Coordonnées personnelles', {
536 ('tel_domicile', 'tel_cellulaire'),
537 ('adresse', 'ville'),
538 ('code_postal', 'province'),
545 def _apercu(self
, obj
):
546 return u
"""<a title="Aperçu de l'employé"
547 onclick="return showAddAnotherPopup(this);"
549 <img src="%simg/loupe.png" />
551 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
552 _apercu
.allow_tags
= True
553 _apercu
.short_description
= u
""
556 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
557 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
558 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
559 _nom
.allow_tags
= True
560 _nom
.short_description
= u
"Employé"
561 _nom
.admin_order_field
= "nom"
565 _id
.short_description
= u
"#"
566 _id
.admin_order_field
= "id"
568 def _date_modification(self
, obj
):
569 return date(obj
.date_modification
) \
570 if obj
.date_modification
is not None else "(aucune)"
571 _date_modification
.short_description
= u
'date modification'
572 _date_modification
.admin_order_field
= 'date_modification'
574 def _dossiers_postes(self
, obj
):
576 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
577 dossier
= u
"""<a title="Aperçu du dossier"
579 onclick="return showAddAnotherPopup(this);"
580 title="Aperçu du dossier">
581 <img src="%simg/loupe.png" />
583 <a href="%s">Dossier</a>
585 (reverse('dossier_apercu', args
=(d
.id,)),
587 reverse('admin:rh_dossier_change', args
=(d
.id,)))
589 poste
= u
"""<a title="Aperçu du poste"
591 onclick="return showAddAnotherPopup(this);"
592 title="Aperçu du poste">
593 <img src="%simg/loupe.png" />
595 <a href="%s">Poste</a>
597 (reverse('poste_apercu', args
=(d
.poste
.id,)),
599 reverse('admin:rh_poste_change', args
=(d
.poste
.id,)))
600 link
= u
"""<li>%s %s - %s : [%s] %s</li>""" % \
607 # Dossier terminé en gris non cliquable
608 if d
.date_fin
is not None and d
.date_fin
< datetime
.date
.today():
609 link
= u
"""<li style="color: grey">%s : [%s] %s</li>""" % \
616 return "<ul>%s</ul>" % "\n".join(l
)
617 _dossiers_postes
.allow_tags
= True
618 _dossiers_postes
.short_description
= u
"Dossiers et postes"
620 def queryset(self
, request
):
621 qs
= super(EmployeAdmin
, self
).queryset(request
)
622 return qs
.select_related(depth
=1).order_by('nom')
624 def save_formset(self
, request
, form
, formset
, change
):
625 instances
= formset
.save(commit
=False)
626 for instance
in instances
:
627 if instance
.__class__
== rh
.EmployeCommentaire
:
628 instance
.owner
= request
.user
629 instance
.date_creation
= datetime
.datetime
.now()
633 class EmployeProxyAdmin(EmployeAdmin
):
634 list_display
= ('_id', '_apercu', '_nom', '_organigramme')
637 def __init__(self
, *args
, **kwargs
):
638 super(EmployeProxyAdmin
, self
).__init__(*args
, **kwargs
)
639 self
.list_display_links
= (None, )
641 def has_add_permission(self
, obj
):
644 def _organigramme(self
, obj
):
646 for d
in rh
.Dossier
.objects
.filter(
647 Q(date_fin__gt
=datetime
.date
.today()) |
Q(date_fin
=None),
648 Q(date_debut__lt
=datetime
.date
.today()) |
Q(date_debut
=None),
652 u
'Organigramme, niveau: ' \
653 u
'<input type="text" id="level_%s" ' \
654 u
'style="width:30px;height:15px;" /> ' \
655 u
'<input type="button" value="Générer" ' \
656 u
"""onclick="window.location='%s' + """ \
657 u
"""document.getElementById('level_%s').value" />""" % (
659 reverse('rho_employe_sans_niveau', args
=(d
.poste
.id,)),
662 link
= u
"""<li>%s - [%s] %s : %s</li>""" % (
669 return "<ul>%s</ul>" % "\n".join(l
)
671 _organigramme
.allow_tags
= True
672 _organigramme
.short_description
= "Organigramme"
675 class EmployeCommentaireAdmin(admin
.ModelAdmin
):
679 class EmployePieceAdmin(admin
.ModelAdmin
):
683 class CategorieEmploiAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
684 list_display
= ('nom', '_date_modification', 'user_modification', )
685 inlines
= (TypePosteInline
,)
686 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
687 (None, {'fields': ('nom', )}),)
689 def _date_modification(self
, obj
):
690 return date(obj
.date_modification
) \
691 if obj
.date_modification
is not None else "(aucune)"
692 _date_modification
.short_description
= u
'date modification'
693 _date_modification
.admin_order_field
= 'date_modification'
696 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
697 search_fields
= ('nom',)
702 '_date_modification',
705 list_filter
= ('type', )
706 inlines
= (DossierROInline
,)
707 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
708 (None, {'fields': ('nom', 'type', 'pays',)}),
711 def _date_modification(self
, obj
):
712 return date(obj
.date_modification
) \
713 if obj
.date_modification
is not None else "(aucune)"
714 _date_modification
.short_description
= u
'date modification'
715 _date_modification
.admin_order_field
= 'date_modification'
718 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
719 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
720 form
= make_ajax_form(rh
.Poste
, {
721 'implantation': 'implantations',
722 'type_poste': 'typepostes',
723 'responsable': 'postes',
724 'valeur_point_min': 'valeurpoints',
725 'valeur_point_max': 'valeurpoints',
727 alphabet_filter
= 'nom'
732 'implantation__region__code',
733 'implantation__region__nom',
734 'rh_dossiers__employe__nom',
735 'rh_dossiers__employe__prenom',
747 '_date_modification',
752 'implantation__region',
756 'type_poste__categorie_emploi',
757 'type_poste__famille_professionnelle',
760 list_display_links
= ('_nom',)
761 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
763 ('nom', 'nom_feminin'),
773 'regime_travail_nb_heure_semaine'),
777 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
780 'fields': (('classement_min',
793 ('Comparatifs de rémunération', {
794 'fields': ('devise_comparaison',
795 ('comp_locale_min', 'comp_locale_max'),
796 ('comp_universite_min', 'comp_universite_max'),
797 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
798 ('comp_ong_min', 'comp_ong_max'),
799 ('comp_autre_min', 'comp_autre_max'))}
802 'fields': ('justification',)}
804 ('Autres Méta-données', {
805 'fields': ('date_debut', 'date_fin')}
809 inlines
= (PosteFinancementInline
,
812 PosteComparaisonInline
,
813 PosteCommentaireInline
, )
815 def lookup_allowed(self
, key
, value
):
817 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
818 'date_fin__isnull', 'implantation__region__id__exact',
819 'implantation__id__exact', 'type_poste__id__exact',
820 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
821 'service__isnull', 'vacant__exact', 'vacant__isnull',
822 ) or super(PosteAdmin
, self
).lookup_allowed(key
, value
)
824 def _apercu(self
, poste
):
825 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);"
826 title="Aperçu du poste"
828 <img src="%simg/loupe.png" />
830 (reverse('poste_apercu', args
=(poste
.id,)),
831 settings
.STATIC_URL
,)
833 _apercu
.allow_tags
= True
834 _apercu
.short_description
= ''
836 def _dae(self
, poste
):
838 postes_dae
= poste
.postes_dae
.all()
839 if len(postes_dae
) > 0:
840 poste_dae
= postes_dae
[0]
842 u
'<a title="Aperçu du dossier" href="%s" ' \
843 u
'onclick="return showAddAnotherPopup(this);">' \
844 u
'<img src="%simg/loupe.png" /></a>' % (reverse(
845 'poste_consulter', args
=("dae-%s" % poste_dae
.id,)
846 ), settings
.STATIC_URL
)
848 _dae
.allow_tags
= True
849 _dae
.short_description
= u
"DAE"
853 _id
.short_description
= '#'
854 _id
.admin_order_field
= 'id'
856 def _service(self
, obj
):
857 if obj
.service
.supprime
:
858 return """<span style="color:red">%s</span>""" % obj
.service
861 _service
.short_description
= 'Service'
862 _service
.allow_tags
= True
864 def _responsable(self
, obj
):
866 responsable
= u
"""<a href="%s"
867 onclick="return showAddAnotherPopup(this)">
868 <img src="%simg/loupe.png"
869 title="Aperçu du poste" />
873 (reverse('poste_apercu', args
=(obj
.responsable
.id,)),
875 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
881 employe
= obj
.responsable
.rh_dossiers
.all()[0]
882 employe_id
= obj
.responsable
.rh_dossiers
.all()[0].id
883 employe_html
= u
"""<br />
885 onclick="return showAddAnotherPopup(this)">
886 <img src="%simg/loupe.png"
887 title="Aperçu de l'employé">
889 <a href="%s">%s</a>""" % \
890 (reverse('employe_apercu', args
=(employe_id
,)),
892 reverse('admin:rh_employe_change', args
=(employe_id
,)),
897 return "%s %s" % (responsable
, employe_html
)
898 _responsable
.short_description
= 'Responsable'
899 _responsable
.allow_tags
= True
901 def _implantation(self
, poste
):
902 return poste
.implantation
.nom
903 _implantation
.short_description
= 'Implantation'
904 _implantation
.admin_order_field
= 'implantation'
906 def _nom(self
, poste
):
907 return """<a href="%s">%s</a>""" % \
908 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
910 _nom
.allow_tags
= True
911 _nom
.short_description
= u
'Poste'
912 _nom
.admin_order_field
= 'nom'
914 def _date_modification(self
, obj
):
915 return date(obj
.date_modification
)
916 _date_modification
.short_description
= u
'date modification'
917 _date_modification
.admin_order_field
= 'date_modification'
919 def _occupe_par(self
, obj
):
920 """Formatte la méthode Poste.occupe_par() pour l'admin"""
922 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.today():
924 employes
= obj
.occupe_par()
928 link
= u
"""<a href='%s'
929 title='Aperçu de l\'employer'
930 onclick='return showAddAnotherPopup(this)'>
931 <img src='%simg/loupe.png' />
933 <a href='%s'>%s</a>""" % \
934 (reverse('employe_apercu', args
=(e
.id,)),
936 reverse('admin:rh_employe_change', args
=(e
.id,)),
939 output
= "\n<br />".join(l
)
941 _occupe_par
.allow_tags
= True
942 _occupe_par
.short_description
= "Occupé par"
944 def save_formset(self
, request
, form
, formset
, change
):
945 instances
= formset
.save(commit
=False)
946 for instance
in instances
:
947 if instance
.__class__
== rh
.PosteCommentaire
:
948 instance
.owner
= request
.user
949 instance
.date_creation
= datetime
.datetime
.now()
954 class PosteCommentaireAdmin(admin
.ModelAdmin
):
958 class PosteFinancementAdmin(admin
.ModelAdmin
):
962 class PostePieceAdmin(admin
.ModelAdmin
):
966 class RemunerationAdmin(admin
.ModelAdmin
):
970 class ResponsableInline(admin
.TabularInline
):
971 model
= rh
.ResponsableImplantation
973 fk_name
= "implantation"
976 class ResponsableImplantationAdmin(admin
.ModelAdmin
):
978 list_filter
= ('region', 'statut', )
979 list_display
= ('nom', 'statut', '_responsable', )
980 readonly_fields
= ('nom', )
982 inlines
= (ResponsableInline
, )
984 def _responsable(self
, obj
):
986 employe
= obj
.responsable
.employe
987 dossiers
= employe
.dossiers_encours()
988 if len(dossiers
) == 0:
989 return u
"<span style='color: red;'>%s %s </span>" % (
990 employe
, u
"sans dossier actif")
994 if obj
.statut
in (1, 2): # ouverte, ouverture imminente
995 css
= "style='color: red;'"
998 return u
"<span %s>Pas de responsable</span>" % css
999 _responsable
.allow_tags
= True
1000 _responsable
.short_description
= u
"Responsable"
1002 def has_add_permission(self
, request
=None):
1005 def has_change_permission(self
, request
, obj
=None):
1006 return in_drh_or_admin(request
.user
)
1008 def has_delete_permission(self
, request
, obj
=None):
1012 class ServiceAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
1016 '_date_modification',
1017 'user_modification',
1019 list_filter
= ('archive', )
1020 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1022 'fields': ('nom', 'archive', ),
1026 def _date_modification(self
, obj
):
1027 return date(obj
.date_modification
) \
1028 if obj
.date_modification
is not None else "(aucune)"
1029 _date_modification
.short_description
= u
'date modification'
1030 _date_modification
.admin_order_field
= 'date_modification'
1033 class ServiceProxyAdmin(ServiceAdmin
):
1034 list_display
= ('nom', '_organigramme', '_archive', )
1037 def __init__(self
, *args
, **kwargs
):
1038 super(ServiceProxyAdmin
, self
).__init__(*args
, **kwargs
)
1039 self
.list_display_links
= (None, )
1041 def queryset(self
, request
):
1042 return super(ServiceProxyAdmin
, self
).queryset(request
) \
1043 .annotate(num_postes
=Count('rh_postes')) \
1044 .filter(num_postes__gt
=0)
1046 def has_add_permission(self
, obj
):
1049 def has_change_permission(self
, request
, obj
=None):
1050 return in_drh_or_admin(request
.user
)
1052 def _organigramme(self
, obj
):
1053 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1054 (reverse('rho_service', args
=(obj
.id,)))
1055 _organigramme
.allow_tags
= True
1056 _organigramme
.short_description
= "Organigramme"
1059 class StatutAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1060 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
1061 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1063 'fields': ('code', 'nom', ),
1067 def _date_modification(self
, obj
):
1068 return date(obj
.date_modification
) \
1069 if obj
.date_modification
is not None else "(aucune)"
1070 _date_modification
.short_description
= u
'date modification'
1071 _date_modification
.admin_order_field
= 'date_modification'
1074 class TauxChangeAdmin(admin
.ModelAdmin
):
1079 '_date_modification',
1080 'user_modification',
1082 list_filter
= ('devise', )
1083 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1085 'fields': ('taux', 'devise', 'annee', ),
1089 def _date_modification(self
, obj
):
1090 return date(obj
.date_modification
) \
1091 if obj
.date_modification
is not None else "(aucune)"
1092 _date_modification
.short_description
= u
'date modification'
1093 _date_modification
.admin_order_field
= 'date_modification'
1096 class TypeContratAdmin(admin
.ModelAdmin
):
1100 '_date_modification',
1101 'user_modification',
1103 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1105 'fields': ('nom', 'nom_long', ),
1109 def _date_modification(self
, obj
):
1110 return date(obj
.date_modification
) \
1111 if obj
.date_modification
is not None else "(aucune)"
1112 _date_modification
.short_description
= u
'date modification'
1113 _date_modification
.admin_order_field
= 'date_modification'
1116 class TypePosteAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1117 search_fields
= ('nom', 'nom_feminin', )
1121 '_date_modification',
1122 'user_modification',
1124 list_filter
= ('categorie_emploi', 'famille_professionnelle')
1125 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1132 'famille_professionnelle',
1137 def _date_modification(self
, obj
):
1138 return date(obj
.date_modification
) \
1139 if obj
.date_modification
is not None else "(aucune)"
1140 _date_modification
.short_description
= u
'date modification'
1141 _date_modification
.admin_order_field
= 'date_modification'
1144 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
,
1149 'nature_remuneration',
1151 '_date_modification',
1152 'user_modification',)
1153 list_filter
= ('archive', )
1154 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1155 (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration',
1159 def _date_modification(self
, obj
):
1160 return date(obj
.date_modification
) \
1161 if obj
.date_modification
is not None else "(aucune)"
1162 _date_modification
.short_description
= u
'date modification'
1163 _date_modification
.admin_order_field
= 'date_modification'
1166 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1167 list_display
= ('nom', '_date_modification', 'user_modification', )
1168 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1169 (None, {'fields': ('nom', )}),
1172 def _date_modification(self
, obj
):
1173 return date(obj
.date_modification
) \
1174 if obj
.date_modification
is not None else "(aucune)"
1175 _date_modification
.short_description
= u
'date modification'
1176 _date_modification
.admin_order_field
= 'date_modification'
1179 class ValeurPointAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1186 '_date_modification',
1187 'user_modification',
1189 list_filter
= ('annee', 'devise', 'implantation__region', )
1190 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1191 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}),
1194 def _date_modification(self
, obj
):
1195 return date(obj
.date_modification
) \
1196 if obj
.date_modification
is not None else "(aucune)"
1197 _date_modification
.short_description
= u
'date modification'
1198 _date_modification
.admin_order_field
= 'date_modification'
1200 def _devise_code(self
, obj
):
1201 return obj
.devise
.code
1202 _devise_code
.short_description
= "Code de la devise"
1204 def _devise_nom(self
, obj
):
1205 return obj
.devise
.nom
1206 _devise_nom
.short_description
= "Nom de la devise"
1209 class ImplantationProxyAdmin(admin
.ModelAdmin
):
1210 list_display
= ('nom', '_organigramme')
1213 def __init__(self
, *args
, **kwargs
):
1214 super(ImplantationProxyAdmin
, self
).__init__(*args
, **kwargs
)
1215 self
.list_display_links
= (None, )
1217 def has_add_permission(self
, obj
):
1220 def has_change_permission(self
, request
, obj
=None):
1221 return in_drh_or_admin(request
.user
)
1223 def _organigramme(self
, obj
):
1224 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1225 reverse('rho_implantation', args
=(obj
.id,))
1227 _organigramme
.allow_tags
= True
1228 _organigramme
.short_description
= "Organigramme"
1231 class RegionProxyAdmin(admin
.ModelAdmin
):
1232 list_display
= ('nom', '_organigramme')
1235 def __init__(self
, *args
, **kwargs
):
1236 super(RegionProxyAdmin
, self
).__init__(*args
, **kwargs
)
1237 self
.list_display_links
= (None, )
1239 def has_add_permission(self
, obj
):
1242 def has_change_permission(self
, request
, obj
=None):
1243 return in_drh_or_admin(request
.user
)
1245 def _organigramme(self
, obj
):
1246 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1247 reverse('rho_region', args
=(obj
.id,))
1249 _organigramme
.allow_tags
= True
1250 _organigramme
.short_description
= "Organigramme"
1253 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
1254 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
1255 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
1256 admin
.site
.register(EmployeProxy
, EmployeProxyAdmin
)
1257 admin
.site
.register(ServiceProxy
, ServiceProxyAdmin
)
1258 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
1259 admin
.site
.register(rh
.CategorieEmploi
, CategorieEmploiAdmin
)
1260 admin
.site
.register(rh
.FamilleProfessionnelle
)
1261 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
1262 admin
.site
.register(rh
.Poste
, PosteAdmin
)
1263 admin
.site
.register(
1264 rh
.ResponsableImplantationProxy
, ResponsableImplantationAdmin
1266 admin
.site
.register(rh
.Service
, ServiceAdmin
)
1267 admin
.site
.register(rh
.Statut
, StatutAdmin
)
1268 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
1269 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
1270 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
1271 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
1272 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
1273 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)
1274 admin
.site
.register(ImplantationProxy
, ImplantationProxyAdmin
)
1275 admin
.site
.register(RegionProxy
, RegionProxyAdmin
)