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
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 project
.rh
import groups
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 """
48 verbose_name
= u
"Organigramme par région"
49 verbose_name_plural
= u
"Organigramme par région"
52 class ImplantationProxy(ref
.Implantation
):
53 """ Proxy utilisé pour les organigrammes par implantation """
57 verbose_name
= u
"Organigramme par implantations"
58 verbose_name_plural
= u
"Organigramme par implantations"
61 class ServiceProxy(rh
.Service
):
62 """ Proxy utilisé pour les organigrammes opar service """
66 verbose_name
= u
"Organigramme par services"
67 verbose_name_plural
= u
"Organigramme par services"
70 class EmployeProxy(rh
.Employe
):
71 """ Proxy utilisé pour les organigrammes des employés """
75 verbose_name
= u
"Organigramme des employés"
76 verbose_name_plural
= u
"Organigramme des employés"
79 class DateRangeMixin(object):
80 prefixe_recherche_temporelle
= ""
82 def get_changelist(self
, request
, **kwargs
):
83 if 'HTTP_REFERER' in request
.META
.keys():
84 referer
= request
.META
['HTTP_REFERER']
85 referer
= "/".join(referer
.split('/')[3:])
86 referer
= "/%s" % referer
.split('?')[0]
87 change_list_view
= 'admin:%s_%s_changelist' % (
88 self
.model
._meta
.app_label
,
89 self
.model
.__name__
.lower(),)
90 if referer
!= reverse(change_list_view
):
91 params
= request
.GET
.copy()
92 params
.update({'statut': 'Actif'})
97 # Override of the InlineModelAdmin to support the link in the tabular inline
98 class LinkedInline(admin
.options
.InlineModelAdmin
):
99 template
= "admin/linked.html"
100 admin_model_path
= None
102 def __init__(self
, *args
):
103 super(LinkedInline
, self
).__init__(*args
)
104 if self
.admin_model_path
is None:
105 self
.admin_model_path
= self
.model
.__name__
.lower()
108 class ProtectRegionMixin(object):
110 def queryset(self
, request
):
111 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
113 user_groups
= request
.user
.groups
.all()
114 if in_drh_or_admin(request
.user
):
117 if groups
.grp_correspondants_rh
in user_groups
or\
118 groups
.grp_administrateurs
in user_groups
or\
119 groups
.grp_directeurs_bureau
in user_groups
:
120 employe
= get_employe_from_user(request
.user
)
121 q
= Q(**{self
.model
.prefix_implantation
: \
122 employe
.implantation
.region
})
123 qs
= qs
.filter(q
).distinct()
127 def has_add_permission(self
, request
):
128 if not in_drh_or_admin(request
.user
):
133 def has_change_permission(self
, request
, obj
=None):
134 user_groups
= request
.user
.groups
.all()
136 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
141 ids
= [o
.id for o
in self
.queryset(request
)]
147 class ReadOnlyInlineMixin(object):
149 def get_readonly_fields(self
, request
, obj
=None):
150 return [f
.name
for f
in self
.model
._meta
.fields \
151 if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
154 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
155 model
= rh
.AyantDroit
156 form
= AyantDroitForm
163 ('nom_affichage', 'genre'),
171 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, \
172 admin
.TabularInline
):
173 readonly_fields
= ('owner', )
174 model
= rh
.AyantDroitCommentaire
178 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
184 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
185 template
= "admin/rh/dossier/linked.html"
186 exclude
= AUF_METADATA_READONLY_FIELDS
191 def has_add_permission(self
, request
=None):
194 def has_change_permission(self
, request
, obj
=None):
197 def has_delete_permission(self
, request
, obj
=None):
201 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, \
202 admin
.TabularInline
):
203 readonly_fields
= ('owner', )
204 model
= rh
.DossierCommentaire
208 class DossierPieceInline(admin
.TabularInline
):
209 model
= rh
.DossierPiece
213 class EmployeInline(admin
.TabularInline
):
217 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, \
218 admin
.TabularInline
):
219 readonly_fields
= ('owner', )
220 model
= rh
.EmployeCommentaire
224 class EmployePieceInline(admin
.TabularInline
):
225 model
= rh
.EmployePiece
229 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
230 readonly_fields
= ('owner', )
231 model
= rh
.PosteCommentaire
235 class PosteFinancementInline(admin
.TabularInline
):
236 model
= rh
.PosteFinancement
239 class PostePieceInline(admin
.TabularInline
):
240 model
= rh
.PostePiece
243 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
244 model
= rh
.Remuneration
248 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
252 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
256 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
257 model
= rh
.PosteComparaison
260 class ClassementAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
261 list_display
= ('_classement', '_date_modification', 'user_modification', )
262 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
264 'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
267 def _classement(self
, obj
):
269 _classement
.short_description
= u
"Classement"
271 def _date_modification(self
, obj
):
272 return date(obj
.date_modification
) \
273 if obj
.date_modification
is not None else "(aucune)"
274 _date_modification
.short_description
= u
'date modification'
275 _date_modification
.admin_order_field
= 'date_modification'
278 class CommentaireAdmin(admin
.ModelAdmin
):
282 class DeviseAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
287 '_date_modification',
290 list_filter
= ('archive', )
291 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
293 'fields': ('code', 'nom', 'archive', ),
297 def _date_modification(self
, obj
):
298 return date(obj
.date_modification
) \
299 if obj
.date_modification
is not None else "(aucune)"
300 _date_modification
.short_description
= u
'date modification'
301 _date_modification
.admin_order_field
= 'date_modification'
304 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
305 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
306 alphabet_filter
= 'employe__nom'
311 'poste__nom_feminin')
320 '_date_modification',
324 list_display_links
= ('_nom',)
326 'poste__implantation__region',
327 'poste__implantation',
328 'poste__type_poste__categorie_emploi',
330 'rh_contrats__type_contrat',
333 inlines
= (DossierPieceInline
, ContratInline
,
335 DossierCommentaireInline
,
337 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
344 'organisme_bstg',)}),
349 'remplacement_de', )}),
353 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
354 ('Occupation du Poste par cet Employe', {
355 'fields': (('date_debut', 'date_fin'), )}
358 form
= make_ajax_form(rh
.Dossier
, {
359 'employe': 'employes',
361 'remplacement_de': 'dossiers',
362 }, superclass
=DossierForm
)
364 def has_add_permission(self
, request
):
365 user_groups
= request
.user
.groups
.all()
366 if groups
.grp_correspondants_rh
in user_groups
or \
367 groups
.grp_administrateurs
in user_groups
or \
368 groups
.grp_directeurs_bureau
in user_groups
or \
369 in_drh_or_admin(request
.user
):
373 def has_delete_permission(self
, request
, obj
=None):
374 return in_drh_or_admin(request
.user
)
376 def lookup_allowed(self
, key
, value
):
378 'employe__nom__istartswith',
379 'poste__implantation__region__id__exact',
380 'poste__implantation__id__exact',
381 'poste__type_poste__id__exact',
382 'poste__type_poste__categorie_emploi__id__exact',
383 'rh_contrats__type_contrat__id__exact',
391 _id
.short_description
= u
"#"
392 _id
.admin_order_field
= "id"
395 return "%d : %s %s" % (
397 obj
.employe
.nom
.upper(),
399 _nom
.allow_tags
= True
400 _nom
.short_description
= u
"Dossier"
402 def _apercu(self
, d
):
403 apercu_link
= u
"""<a title="Aperçu du dossier"
404 onclick="return showAddAnotherPopup(this);"
406 <img src="%simg/loupe.png" />
408 (reverse('dossier_apercu', args
=(d
.id,)),
412 _apercu
.allow_tags
= True
413 _apercu
.short_description
= u
""
417 dossiers_dae
= d
.dossiers_dae
.all()
418 if len(dossiers_dae
) > 0:
419 dossier_dae
= dossiers_dae
[0]
420 apercu_link
= u
"""<a title="Aperçu du dossier"
421 onclick="return showAddAnotherPopup(this);"
423 <img src="%simg/loupe.png" />
425 (reverse('embauche_consulter', args
=(dossier_dae
.id,)),
429 _dae
.allow_tags
= True
430 _dae
.short_description
= u
"DAE"
432 def _date_debut(self
, obj
):
433 return date(obj
.date_debut
)
435 _date_debut
.short_description
= u
'Occupation début'
436 _date_debut
.admin_order_field
= 'date_debut'
438 def _date_fin(self
, obj
):
439 return date(obj
.date_fin
)
440 _date_fin
.short_description
= u
'Occupation fin'
441 _date_fin
.admin_order_field
= 'date_fin'
443 def _date_modification(self
, obj
):
444 return date(obj
.date_modification
) \
445 if obj
.date_modification
is not None else "(aucune)"
446 _date_modification
.short_description
= u
'date modification'
447 _date_modification
.admin_order_field
= 'date_modification'
449 def _poste(self
, dossier
):
450 link
= u
"""<a title="Aperçu du poste"
451 onclick="return showAddAnotherPopup(this);"
452 href='%s'><img src="%simg/loupe.png" />
454 <a href="%s" title="Modifier le poste">%s</a>""" % \
455 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
457 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
461 _poste
.allow_tags
= True
462 _poste
.short_description
= u
'Poste'
463 _poste
.admin_order_field
= 'poste__nom'
465 def _employe(self
, obj
):
466 employe
= obj
.employe
467 view_link
= reverse('employe_apercu', args
=(employe
.id,))
468 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
471 view
= u
"""<a href="%s"
472 title="Aperçu l'employé"
473 onclick="return showAddAnotherPopup(this);">
474 <img src="%simg/loupe.png" />
475 </a>""" % (view_link
, settings
.STATIC_URL
,)
476 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
477 (view
, edit_link
, style
, employe
)
478 _employe
.allow_tags
= True
479 _employe
.short_description
= u
"Employé"
480 _employe
.admin_order_field
= "employe__nom"
482 def save_formset(self
, request
, form
, formset
, change
):
483 instances
= formset
.save(commit
=False)
484 for instance
in instances
:
485 if instance
.__class__
== rh
.DossierCommentaire
:
486 instance
.owner
= request
.user
487 instance
.date_creation
= datetime
.datetime
.now()
491 class DossierPieceAdmin(admin
.ModelAdmin
):
495 class DossierCommentaireAdmin(admin
.ModelAdmin
):
499 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
500 ProtectRegionMixin
, admin
.ModelAdmin
,):
501 prefixe_recherche_temporelle
= "rh_dossiers__"
502 alphabet_filter
= 'nom'
503 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
504 search_fields
= ('id', 'nom', 'prenom', 'nom_affichage', )
506 form
= EmployeAdminForm
512 '_date_modification',
515 list_display_links
= ('_nom',)
517 'rh_dossiers__poste__implantation__region',
518 'rh_dossiers__poste__implantation',
521 inlines
= (AyantDroitInline
,
524 EmployeCommentaireInline
)
525 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
529 ('nom_affichage', 'genre'),
534 ('Informations personnelles', {
535 'fields': ('situation_famille', 'date_entree', )}
539 ('tel_domicile', 'tel_cellulaire'),
540 ('adresse', 'ville'),
541 ('code_postal', 'province'),
547 def has_add_permission(self
, request
):
548 user_groups
= request
.user
.groups
.all()
549 if groups
.grp_correspondants_rh
in user_groups
or \
550 groups
.grp_administrateurs
in user_groups
or \
551 groups
.grp_directeurs_bureau
in user_groups
or \
552 in_drh_or_admin(request
.user
):
556 def has_delete_permission(self
, request
, obj
=None):
557 return in_drh_or_admin(request
.user
)
559 def _apercu(self
, obj
):
560 return u
"""<a title="Aperçu de l'employé"
561 onclick="return showAddAnotherPopup(this);"
563 <img src="%simg/loupe.png" />
565 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
566 _apercu
.allow_tags
= True
567 _apercu
.short_description
= u
""
570 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
571 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
572 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
573 _nom
.allow_tags
= True
574 _nom
.short_description
= u
"Employé"
575 _nom
.admin_order_field
= "nom"
579 _id
.short_description
= u
"#"
580 _id
.admin_order_field
= "id"
582 def _date_modification(self
, obj
):
583 return date(obj
.date_modification
) \
584 if obj
.date_modification
is not None else "(aucune)"
585 _date_modification
.short_description
= u
'date modification'
586 _date_modification
.admin_order_field
= 'date_modification'
588 def _dossiers_postes(self
, obj
):
590 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
591 dossier
= u
"""<a title="Aperçu du dossier"
593 onclick="return showAddAnotherPopup(this);"
594 title="Aperçu du dossier">
595 <img src="%simg/loupe.png" />
597 <a href="%s">Dossier</a>
599 (reverse('dossier_apercu', args
=(d
.id,)),
601 reverse('admin:rh_dossier_change', args
=(d
.id,)))
603 poste
= u
"""<a title="Aperçu du poste"
605 onclick="return showAddAnotherPopup(this);"
606 title="Aperçu du poste">
607 <img src="%simg/loupe.png" />
609 <a href="%s">Poste</a>
611 (reverse('poste_apercu', args
=(d
.poste
.id,)),
613 reverse('admin:rh_poste_change', args
=(d
.poste
.id,)))
614 link
= u
"""<li>%s %s - %s : [%s] %s</li>""" % \
621 # Dossier terminé en gris non cliquable
622 if d
.date_fin
is not None and d
.date_fin
< datetime
.date
.today():
623 link
= u
"""<li style="color: grey">%s : [%s] %s</li>""" % \
630 return "<ul>%s</ul>" % "\n".join(l
)
631 _dossiers_postes
.allow_tags
= True
632 _dossiers_postes
.short_description
= u
"Dossiers et postes"
634 def queryset(self
, request
):
635 qs
= super(EmployeAdmin
, self
).queryset(request
)
636 return qs
.select_related(depth
=1).order_by('nom')
638 def save_formset(self
, request
, form
, formset
, change
):
639 instances
= formset
.save(commit
=False)
640 for instance
in instances
:
641 if instance
.__class__
== rh
.EmployeCommentaire
:
642 instance
.owner
= request
.user
643 instance
.date_creation
= datetime
.datetime
.now()
647 class EmployeProxyAdmin(EmployeAdmin
):
648 list_display
= ('_id', '_apercu', '_nom', '_organigramme')
651 def __init__(self
, *args
, **kwargs
):
652 super(EmployeProxyAdmin
, self
).__init__(*args
, **kwargs
)
653 self
.list_display_links
= (None, )
655 def has_add_permission(self
, obj
):
658 def _organigramme(self
, obj
):
660 for d
in rh
.Dossier
.objects
.filter(
661 Q(date_fin__gt
=datetime
.date
.today()) |
Q(date_fin
=None),
662 Q(date_debut__lt
=datetime
.date
.today()) |
Q(date_debut
=None),
666 u
'Organigramme, niveau: ' \
667 u
'<input type="text" id="level_%s" ' \
668 u
'style="width:30px;height:15px;" /> ' \
669 u
'<input type="button" value="Générer" ' \
670 u
"""onclick="window.location='%s' + """ \
671 u
"""document.getElementById('level_%s').value" />""" % (
673 reverse('rho_employe_sans_niveau', args
=(d
.poste
.id,)),
676 link
= u
"""<li>%s - [%s] %s : %s</li>""" % (
683 return "<ul>%s</ul>" % "\n".join(l
)
685 _organigramme
.allow_tags
= True
686 _organigramme
.short_description
= "Organigramme"
689 class EmployeCommentaireAdmin(admin
.ModelAdmin
):
693 class EmployePieceAdmin(admin
.ModelAdmin
):
697 class CategorieEmploiAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
698 list_display
= ('nom', '_date_modification', 'user_modification', )
699 inlines
= (TypePosteInline
,)
700 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
701 (None, {'fields': ('nom', )}),)
703 def _date_modification(self
, obj
):
704 return date(obj
.date_modification
) \
705 if obj
.date_modification
is not None else "(aucune)"
706 _date_modification
.short_description
= u
'date modification'
707 _date_modification
.admin_order_field
= 'date_modification'
710 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
711 search_fields
= ('nom',)
716 '_date_modification',
719 list_filter
= ('type', )
720 inlines
= (DossierROInline
,)
721 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
722 (None, {'fields': ('nom', 'type', 'pays',)}),
725 def _date_modification(self
, obj
):
726 return date(obj
.date_modification
) \
727 if obj
.date_modification
is not None else "(aucune)"
728 _date_modification
.short_description
= u
'date modification'
729 _date_modification
.admin_order_field
= 'date_modification'
732 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
733 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
734 form
= make_ajax_form(rh
.Poste
, {
735 'implantation': 'implantations',
736 'type_poste': 'typepostes',
737 'responsable': 'postes',
738 'valeur_point_min': 'valeurpoints',
739 'valeur_point_max': 'valeurpoints',
741 alphabet_filter
= 'nom'
746 'implantation__region__code',
747 'implantation__region__nom',
748 'rh_dossiers__employe__nom',
749 'rh_dossiers__employe__prenom',
761 '_date_modification',
766 'implantation__region',
770 'type_poste__categorie_emploi',
771 'type_poste__famille_professionnelle',
774 list_display_links
= ('_nom',)
775 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
777 ('nom', 'nom_feminin'),
787 'regime_travail_nb_heure_semaine'),
791 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
794 'fields': (('classement_min',
807 ('Comparatifs de rémunération', {
808 'fields': ('devise_comparaison',
809 ('comp_locale_min', 'comp_locale_max'),
810 ('comp_universite_min', 'comp_universite_max'),
811 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
812 ('comp_ong_min', 'comp_ong_max'),
813 ('comp_autre_min', 'comp_autre_max'))}
816 'fields': ('justification',)}
818 ('Autres Méta-données', {
819 'fields': ('date_debut', 'date_fin')}
823 inlines
= (PosteFinancementInline
,
826 PosteComparaisonInline
,
827 PosteCommentaireInline
, )
829 def has_add_permission(self
, request
):
830 user_groups
= request
.user
.groups
.all()
831 if groups
.grp_correspondants_rh
in user_groups
or \
832 groups
.grp_administrateurs
in user_groups
or \
833 groups
.grp_directeurs_bureau
in user_groups
or \
834 in_drh_or_admin(request
.user
):
838 def has_delete_permission(self
, request
, obj
=None):
839 return in_drh_or_admin(request
.user
)
841 def lookup_allowed(self
, key
, value
):
843 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
844 'date_fin__isnull', 'implantation__region__id__exact',
845 'implantation__id__exact', 'type_poste__id__exact',
846 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
847 'service__isnull', 'vacant__exact', 'vacant__isnull',
848 ) or super(PosteAdmin
, self
).lookup_allowed(key
, value
)
850 def _apercu(self
, poste
):
851 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);"
852 title="Aperçu du poste"
854 <img src="%simg/loupe.png" />
856 (reverse('poste_apercu', args
=(poste
.id,)),
857 settings
.STATIC_URL
,)
859 _apercu
.allow_tags
= True
860 _apercu
.short_description
= ''
862 def _dae(self
, poste
):
864 postes_dae
= poste
.postes_dae
.all()
865 if len(postes_dae
) > 0:
866 poste_dae
= postes_dae
[0]
868 u
'<a title="Aperçu du dossier" href="%s" ' \
869 u
'onclick="return showAddAnotherPopup(this);">' \
870 u
'<img src="%simg/loupe.png" /></a>' % (reverse(
871 'poste_consulter', args
=("dae-%s" % poste_dae
.id,)
872 ), settings
.STATIC_URL
)
874 _dae
.allow_tags
= True
875 _dae
.short_description
= u
"DAE"
879 _id
.short_description
= '#'
880 _id
.admin_order_field
= 'id'
882 def _service(self
, obj
):
883 if obj
.service
.supprime
:
884 return """<span style="color:red">%s</span>""" % obj
.service
887 _service
.short_description
= 'Service'
888 _service
.allow_tags
= True
890 def _responsable(self
, obj
):
892 responsable
= u
"""<a href="%s"
893 onclick="return showAddAnotherPopup(this)">
894 <img src="%simg/loupe.png"
895 title="Aperçu du poste" />
899 (reverse('poste_apercu', args
=(obj
.responsable
.id,)),
901 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
907 employe
= obj
.responsable
.rh_dossiers
.all()[0]
908 employe_id
= obj
.responsable
.rh_dossiers
.all()[0].id
909 employe_html
= u
"""<br />
911 onclick="return showAddAnotherPopup(this)">
912 <img src="%simg/loupe.png"
913 title="Aperçu de l'employé">
915 <a href="%s">%s</a>""" % \
916 (reverse('employe_apercu', args
=(employe_id
,)),
918 reverse('admin:rh_employe_change', args
=(employe_id
,)),
923 return "%s %s" % (responsable
, employe_html
)
924 _responsable
.short_description
= 'Responsable'
925 _responsable
.allow_tags
= True
927 def _nom(self
, poste
):
928 return """<a href="%s">%s</a>""" % \
929 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
931 _nom
.allow_tags
= True
932 _nom
.short_description
= u
'Nom'
933 _nom
.admin_order_field
= 'nom'
935 def _date_modification(self
, obj
):
936 return date(obj
.date_modification
)
937 _date_modification
.short_description
= u
'date modification'
938 _date_modification
.admin_order_field
= 'date_modification'
940 def _occupe_par(self
, obj
):
941 """Formatte la méthode Poste.occupe_par() pour l'admin"""
943 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.today():
945 employes
= obj
.occupe_par()
949 link
= u
"""<a href='%s'
950 title='Aperçu de l\'employer'
951 onclick='return showAddAnotherPopup(this)'>
952 <img src='%simg/loupe.png' />
954 <a href='%s'>%s</a>""" % \
955 (reverse('employe_apercu', args
=(e
.id,)),
957 reverse('admin:rh_employe_change', args
=(e
.id,)),
960 output
= "\n<br />".join(l
)
962 _occupe_par
.allow_tags
= True
963 _occupe_par
.short_description
= "Occupé par"
965 def save_formset(self
, request
, form
, formset
, change
):
966 instances
= formset
.save(commit
=False)
967 for instance
in instances
:
968 if instance
.__class__
== rh
.PosteCommentaire
:
969 instance
.owner
= request
.user
970 instance
.date_creation
= datetime
.datetime
.now()
975 class PosteCommentaireAdmin(admin
.ModelAdmin
):
979 class PosteFinancementAdmin(admin
.ModelAdmin
):
983 class PostePieceAdmin(admin
.ModelAdmin
):
987 class RemunerationAdmin(admin
.ModelAdmin
):
991 class ResponsableInline(admin
.TabularInline
):
992 model
= rh
.ResponsableImplantation
994 fk_name
= "implantation"
997 class ResponsableImplantationAdmin(admin
.ModelAdmin
):
999 list_filter
= ('region', 'statut', )
1000 list_display
= ('nom', 'statut', '_responsable', )
1001 readonly_fields
= ('nom', )
1003 inlines
= (ResponsableInline
, )
1005 def _responsable(self
, obj
):
1007 employe
= obj
.responsable
.employe
1008 dossiers
= employe
.dossiers_encours()
1009 if len(dossiers
) == 0:
1010 return u
"<span style='color: red;'>%s %s </span>" % (
1011 employe
, u
"sans dossier actif")
1015 if obj
.statut
in (1, 2): # ouverte, ouverture imminente
1016 css
= "style='color: red;'"
1019 return u
"<span %s>Pas de responsable</span>" % css
1020 _responsable
.allow_tags
= True
1021 _responsable
.short_description
= u
"Responsable"
1023 def has_add_permission(self
, request
=None):
1026 def has_change_permission(self
, request
, obj
=None):
1027 return in_drh_or_admin(request
.user
)
1029 def has_delete_permission(self
, request
, obj
=None):
1033 class ServiceAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
1037 '_date_modification',
1038 'user_modification',
1040 list_filter
= ('archive', )
1041 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1043 'fields': ('nom', 'archive', ),
1047 def _date_modification(self
, obj
):
1048 return date(obj
.date_modification
) \
1049 if obj
.date_modification
is not None else "(aucune)"
1050 _date_modification
.short_description
= u
'date modification'
1051 _date_modification
.admin_order_field
= 'date_modification'
1054 class ServiceProxyAdmin(ServiceAdmin
):
1055 list_display
= ('nom', '_organigramme', '_archive', )
1058 def __init__(self
, *args
, **kwargs
):
1059 super(ServiceProxyAdmin
, self
).__init__(*args
, **kwargs
)
1060 self
.list_display_links
= (None, )
1062 def has_add_permission(self
, obj
):
1065 def has_change_permission(self
, request
, obj
=None):
1066 return in_drh_or_admin(request
.user
)
1068 def _organigramme(self
, obj
):
1069 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1070 (reverse('rho_service', args
=(obj
.id,)))
1071 _organigramme
.allow_tags
= True
1072 _organigramme
.short_description
= "Organigramme"
1075 class StatutAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1076 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
1077 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1079 'fields': ('code', 'nom', ),
1083 def _date_modification(self
, obj
):
1084 return date(obj
.date_modification
) \
1085 if obj
.date_modification
is not None else "(aucune)"
1086 _date_modification
.short_description
= u
'date modification'
1087 _date_modification
.admin_order_field
= 'date_modification'
1090 class TauxChangeAdmin(admin
.ModelAdmin
):
1095 '_date_modification',
1096 'user_modification',
1098 list_filter
= ('devise', )
1099 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1101 'fields': ('taux', 'devise', 'annee', ),
1105 def _date_modification(self
, obj
):
1106 return date(obj
.date_modification
) \
1107 if obj
.date_modification
is not None else "(aucune)"
1108 _date_modification
.short_description
= u
'date modification'
1109 _date_modification
.admin_order_field
= 'date_modification'
1112 class TypeContratAdmin(admin
.ModelAdmin
):
1116 '_date_modification',
1117 'user_modification',
1119 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1121 'fields': ('nom', 'nom_long', ),
1125 def _date_modification(self
, obj
):
1126 return date(obj
.date_modification
) \
1127 if obj
.date_modification
is not None else "(aucune)"
1128 _date_modification
.short_description
= u
'date modification'
1129 _date_modification
.admin_order_field
= 'date_modification'
1132 class TypePosteAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1133 search_fields
= ('nom', 'nom_feminin', )
1137 '_date_modification',
1138 'user_modification',
1140 list_filter
= ('categorie_emploi', 'famille_professionnelle')
1141 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1148 'famille_professionnelle',
1153 def _date_modification(self
, obj
):
1154 return date(obj
.date_modification
) \
1155 if obj
.date_modification
is not None else "(aucune)"
1156 _date_modification
.short_description
= u
'date modification'
1157 _date_modification
.admin_order_field
= 'date_modification'
1160 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
,
1165 'nature_remuneration',
1167 '_date_modification',
1168 'user_modification',)
1169 list_filter
= ('archive', )
1170 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1171 (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration',
1175 def _date_modification(self
, obj
):
1176 return date(obj
.date_modification
) \
1177 if obj
.date_modification
is not None else "(aucune)"
1178 _date_modification
.short_description
= u
'date modification'
1179 _date_modification
.admin_order_field
= 'date_modification'
1182 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1183 list_display
= ('nom', '_date_modification', 'user_modification', )
1184 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1185 (None, {'fields': ('nom', )}),
1188 def _date_modification(self
, obj
):
1189 return date(obj
.date_modification
) \
1190 if obj
.date_modification
is not None else "(aucune)"
1191 _date_modification
.short_description
= u
'date modification'
1192 _date_modification
.admin_order_field
= 'date_modification'
1195 class ValeurPointAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1202 '_date_modification',
1203 'user_modification',
1205 list_filter
= ('annee', 'devise', 'implantation__region', )
1206 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1207 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}),
1210 def _date_modification(self
, obj
):
1211 return date(obj
.date_modification
) \
1212 if obj
.date_modification
is not None else "(aucune)"
1213 _date_modification
.short_description
= u
'date modification'
1214 _date_modification
.admin_order_field
= 'date_modification'
1216 def _devise_code(self
, obj
):
1217 return obj
.devise
.code
1218 _devise_code
.short_description
= "Code de la devise"
1220 def _devise_nom(self
, obj
):
1221 return obj
.devise
.nom
1222 _devise_nom
.short_description
= "Nom de la devise"
1225 class ImplantationProxyAdmin(admin
.ModelAdmin
):
1226 list_display
= ('nom', '_organigramme')
1229 def __init__(self
, *args
, **kwargs
):
1230 super(ImplantationProxyAdmin
, self
).__init__(*args
, **kwargs
)
1231 self
.list_display_links
= (None, )
1233 def has_add_permission(self
, obj
):
1236 def has_change_permission(self
, request
, obj
=None):
1237 return in_drh_or_admin(request
.user
)
1239 def _organigramme(self
, obj
):
1240 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1241 reverse('rho_implantation', args
=(obj
.id,))
1243 _organigramme
.allow_tags
= True
1244 _organigramme
.short_description
= "Organigramme"
1247 class RegionProxyAdmin(admin
.ModelAdmin
):
1248 list_display
= ('nom', '_organigramme')
1251 def __init__(self
, *args
, **kwargs
):
1252 super(RegionProxyAdmin
, self
).__init__(*args
, **kwargs
)
1253 self
.list_display_links
= (None, )
1255 def has_add_permission(self
, obj
):
1258 def has_change_permission(self
, request
, obj
=None):
1259 return in_drh_or_admin(request
.user
)
1261 def _organigramme(self
, obj
):
1262 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1263 reverse('rho_region', args
=(obj
.id,))
1265 _organigramme
.allow_tags
= True
1266 _organigramme
.short_description
= "Organigramme"
1269 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
1270 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
1271 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
1272 admin
.site
.register(EmployeProxy
, EmployeProxyAdmin
)
1273 admin
.site
.register(ServiceProxy
, ServiceProxyAdmin
)
1274 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
1275 admin
.site
.register(rh
.CategorieEmploi
, CategorieEmploiAdmin
)
1276 admin
.site
.register(rh
.FamilleProfessionnelle
)
1277 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
1278 admin
.site
.register(rh
.Poste
, PosteAdmin
)
1279 admin
.site
.register(
1280 rh
.ResponsableImplantationProxy
, ResponsableImplantationAdmin
1282 admin
.site
.register(rh
.Service
, ServiceAdmin
)
1283 admin
.site
.register(rh
.Statut
, StatutAdmin
)
1284 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
1285 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
1286 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
1287 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
1288 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
1289 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)
1290 admin
.site
.register(ImplantationProxy
, ImplantationProxyAdmin
)
1291 admin
.site
.register(RegionProxy
, RegionProxyAdmin
)