1 # -*- encoding: utf-8 -*-
5 from django
.core
.urlresolvers
import reverse
6 from django
.contrib
import admin
7 from django
.conf
import settings
8 from django
.db
.models
import Q
, Count
9 from django
.template
.defaultfilters
import date
11 from ajax_select
import make_ajax_form
13 from auf
.django
.metadata
.admin
import \
14 AUFMetadataAdminMixin
, AUFMetadataInlineAdminMixin
, \
15 AUF_METADATA_READONLY_FIELDS
16 import auf
.django
.references
.models
as ref
18 from project
import groups
19 from project
.decorators
import in_drh_or_admin
20 from project
.groups
import get_employe_from_user
22 import project
.rh
.models
as rh
23 from project
.rh
.forms
import \
24 ContratForm
, AyantDroitForm
, EmployeAdminForm
, AjaxSelect
, DossierForm
25 from project
.rh
.change_list
import ChangeList
28 class BaseAdmin(admin
.ModelAdmin
):
32 'css/admin_custom.css',
33 'jquery-autocomplete/jquery.autocomplete.css',
36 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
37 'jquery-autocomplete/jquery.autocomplete.min.js',
41 class ArchiveMixin(object):
43 Archive Mixin pour gérer le queryset et le display
44 NON COMPRIS : list_filter, et list_display, field à setter dans la classe.
47 def queryset(self
, request
):
48 return self
.model
._base_manager
50 def _archive(self
, obj
):
55 _archive
.short_description
= u
'Archivé'
56 _archive
.admin_order_field
= 'archive'
59 class RegionProxy(ref
.Region
):
60 """ Proxy utilisé pour les organigrammes par région """
64 verbose_name
= u
"Organigramme par région"
65 verbose_name_plural
= u
"Organigramme par région"
68 class ImplantationProxy(ref
.Implantation
):
69 """ Proxy utilisé pour les organigrammes par implantation """
73 verbose_name
= u
"Organigramme par implantations"
74 verbose_name_plural
= u
"Organigramme par implantations"
77 class ServiceProxy(rh
.Service
):
78 """ Proxy utilisé pour les organigrammes opar service """
83 verbose_name
= u
"Organigramme par services"
84 verbose_name_plural
= u
"Organigramme par services"
87 class EmployeProxy(rh
.Employe
):
88 """ Proxy utilisé pour les organigrammes des employés """
92 verbose_name
= u
"Organigramme des employés"
93 verbose_name_plural
= u
"Organigramme des employés"
96 class DateRangeMixin(object):
97 prefixe_recherche_temporelle
= ""
99 def get_changelist(self
, request
, **kwargs
):
100 if 'HTTP_REFERER' in request
.META
.keys():
101 referer
= request
.META
['HTTP_REFERER']
102 referer
= "/".join(referer
.split('/')[3:])
103 referer
= "/%s" % referer
.split('?')[0]
104 change_list_view
= 'admin:%s_%s_changelist' % (
105 self
.model
._meta
.app_label
,
106 self
.model
.__name__
.lower(),)
107 if referer
!= reverse(change_list_view
):
108 params
= request
.GET
.copy()
109 params
.update({'statut': 'Actif'})
114 # Override of the InlineModelAdmin to support the link in the tabular inline
115 class LinkedInline(admin
.options
.InlineModelAdmin
):
116 template
= "admin/linked.html"
117 admin_model_path
= None
119 def __init__(self
, *args
):
120 super(LinkedInline
, self
).__init__(*args
)
121 if self
.admin_model_path
is None:
122 self
.admin_model_path
= self
.model
.__name__
.lower()
125 class ProtectRegionMixin(object):
127 def queryset(self
, request
):
128 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
130 user_groups
= request
.user
.groups
.all()
131 if in_drh_or_admin(request
.user
):
134 if groups
.grp_correspondants_rh
in user_groups
or\
135 groups
.grp_administrateurs
in user_groups
or\
136 groups
.grp_directeurs_bureau
in user_groups
:
137 employe
= get_employe_from_user(request
.user
)
138 q
= Q(**{self
.model
.prefix_implantation
: \
139 employe
.implantation
.region
})
140 qs
= qs
.filter(q
).distinct()
144 def has_add_permission(self
, request
):
145 if not in_drh_or_admin(request
.user
):
150 def has_change_permission(self
, request
, obj
=None):
151 user_groups
= request
.user
.groups
.all()
153 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
158 ids
= [o
.id for o
in self
.queryset(request
)]
164 class ReadOnlyInlineMixin(object):
166 def get_readonly_fields(self
, request
, obj
=None):
167 return [f
.name
for f
in self
.model
._meta
.fields \
168 if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
171 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
172 model
= rh
.AyantDroit
173 form
= AyantDroitForm
180 ('nom_affichage', 'genre'),
188 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, \
189 admin
.TabularInline
):
190 readonly_fields
= ('owner', )
191 model
= rh
.AyantDroitCommentaire
195 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
201 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
202 template
= "admin/rh/dossier/linked.html"
203 exclude
= AUF_METADATA_READONLY_FIELDS
208 def has_add_permission(self
, request
=None):
211 def has_change_permission(self
, request
, obj
=None):
214 def has_delete_permission(self
, request
, obj
=None):
218 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, \
219 admin
.TabularInline
):
220 readonly_fields
= ('owner', )
221 model
= rh
.DossierCommentaire
225 class DossierPieceInline(admin
.TabularInline
):
226 model
= rh
.DossierPiece
230 class EmployeInline(admin
.TabularInline
):
234 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, \
235 admin
.TabularInline
):
236 readonly_fields
= ('owner', )
237 model
= rh
.EmployeCommentaire
241 class EmployePieceInline(admin
.TabularInline
):
242 model
= rh
.EmployePiece
246 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
247 readonly_fields
= ('owner', )
248 model
= rh
.PosteCommentaire
252 class PosteFinancementInline(admin
.TabularInline
):
253 model
= rh
.PosteFinancement
256 class PostePieceInline(admin
.TabularInline
):
257 model
= rh
.PostePiece
260 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
261 model
= rh
.Remuneration
265 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
269 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
273 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
274 model
= rh
.PosteComparaison
277 class ClassementAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
278 list_display
= ('_classement', '_date_modification', 'user_modification', )
279 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
281 'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
284 def _classement(self
, obj
):
286 _classement
.short_description
= u
"Classement"
288 def _date_modification(self
, obj
):
289 return date(obj
.date_modification
) \
290 if obj
.date_modification
is not None else "(aucune)"
291 _date_modification
.short_description
= u
'date modification'
292 _date_modification
.admin_order_field
= 'date_modification'
295 class DeviseAdmin(AUFMetadataAdminMixin
, BaseAdmin
, ArchiveMixin
):
300 '_date_modification',
303 list_filter
= ('archive', )
304 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
306 'fields': ('code', 'nom', 'archive', ),
310 def _date_modification(self
, obj
):
311 return date(obj
.date_modification
) \
312 if obj
.date_modification
is not None else "(aucune)"
313 _date_modification
.short_description
= u
'date modification'
314 _date_modification
.admin_order_field
= 'date_modification'
317 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
318 ProtectRegionMixin
, BaseAdmin
, AjaxSelect
):
319 alphabet_filter
= 'employe__nom'
327 'poste__nom_feminin',
328 'poste__implantation__nom',
338 '_date_modification',
342 list_display_links
= ('_nom',)
344 'poste__implantation__region',
345 'poste__implantation',
346 'poste__type_poste__categorie_emploi',
348 'rh_contrats__type_contrat',
351 inlines
= (DossierPieceInline
, ContratInline
,
353 DossierCommentaireInline
,
355 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
362 'organisme_bstg',)}),
367 'remplacement_de', )}),
371 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
372 ('Occupation du Poste par cet Employe', {
373 'fields': (('date_debut', 'date_fin'), )}
376 form
= make_ajax_form(rh
.Dossier
, {
377 'employe': 'employes',
379 'remplacement_de': 'dossiers',
380 }, superclass
=DossierForm
)
382 def has_add_permission(self
, request
):
383 user_groups
= request
.user
.groups
.all()
384 if groups
.grp_correspondants_rh
in user_groups
or \
385 groups
.grp_administrateurs
in user_groups
or \
386 groups
.grp_directeurs_bureau
in user_groups
or \
387 in_drh_or_admin(request
.user
):
391 def has_delete_permission(self
, request
, obj
=None):
392 return in_drh_or_admin(request
.user
)
394 def lookup_allowed(self
, key
, value
):
396 'employe__nom__istartswith',
397 'poste__implantation__region__id__exact',
398 'poste__implantation__id__exact',
399 'poste__type_poste__id__exact',
400 'poste__type_poste__categorie_emploi__id__exact',
401 'rh_contrats__type_contrat__id__exact',
409 _id
.short_description
= u
"#"
410 _id
.admin_order_field
= "id"
413 return "%d : %s %s" % (
415 obj
.employe
.nom
.upper(),
417 _nom
.allow_tags
= True
418 _nom
.short_description
= u
"Dossier"
420 def _apercu(self
, d
):
421 apercu_link
= u
"""<a title="Aperçu du dossier"
422 onclick="return showAddAnotherPopup(this);"
424 <img src="%simg/dossier-apercu.png" />
426 (reverse('dossier_apercu', args
=(d
.id,)),
430 _apercu
.allow_tags
= True
431 _apercu
.short_description
= u
""
435 dossiers_dae
= d
.dossiers_dae
.all()
436 if len(dossiers_dae
) > 0:
437 dossier_dae
= dossiers_dae
[0]
438 apercu_link
= u
"""<a title="Aperçu du dossier"
439 onclick="return showAddAnotherPopup(this);"
441 <img src="%simg/loupe.png" />
443 (reverse('embauche_consulter', args
=(dossier_dae
.id,)),
447 _dae
.allow_tags
= True
448 _dae
.short_description
= u
"DAE"
450 def _date_debut(self
, obj
):
451 return date(obj
.date_debut
)
453 _date_debut
.short_description
= u
'Occupation début'
454 _date_debut
.admin_order_field
= 'date_debut'
456 def _date_fin(self
, obj
):
457 return date(obj
.date_fin
)
458 _date_fin
.short_description
= u
'Occupation fin'
459 _date_fin
.admin_order_field
= 'date_fin'
461 def _date_modification(self
, obj
):
462 return date(obj
.date_modification
) \
463 if obj
.date_modification
is not None else "(aucune)"
464 _date_modification
.short_description
= u
'date modification'
465 _date_modification
.admin_order_field
= 'date_modification'
467 def _poste(self
, dossier
):
468 link
= u
"""<a title="Aperçu du poste"
469 onclick="return showAddAnotherPopup(this);"
470 href='%s'><img src="%simg/poste-apercu.png" />
472 <a href="%s" title="Modifier le poste">%s</a>""" % \
473 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
475 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
479 _poste
.allow_tags
= True
480 _poste
.short_description
= u
'Poste'
481 _poste
.admin_order_field
= 'poste__nom'
483 def _employe(self
, obj
):
484 employe
= obj
.employe
485 view_link
= reverse('employe_apercu', args
=(employe
.id,))
486 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
489 view
= u
"""<a href="%s"
490 title="Aperçu l'employé"
491 onclick="return showAddAnotherPopup(this);">
492 <img src="%simg/employe-apercu.png" />
493 </a>""" % (view_link
, settings
.STATIC_URL
,)
494 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
495 (view
, edit_link
, style
, employe
)
496 _employe
.allow_tags
= True
497 _employe
.short_description
= u
"Employé"
498 _employe
.admin_order_field
= "employe__nom"
500 def save_formset(self
, request
, form
, formset
, change
):
501 instances
= formset
.save(commit
=False)
502 for instance
in instances
:
503 if instance
.__class__
== rh
.DossierCommentaire
:
504 instance
.owner
= request
.user
505 instance
.date_creation
= datetime
.datetime
.now()
509 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
510 ProtectRegionMixin
, BaseAdmin
):
511 prefixe_recherche_temporelle
= "rh_dossiers__"
512 alphabet_filter
= 'nom'
513 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
515 'id', 'nom', 'prenom', 'nom_affichage',
516 'rh_dossiers__poste__nom',
517 'rh_dossiers__poste__nom_feminin'
520 form
= EmployeAdminForm
527 '_date_modification',
530 list_display_links
= ('_nom',)
532 'rh_dossiers__poste__implantation__region',
533 'rh_dossiers__poste__implantation',
536 inlines
= (AyantDroitInline
,
539 EmployeCommentaireInline
)
540 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
544 ('nom_affichage', 'genre'),
549 ('Informations personnelles', {
550 'fields': ('situation_famille', 'date_entree', )}
552 ('Coordonnées personnelles', {
554 ('tel_domicile', 'tel_cellulaire'),
555 ('adresse', 'ville'),
556 ('code_postal', 'province'),
563 def has_add_permission(self
, request
):
564 user_groups
= request
.user
.groups
.all()
565 if groups
.grp_correspondants_rh
in user_groups
or \
566 groups
.grp_administrateurs
in user_groups
or \
567 groups
.grp_directeurs_bureau
in user_groups
or \
568 in_drh_or_admin(request
.user
):
572 def has_delete_permission(self
, request
, obj
=None):
573 return in_drh_or_admin(request
.user
)
575 def _apercu(self
, obj
):
576 return u
"""<a title="Aperçu de l'employé"
577 onclick="return showAddAnotherPopup(this);"
579 <img src="%simg/employe-apercu.png" />
581 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
582 _apercu
.allow_tags
= True
583 _apercu
.short_description
= u
""
586 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
587 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
588 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
589 _nom
.allow_tags
= True
590 _nom
.short_description
= u
"Employé"
591 _nom
.admin_order_field
= "nom"
595 _id
.short_description
= u
"#"
596 _id
.admin_order_field
= "id"
598 def _date_modification(self
, obj
):
599 return date(obj
.date_modification
) \
600 if obj
.date_modification
is not None else "(aucune)"
601 _date_modification
.short_description
= u
'date modification'
602 _date_modification
.admin_order_field
= 'date_modification'
604 def _dossiers_postes(self
, obj
):
606 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
607 dossier
= u
"""<a title="Aperçu du dossier"
609 onclick="return showAddAnotherPopup(this);"
610 title="Aperçu du dossier">
611 <img src="%simg/dossier-apercu.png" />
613 <a href="%s">Dossier</a>
615 (reverse('dossier_apercu', args
=(d
.id,)),
617 reverse('admin:rh_dossier_change', args
=(d
.id,)))
619 poste
= u
"""<a title="Aperçu du poste"
621 onclick="return showAddAnotherPopup(this);"
622 title="Aperçu du poste">
623 <img src="%simg/poste-apercu.png" />
625 <a href="%s">Poste</a>
627 (reverse('poste_apercu', args
=(d
.poste
.id,)),
629 reverse('admin:rh_poste_change', args
=(d
.poste
.id,)))
630 link
= u
"""<li>%s %s - %s : [%s] %s</li>""" % \
637 # Dossier terminé en gris non cliquable
638 if d
.date_fin
is not None and d
.date_fin
< datetime
.date
.today():
639 link
= u
"""<li style="color: grey">%s : [%s] %s</li>""" % \
646 return "<ul>%s</ul>" % "\n".join(l
)
647 _dossiers_postes
.allow_tags
= True
648 _dossiers_postes
.short_description
= u
"Dossiers et postes"
650 def queryset(self
, request
):
651 qs
= super(EmployeAdmin
, self
).queryset(request
)
652 return qs
.select_related(depth
=1).order_by('nom')
654 def save_formset(self
, request
, form
, formset
, change
):
655 instances
= formset
.save(commit
=False)
656 for instance
in instances
:
657 if instance
.__class__
== rh
.EmployeCommentaire
:
658 instance
.owner
= request
.user
659 instance
.date_creation
= datetime
.datetime
.now()
663 class EmployeProxyAdmin(EmployeAdmin
):
664 list_display
= ('_id', '_apercu', '_nom', '_organigramme')
667 def __init__(self
, *args
, **kwargs
):
668 super(EmployeProxyAdmin
, self
).__init__(*args
, **kwargs
)
669 self
.list_display_links
= (None, )
671 def has_add_permission(self
, obj
):
674 def has_change_permission(self
, request
, obj
=None):
675 user_groups
= request
.user
.groups
.all()
676 if groups
.grp_correspondants_rh
in user_groups
or \
677 groups
.grp_administrateurs
in user_groups
or \
678 groups
.grp_directeurs_bureau
in user_groups
or \
679 in_drh_or_admin(request
.user
):
683 def _organigramme(self
, obj
):
685 for d
in rh
.Dossier
.objects
.filter(
686 Q(date_fin__gt
=datetime
.date
.today()) |
Q(date_fin
=None),
687 Q(date_debut__lt
=datetime
.date
.today()) |
Q(date_debut
=None),
691 u
'Organigramme, niveau: ' \
692 u
'<input type="text" id="level_%s" ' \
693 u
'style="width:30px;height:15px;" /> ' \
694 u
'<input type="button" value="Générer" ' \
695 u
"""onclick="window.location='%s' + """ \
696 u
"""document.getElementById('level_%s').value" />""" % (
698 reverse('rho_employe_sans_niveau', args
=(d
.poste
.id,)),
701 link
= u
"""<li>%s - [%s] %s : %s</li>""" % (
708 return "<ul>%s</ul>" % "\n".join(l
)
710 _organigramme
.allow_tags
= True
711 _organigramme
.short_description
= "Organigramme"
714 class CategorieEmploiAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
715 list_display
= ('nom', '_date_modification', 'user_modification', )
716 inlines
= (TypePosteInline
,)
717 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
718 (None, {'fields': ('nom', )}),)
720 def _date_modification(self
, obj
):
721 return date(obj
.date_modification
) \
722 if obj
.date_modification
is not None else "(aucune)"
723 _date_modification
.short_description
= u
'date modification'
724 _date_modification
.admin_order_field
= 'date_modification'
727 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
728 search_fields
= ('nom',)
733 '_date_modification',
736 list_filter
= ('type', )
737 inlines
= (DossierROInline
,)
738 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
739 (None, {'fields': ('nom', 'type', 'pays',)}),
742 def _date_modification(self
, obj
):
743 return date(obj
.date_modification
) \
744 if obj
.date_modification
is not None else "(aucune)"
745 _date_modification
.short_description
= u
'date modification'
746 _date_modification
.admin_order_field
= 'date_modification'
749 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
750 ProtectRegionMixin
, BaseAdmin
, AjaxSelect
):
751 form
= make_ajax_form(rh
.Poste
, {
752 'implantation': 'implantations',
753 'type_poste': 'typepostes',
754 'responsable': 'postes',
755 'valeur_point_min': 'valeurpoints',
756 'valeur_point_max': 'valeurpoints',
758 alphabet_filter
= 'nom'
763 'implantation__region__code',
764 'implantation__region__nom',
765 'rh_dossiers__employe__nom',
766 'rh_dossiers__employe__prenom',
778 '_date_modification',
783 'implantation__region',
787 'type_poste__categorie_emploi',
788 'type_poste__famille_professionnelle',
791 list_display_links
= ('_nom',)
792 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
794 ('nom', 'nom_feminin'),
804 'regime_travail_nb_heure_semaine'),
808 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
811 'fields': (('classement_min',
824 ('Comparatifs de rémunération', {
825 'fields': ('devise_comparaison',
826 ('comp_locale_min', 'comp_locale_max'),
827 ('comp_universite_min', 'comp_universite_max'),
828 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
829 ('comp_ong_min', 'comp_ong_max'),
830 ('comp_autre_min', 'comp_autre_max'))}
833 'fields': ('justification',)}
835 ('Autres Méta-données', {
836 'fields': ('date_debut', 'date_fin')}
840 inlines
= (PosteFinancementInline
,
843 PosteComparaisonInline
,
844 PosteCommentaireInline
, )
846 def has_add_permission(self
, request
):
847 user_groups
= request
.user
.groups
.all()
848 if groups
.grp_correspondants_rh
in user_groups
or \
849 groups
.grp_administrateurs
in user_groups
or \
850 groups
.grp_directeurs_bureau
in user_groups
or \
851 in_drh_or_admin(request
.user
):
855 def has_delete_permission(self
, request
, obj
=None):
856 return in_drh_or_admin(request
.user
)
858 def lookup_allowed(self
, key
, value
):
860 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
861 'date_fin__isnull', 'implantation__region__id__exact',
862 'implantation__id__exact', 'type_poste__id__exact',
863 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
864 'service__isnull', 'vacant__exact', 'vacant__isnull',
865 ) or super(PosteAdmin
, self
).lookup_allowed(key
, value
)
867 def _apercu(self
, poste
):
868 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);"
869 title="Aperçu du poste"
871 <img src="%simg/poste-apercu.png" />
873 (reverse('poste_apercu', args
=(poste
.id,)),
874 settings
.STATIC_URL
,)
876 _apercu
.allow_tags
= True
877 _apercu
.short_description
= ''
879 def _dae(self
, poste
):
881 postes_dae
= poste
.postes_dae
.all()
882 if len(postes_dae
) > 0:
883 poste_dae
= postes_dae
[0]
885 u
'<a title="Aperçu du dossier" href="%s" ' \
886 u
'onclick="return showAddAnotherPopup(this);">' \
887 u
'<img src="%simg/loupe.png" /></a>' % (reverse(
888 'poste_consulter', args
=("dae-%s" % poste_dae
.id,)
889 ), settings
.STATIC_URL
)
891 _dae
.allow_tags
= True
892 _dae
.short_description
= u
"DAE"
896 _id
.short_description
= '#'
897 _id
.admin_order_field
= 'id'
899 def _service(self
, obj
):
900 if obj
.service
.supprime
:
901 return """<span style="color:red">%s</span>""" % obj
.service
904 _service
.short_description
= 'Service'
905 _service
.allow_tags
= True
907 def _responsable(self
, obj
):
909 responsable
= u
"""<a href="%s"
910 onclick="return showAddAnotherPopup(this)">
911 <img src="%simg/poste-apercu.png"
912 title="Aperçu du poste" />
916 (reverse('poste_apercu', args
=(obj
.responsable
.id,)),
918 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
924 dossier
= obj
.responsable
.rh_dossiers
.all().order_by('-date_debut')[0]
925 employe_id
= dossier
.employe
.id
926 employe_html
= u
"""<br />
928 onclick="return showAddAnotherPopup(this)">
929 <img src="%simg/employe-apercu.png"
930 title="Aperçu de l'employé">
932 <a href="%s">%s</a>""" % \
933 (reverse('employe_apercu', args
=(employe_id
,)),
935 reverse('admin:rh_employe_change', args
=(employe_id
,)),
940 return "%s %s" % (responsable
, employe_html
)
941 _responsable
.short_description
= 'Responsable'
942 _responsable
.allow_tags
= True
944 def _implantation(self
, poste
):
945 return poste
.implantation
.nom
946 _implantation
.short_description
= 'Implantation'
947 _implantation
.admin_order_field
= 'implantation'
949 def _nom(self
, poste
):
950 return """<a href="%s">%s</a>""" % \
951 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
953 _nom
.allow_tags
= True
954 _nom
.short_description
= u
'Poste'
955 _nom
.admin_order_field
= 'nom'
957 def _date_modification(self
, obj
):
958 return date(obj
.date_modification
)
959 _date_modification
.short_description
= u
'date modification'
960 _date_modification
.admin_order_field
= 'date_modification'
962 def _occupe_par(self
, obj
):
963 """Formatte la méthode Poste.occupe_par() pour l'admin"""
965 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.today():
967 employes
= obj
.occupe_par()
971 link
= u
"""<a href='%s'
972 title='Aperçu de l\'employé'
973 onclick='return showAddAnotherPopup(this)'>
974 <img src='%simg/employe-apercu.png' />
976 <a href='%s'>%s</a>""" % \
977 (reverse('employe_apercu', args
=(e
.id,)),
979 reverse('admin:rh_employe_change', args
=(e
.id,)),
982 output
= "\n<br />".join(l
)
984 _occupe_par
.allow_tags
= True
985 _occupe_par
.short_description
= "Occupé par"
987 def save_formset(self
, request
, form
, formset
, change
):
988 instances
= formset
.save(commit
=False)
989 for instance
in instances
:
990 if instance
.__class__
== rh
.PosteCommentaire
:
991 instance
.owner
= request
.user
992 instance
.date_creation
= datetime
.datetime
.now()
997 class ResponsableInline(admin
.TabularInline
):
998 model
= rh
.ResponsableImplantation
1000 fk_name
= "implantation"
1003 class ResponsableImplantationAdmin(BaseAdmin
):
1005 list_filter
= ('region', 'statut', )
1006 list_display
= ('_region', '_nom', 'statut', '_responsable', )
1007 readonly_fields
= ('nom', )
1009 inlines
= (ResponsableInline
, )
1011 def _region(self
, obj
):
1012 return obj
.region
.code
1013 _region
.short_description
= u
"Région"
1014 _region
.admin_order_field
= 'region__code'
1016 def _nom(self
, obj
):
1018 _nom
.short_description
= u
"Implantation"
1019 _nom
.admin_order_field
= 'nom'
1021 def _responsable(self
, obj
):
1023 employe
= obj
.responsable
.employe
1024 dossiers
= employe
.dossiers_encours()
1025 if len(dossiers
) == 0:
1026 return u
"<span style='color: red;'>%s %s </span>" % (
1027 employe
, u
"sans dossier actif")
1031 if obj
.statut
in (1, 2): # ouverte, ouverture imminente
1032 css
= "style='color: red;'"
1035 return u
"<span %s>Pas de responsable</span>" % css
1036 _responsable
.allow_tags
= True
1037 _responsable
.short_description
= u
"Responsable"
1039 def has_add_permission(self
, request
=None):
1042 def has_change_permission(self
, request
, obj
=None):
1043 return in_drh_or_admin(request
.user
)
1045 def has_delete_permission(self
, request
, obj
=None):
1049 class ServiceAdmin(AUFMetadataAdminMixin
, BaseAdmin
, ArchiveMixin
):
1053 '_date_modification',
1054 'user_modification',
1056 list_filter
= ('archive', )
1057 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1059 'fields': ('nom', 'archive', ),
1063 def _date_modification(self
, obj
):
1064 return date(obj
.date_modification
) \
1065 if obj
.date_modification
is not None else "(aucune)"
1066 _date_modification
.short_description
= u
'date modification'
1067 _date_modification
.admin_order_field
= 'date_modification'
1070 class ServiceProxyAdmin(ServiceAdmin
):
1071 list_display
= ('nom', '_organigramme', '_archive', )
1074 def __init__(self
, *args
, **kwargs
):
1075 super(ServiceProxyAdmin
, self
).__init__(*args
, **kwargs
)
1076 self
.list_display_links
= (None, )
1078 def queryset(self
, request
):
1079 return super(ServiceProxyAdmin
, self
).queryset(request
) \
1080 .annotate(num_postes
=Count('rh_postes')) \
1081 .filter(num_postes__gt
=0)
1083 def has_add_permission(self
, obj
):
1086 def has_change_permission(self
, request
, obj
=None):
1087 user_groups
= request
.user
.groups
.all()
1088 if groups
.grp_correspondants_rh
in user_groups
or \
1089 groups
.grp_administrateurs
in user_groups
or \
1090 groups
.grp_directeurs_bureau
in user_groups
or \
1091 in_drh_or_admin(request
.user
):
1095 def _organigramme(self
, obj
):
1096 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1097 (reverse('rho_service', args
=(obj
.id,)))
1098 _organigramme
.allow_tags
= True
1099 _organigramme
.short_description
= "Organigramme"
1102 class StatutAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1103 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
1104 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1106 'fields': ('code', 'nom', ),
1110 def _date_modification(self
, obj
):
1111 return date(obj
.date_modification
) \
1112 if obj
.date_modification
is not None else "(aucune)"
1113 _date_modification
.short_description
= u
'date modification'
1114 _date_modification
.admin_order_field
= 'date_modification'
1117 class TauxChangeAdmin(BaseAdmin
):
1122 '_date_modification',
1123 'user_modification',
1125 list_filter
= ('devise', )
1126 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1128 'fields': ('taux', 'devise', 'annee', ),
1132 def _date_modification(self
, obj
):
1133 return date(obj
.date_modification
) \
1134 if obj
.date_modification
is not None else "(aucune)"
1135 _date_modification
.short_description
= u
'date modification'
1136 _date_modification
.admin_order_field
= 'date_modification'
1139 class TypeContratAdmin(BaseAdmin
):
1143 '_date_modification',
1144 'user_modification',
1146 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1148 'fields': ('nom', 'nom_long', ),
1152 def _date_modification(self
, obj
):
1153 return date(obj
.date_modification
) \
1154 if obj
.date_modification
is not None else "(aucune)"
1155 _date_modification
.short_description
= u
'date modification'
1156 _date_modification
.admin_order_field
= 'date_modification'
1159 class TypePosteAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1160 search_fields
= ('nom', 'nom_feminin', )
1164 '_date_modification',
1165 'user_modification',
1167 list_filter
= ('categorie_emploi', 'famille_professionnelle')
1168 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1175 'famille_professionnelle',
1180 def _date_modification(self
, obj
):
1181 return date(obj
.date_modification
) \
1182 if obj
.date_modification
is not None else "(aucune)"
1183 _date_modification
.short_description
= u
'date modification'
1184 _date_modification
.admin_order_field
= 'date_modification'
1187 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, BaseAdmin
,
1192 'nature_remuneration',
1194 '_date_modification',
1195 'user_modification',)
1196 list_filter
= ('archive', )
1197 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1198 (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration',
1202 def _date_modification(self
, obj
):
1203 return date(obj
.date_modification
) \
1204 if obj
.date_modification
is not None else "(aucune)"
1205 _date_modification
.short_description
= u
'date modification'
1206 _date_modification
.admin_order_field
= 'date_modification'
1209 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1210 list_display
= ('nom', '_date_modification', 'user_modification', )
1211 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1212 (None, {'fields': ('nom', )}),
1215 def _date_modification(self
, obj
):
1216 return date(obj
.date_modification
) \
1217 if obj
.date_modification
is not None else "(aucune)"
1218 _date_modification
.short_description
= u
'date modification'
1219 _date_modification
.admin_order_field
= 'date_modification'
1222 class ValeurPointAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1229 '_date_modification',
1230 'user_modification',
1232 list_filter
= ('annee', 'devise', 'implantation__region', )
1233 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1234 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}),
1237 def _date_modification(self
, obj
):
1238 return date(obj
.date_modification
) \
1239 if obj
.date_modification
is not None else "(aucune)"
1240 _date_modification
.short_description
= u
'date modification'
1241 _date_modification
.admin_order_field
= 'date_modification'
1243 def _devise_code(self
, obj
):
1244 return obj
.devise
.code
1245 _devise_code
.short_description
= "Code de la devise"
1247 def _devise_nom(self
, obj
):
1248 return obj
.devise
.nom
1249 _devise_nom
.short_description
= "Nom de la devise"
1252 class ImplantationProxyAdmin(BaseAdmin
):
1253 list_display
= ('nom', '_organigramme')
1256 def __init__(self
, *args
, **kwargs
):
1257 super(ImplantationProxyAdmin
, self
).__init__(*args
, **kwargs
)
1258 self
.list_display_links
= (None, )
1260 def has_add_permission(self
, obj
):
1263 def has_change_permission(self
, request
, obj
=None):
1264 user_groups
= request
.user
.groups
.all()
1265 if groups
.grp_correspondants_rh
in user_groups
or \
1266 groups
.grp_administrateurs
in user_groups
or \
1267 groups
.grp_directeurs_bureau
in user_groups
or \
1268 in_drh_or_admin(request
.user
):
1272 def _organigramme(self
, obj
):
1273 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1274 reverse('rho_implantation', args
=(obj
.id,))
1276 _organigramme
.allow_tags
= True
1277 _organigramme
.short_description
= "Organigramme"
1280 class RegionProxyAdmin(BaseAdmin
):
1281 list_display
= ('nom', '_organigramme')
1284 def __init__(self
, *args
, **kwargs
):
1285 super(RegionProxyAdmin
, self
).__init__(*args
, **kwargs
)
1286 self
.list_display_links
= (None, )
1288 def has_add_permission(self
, obj
):
1291 def has_change_permission(self
, request
, obj
=None):
1292 user_groups
= request
.user
.groups
.all()
1293 if groups
.grp_correspondants_rh
in user_groups
or \
1294 groups
.grp_administrateurs
in user_groups
or \
1295 groups
.grp_directeurs_bureau
in user_groups
or \
1296 in_drh_or_admin(request
.user
):
1300 def _organigramme(self
, obj
):
1301 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1302 reverse('rho_region', args
=(obj
.id,))
1304 _organigramme
.allow_tags
= True
1305 _organigramme
.short_description
= "Organigramme"
1308 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
1309 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
1310 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
1311 admin
.site
.register(EmployeProxy
, EmployeProxyAdmin
)
1312 admin
.site
.register(ServiceProxy
, ServiceProxyAdmin
)
1313 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
1314 admin
.site
.register(rh
.CategorieEmploi
, CategorieEmploiAdmin
)
1315 admin
.site
.register(rh
.FamilleProfessionnelle
)
1316 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
1317 admin
.site
.register(rh
.Poste
, PosteAdmin
)
1318 admin
.site
.register(
1319 rh
.ResponsableImplantationProxy
, ResponsableImplantationAdmin
1321 admin
.site
.register(rh
.Service
, ServiceAdmin
)
1322 admin
.site
.register(rh
.Statut
, StatutAdmin
)
1323 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
1324 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
1325 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
1326 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
1327 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
1328 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)
1329 admin
.site
.register(ImplantationProxy
, ImplantationProxyAdmin
)
1330 admin
.site
.register(RegionProxy
, RegionProxyAdmin
)