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
9 from django
.template
.defaultfilters
import date
10 from ajax_select
import make_ajax_form
11 from auf
.django
.metadata
.admin
import AUFMetadataAdminMixin
, \
12 AUFMetadataInlineAdminMixin
, \
13 AUF_METADATA_READONLY_FIELDS
14 from forms
import ContratForm
, AyantDroitForm
, EmployeAdminForm
, AjaxSelect
, \
16 from dae
import models
as dae
17 from dae
.utils
import get_employe_from_user
18 from change_list
import ChangeList
19 from groups
import grp_correspondants_rh
20 from decorators
import in_drh_or_admin
22 import auf
.django
.references
.models
as ref
24 class ArchiveMixin(object):
26 Archive Mixin pour gérer le queryset et le display
27 NON COMPRIS : list_filter, et list_display, field à setter dans la classe.
30 def queryset(self
, request
):
31 return self
.model
._base_manager
33 def _archive(self
, obj
):
38 _archive
.short_description
= u
'Archivé'
39 _archive
.admin_order_field
= 'archive'
41 class RegionProxy(ref
.Region
):
42 """ Proxy utilisé pour les organigrammes par région """
45 verbose_name
= u
"Organigramme par région"
46 verbose_name_plural
= u
"Organigramme par région"
49 class ImplantationProxy(ref
.Implantation
):
50 """ Proxy utilisé pour les organigrammes par implantation """
53 verbose_name
= u
"Organigramme par implantations"
54 verbose_name_plural
= u
"Organigramme par implantations"
57 class ServiceProxy(rh
.Service
):
58 """ Proxy utilisé pour les organigrammes opar service """
61 verbose_name
= u
"Organigramme par services"
62 verbose_name_plural
= u
"Organigramme par services"
65 class EmployeProxy(rh
.Employe
):
66 """ Proxy utilisé pour les organigrammes des employés """
69 verbose_name
= u
"Organigramme des employés"
70 verbose_name_plural
= u
"Organigramme des employés"
73 class DateRangeMixin(object):
74 prefixe_recherche_temporelle
= ""
76 def get_changelist(self
, request
, **kwargs
):
77 if 'HTTP_REFERER' in request
.META
.keys():
78 referer
= request
.META
['HTTP_REFERER']
79 referer
= "/".join(referer
.split('/')[3:])
80 referer
= "/%s" % referer
.split('?')[0]
81 change_list_view
= 'admin:%s_%s_changelist' % (
82 self
.model
._meta
.app_label
,
83 self
.model
.__name__
.lower(),)
84 if referer
!= reverse(change_list_view
):
85 params
= request
.GET
.copy()
86 params
.update({'statut': 'Actif'})
91 # Override of the InlineModelAdmin to support the link in the tabular inline
92 class LinkedInline(admin
.options
.InlineModelAdmin
):
93 template
= "admin/linked.html"
94 admin_model_path
= None
96 def __init__(self
, *args
):
97 super(LinkedInline
, self
).__init__(*args
)
98 if self
.admin_model_path
is None:
99 self
.admin_model_path
= self
.model
.__name__
.lower()
102 class ProtectRegionMixin(object):
104 def queryset(self
, request
):
105 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
107 user_groups
= request
.user
.groups
.all()
108 if in_drh_or_admin(request
.user
):
111 if grp_correspondants_rh
in user_groups
:
112 employe
= get_employe_from_user(request
.user
)
113 q
= Q(**{self
.model
.prefix_implantation
: \
114 employe
.implantation
.region
})
115 qs
= qs
.filter(q
).distinct()
119 def has_add_permission(self
, request
):
120 if not in_drh_or_admin(request
.user
):
125 def has_change_permission(self
, request
, obj
=None):
126 user_groups
= request
.user
.groups
.all()
128 # Lock pour autoriser uniquement les DRH à utiliser RH
129 if not in_drh_or_admin(request
.user
):
132 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
137 ids
= [o
.id for o
in self
.queryset(request
)]
143 class ReadOnlyInlineMixin(object):
145 def get_readonly_fields(self
, request
, obj
=None):
146 return [f
.name
for f
in self
.model
._meta
.fields \
147 if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
150 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
151 model
= rh
.AyantDroit
152 form
= AyantDroitForm
159 ('nom_affichage', 'genre'),
167 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, \
168 admin
.TabularInline
):
169 readonly_fields
= ('owner', )
170 model
= rh
.AyantDroitCommentaire
174 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
180 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
181 template
= "admin/rh/dossier/linked.html"
182 exclude
= AUF_METADATA_READONLY_FIELDS
187 def has_add_permission(self
, request
=None):
190 def has_change_permission(self
, request
, obj
=None):
193 def has_delete_permission(self
, request
, obj
=None):
197 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, \
198 admin
.TabularInline
):
199 readonly_fields
= ('owner', )
200 model
= rh
.DossierCommentaire
204 class DossierPieceInline(admin
.TabularInline
):
205 model
= rh
.DossierPiece
209 class EmployeInline(admin
.TabularInline
):
213 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, \
214 admin
.TabularInline
):
215 readonly_fields
= ('owner', )
216 model
= rh
.EmployeCommentaire
220 class EmployePieceInline(admin
.TabularInline
):
221 model
= rh
.EmployePiece
225 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
226 readonly_fields
= ('owner', )
227 model
= rh
.PosteCommentaire
231 class PosteFinancementInline(admin
.TabularInline
):
232 model
= rh
.PosteFinancement
235 class PostePieceInline(admin
.TabularInline
):
236 model
= rh
.PostePiece
239 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
240 model
= rh
.Remuneration
244 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
248 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
252 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
253 model
= rh
.PosteComparaison
256 class ClassementAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
257 list_display
= ('_classement', '_date_modification', 'user_modification', )
258 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
260 'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
263 def _classement(self
, obj
):
265 _classement
.short_description
= u
"Classement"
267 def _date_modification(self
, obj
):
268 return date(obj
.date_modification
) \
269 if obj
.date_modification
is not None else "(aucune)"
270 _date_modification
.short_description
= u
'date modification'
271 _date_modification
.admin_order_field
= 'date_modification'
274 class CommentaireAdmin(admin
.ModelAdmin
):
278 class DeviseAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
283 '_date_modification',
286 list_filter
= ('archive', )
287 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
289 'fields': ('code', 'nom', 'archive', ),
293 def _date_modification(self
, obj
):
294 return date(obj
.date_modification
) \
295 if obj
.date_modification
is not None else "(aucune)"
296 _date_modification
.short_description
= u
'date modification'
297 _date_modification
.admin_order_field
= 'date_modification'
300 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
301 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
302 alphabet_filter
= 'employe__nom'
307 'poste__nom_feminin')
316 '_date_modification',
320 list_display_links
= ('_nom',)
322 'poste__implantation__region',
323 'poste__implantation',
324 'poste__type_poste__famille_emploi',
326 'rh_contrats__type_contrat',
329 inlines
= (DossierPieceInline
, ContratInline
,
331 DossierCommentaireInline
,
333 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
340 'organisme_bstg',)}),
345 'remplacement_de', )}),
349 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
350 ('Occupation du Poste par cet Employe', {
351 'fields': (('date_debut', 'date_fin'), )}
354 form
= make_ajax_form(rh
.Dossier
, {
355 'employe': 'employes',
357 'remplacement_de': 'dossiers',
358 }, superclass
=DossierForm
)
360 def lookup_allowed(self
, key
, value
):
362 'employe__nom__istartswith',
363 'poste__implantation__region__id__exact',
364 'poste__implantation__id__exact',
365 'poste__type_poste__id__exact',
366 'poste__type_poste__famille_emploi__id__exact',
367 'rh_contrats__type_contrat__id__exact',
375 _id
.short_description
= u
"#"
376 _id
.admin_order_field
= "id"
379 return "%d : %s %s" % (
381 obj
.employe
.nom
.upper(),
383 _nom
.allow_tags
= True
384 _nom
.short_description
= u
"Dossier"
386 def _apercu(self
, d
):
387 apercu_link
= u
"""<a title="Aperçu du dossier"
388 onclick="return showAddAnotherPopup(this);"
390 <img src="%simg/loupe.png" />
392 (reverse('dossier_apercu', args
=(d
.id,)),
396 _apercu
.allow_tags
= True
397 _apercu
.short_description
= u
""
401 dossiers_dae
= d
.dossiers_dae
.all()
402 if len(dossiers_dae
) > 0:
403 dossier_dae
= dossiers_dae
[0]
404 apercu_link
= u
"""<a title="Aperçu du dossier"
405 onclick="return showAddAnotherPopup(this);"
407 <img src="%simg/loupe.png" />
409 (reverse('embauche_consulter', args
=(dossier_dae
.id,)),
413 _dae
.allow_tags
= True
414 _dae
.short_description
= u
"DAE"
416 def _date_debut(self
, obj
):
417 return date(obj
.date_debut
)
419 _date_debut
.short_description
= u
'Occupation début'
420 _date_debut
.admin_order_field
= 'date_debut'
422 def _date_fin(self
, obj
):
423 return date(obj
.date_fin
)
424 _date_fin
.short_description
= u
'Occupation fin'
425 _date_fin
.admin_order_field
= 'date_fin'
427 def _date_modification(self
, obj
):
428 return date(obj
.date_modification
) \
429 if obj
.date_modification
is not None else "(aucune)"
430 _date_modification
.short_description
= u
'date modification'
431 _date_modification
.admin_order_field
= 'date_modification'
433 def _poste(self
, dossier
):
434 link
= u
"""<a title="Aperçu du poste"
435 onclick="return showAddAnotherPopup(this);"
436 href='%s'><img src="%simg/loupe.png" />
438 <a href="%s" title="Modifier le poste">%s</a>""" % \
439 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
441 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
445 _poste
.allow_tags
= True
446 _poste
.short_description
= u
'Poste'
447 _poste
.admin_order_field
= 'poste__nom'
449 def _employe(self
, obj
):
450 employe
= obj
.employe
451 view_link
= reverse('employe_apercu', args
=(employe
.id,))
452 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
455 view
= u
"""<a href="%s"
456 title="Aperçu l'employé"
457 onclick="return showAddAnotherPopup(this);">
458 <img src="%simg/loupe.png" />
459 </a>""" % (view_link
, settings
.STATIC_URL
,)
460 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
461 (view
, edit_link
, style
, employe
)
462 _employe
.allow_tags
= True
463 _employe
.short_description
= u
"Employé"
464 _employe
.admin_order_field
= "employe__nom"
466 def save_formset(self
, request
, form
, formset
, change
):
467 instances
= formset
.save(commit
=False)
468 for instance
in instances
:
469 if instance
.__class__
== rh
.DossierCommentaire
:
470 instance
.owner
= request
.user
471 instance
.date_creation
= datetime
.datetime
.now()
475 class DossierPieceAdmin(admin
.ModelAdmin
):
479 class DossierCommentaireAdmin(admin
.ModelAdmin
):
483 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
484 ProtectRegionMixin
, admin
.ModelAdmin
,):
485 prefixe_recherche_temporelle
= "rh_dossiers__"
486 alphabet_filter
= 'nom'
487 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
488 search_fields
= ('id', 'nom', 'prenom', 'nom_affichage', )
490 form
= EmployeAdminForm
496 '_date_modification',
499 list_display_links
= ('_nom',)
501 'rh_dossiers__poste__implantation__region',
502 'rh_dossiers__poste__implantation',
505 inlines
= (AyantDroitInline
,
508 EmployeCommentaireInline
)
509 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
513 ('nom_affichage', 'genre'),
518 ('Informations personnelles', {
519 'fields': ('situation_famille', 'date_entree', )}
523 ('tel_domicile', 'tel_cellulaire'),
524 ('adresse', 'ville'),
525 ('code_postal', 'province'),
531 def _apercu(self
, obj
):
532 return u
"""<a title="Aperçu de l'employé"
533 onclick="return showAddAnotherPopup(this);"
535 <img src="%simg/loupe.png" />
537 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
538 _apercu
.allow_tags
= True
539 _apercu
.short_description
= u
""
542 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
543 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
544 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
545 _nom
.allow_tags
= True
546 _nom
.short_description
= u
"Employé"
547 _nom
.admin_order_field
= "nom"
551 _id
.short_description
= u
"#"
552 _id
.admin_order_field
= "id"
554 def _date_modification(self
, obj
):
555 return date(obj
.date_modification
) \
556 if obj
.date_modification
is not None else "(aucune)"
557 _date_modification
.short_description
= u
'date modification'
558 _date_modification
.admin_order_field
= 'date_modification'
560 def _dossiers_postes(self
, obj
):
562 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
563 dossier
= u
"""<a title="Aperçu du dossier"
565 onclick="return showAddAnotherPopup(this);"
566 title="Aperçu du dossier">
567 <img src="%simg/loupe.png" />
569 <a href="%s">Dossier</a>
571 (reverse('dossier_apercu', args
=(d
.id,)),
573 reverse('admin:rh_dossier_change', args
=(d
.id,)))
575 poste
= u
"""<a title="Aperçu du poste"
577 onclick="return showAddAnotherPopup(this);"
578 title="Aperçu du poste">
579 <img src="%simg/loupe.png" />
581 <a href="%s">Poste</a>
583 (reverse('poste_apercu', args
=(d
.poste
.id,)),
585 reverse('admin:rh_poste_change', args
=(d
.poste
.id,)))
586 link
= u
"""<li>%s %s - %s : [%s] %s</li>""" % \
593 # Dossier terminé en gris non cliquable
594 if d
.date_fin
is not None and d
.date_fin
< datetime
.date
.today():
595 link
= u
"""<li style="color: grey">%s : [%s] %s</li>""" % \
602 return "<ul>%s</ul>" % "\n".join(l
)
603 _dossiers_postes
.allow_tags
= True
604 _dossiers_postes
.short_description
= u
"Dossiers et postes"
606 def queryset(self
, request
):
607 qs
= super(EmployeAdmin
, self
).queryset(request
)
608 return qs
.select_related(depth
=1).order_by('nom')
610 def save_formset(self
, request
, form
, formset
, change
):
611 instances
= formset
.save(commit
=False)
612 for instance
in instances
:
613 if instance
.__class__
== rh
.EmployeCommentaire
:
614 instance
.owner
= request
.user
615 instance
.date_creation
= datetime
.datetime
.now()
619 class EmployeProxyAdmin(EmployeAdmin
):
620 list_display
= ('_id', '_apercu', '_nom', '_organigramme')
623 def __init__(self
, *args
, **kwargs
):
624 super(EmployeProxyAdmin
, self
).__init__(*args
, **kwargs
)
625 self
.list_display_links
= (None, )
627 def has_add_permission(self
, obj
):
630 def _organigramme(self
, obj
):
632 for d
in rh
.Dossier
.objects
.filter((Q(date_fin__gt
=datetime
.date
.today()) |
Q(date_fin
=None)) & (Q(date_debut__lt
=datetime
.date
.today()) |
Q(date_debut
=None)) ).filter(employe
=obj
.id).all():
633 organigramme
= u
"""Organigramme, niveau: <input type="text" id="level_%s" style="width:30px;height:15px;" /> <input type="button" value="Générer" onclick="window.location='%s'+document.getElementById('level_%s').value" />""" % \
634 (d
.poste
.id, reverse('rho_employe_sans_niveau', args
=(d
.poste
.id,)), d
.poste
.id)
635 link
= u
"""<li>%s - [%s] %s : %s</li>""" % \
642 return "<ul>%s</ul>" % "\n".join(l
)
644 _organigramme
.allow_tags
= True
645 _organigramme
.short_description
= "Organigramme"
648 class EmployeCommentaireAdmin(admin
.ModelAdmin
):
652 class EmployePieceAdmin(admin
.ModelAdmin
):
656 class FamilleEmploiAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
657 list_display
= ('nom', '_date_modification', 'user_modification', )
658 inlines
= (TypePosteInline
,)
659 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
660 (None, {'fields': ('nom', )}),)
662 def _date_modification(self
, obj
):
663 return date(obj
.date_modification
) \
664 if obj
.date_modification
is not None else "(aucune)"
665 _date_modification
.short_description
= u
'date modification'
666 _date_modification
.admin_order_field
= 'date_modification'
669 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
670 search_fields
= ('nom',)
675 '_date_modification',
678 list_filter
= ('type', )
679 inlines
= (DossierROInline
,)
680 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
681 (None, {'fields': ('nom', 'type', 'pays',)}),
684 def _date_modification(self
, obj
):
685 return date(obj
.date_modification
) \
686 if obj
.date_modification
is not None else "(aucune)"
687 _date_modification
.short_description
= u
'date modification'
688 _date_modification
.admin_order_field
= 'date_modification'
691 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
692 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
693 form
= make_ajax_form(rh
.Poste
, {
694 'implantation': 'implantations',
695 'type_poste': 'typepostes',
696 'responsable': 'postes',
697 'valeur_point_min': 'valeurpoints',
698 'valeur_point_max': 'valeurpoints',
700 alphabet_filter
= 'nom'
705 'implantation__region__code',
706 'implantation__region__nom',
707 'rh_dossiers__employe__nom',
708 'rh_dossiers__employe__prenom',
720 '_date_modification',
725 'implantation__region',
729 'type_poste__famille_emploi',
732 list_display_links
= ('_nom',)
733 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
735 ('nom', 'nom_feminin'),
745 'regime_travail_nb_heure_semaine'),
749 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
752 'fields': (('classement_min',
765 ('Comparatifs de rémunération', {
766 'fields': ('devise_comparaison',
767 ('comp_locale_min', 'comp_locale_max'),
768 ('comp_universite_min', 'comp_universite_max'),
769 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
770 ('comp_ong_min', 'comp_ong_max'),
771 ('comp_autre_min', 'comp_autre_max'))}
774 'fields': ('justification',)}
776 ('Autres Méta-données', {
777 'fields': ('date_debut', 'date_fin')}
781 inlines
= (PosteFinancementInline
,
784 PosteComparaisonInline
,
785 PosteCommentaireInline
, )
787 def lookup_allowed(self
, key
, value
):
790 'date_debut__isnull',
793 'implantation__region__id__exact',
794 'implantation__id__exact',
795 'type_poste__id__exact',
796 'type_poste__famille_emploi__id__exact',
797 'service__id__exact',
804 def _apercu(self
, poste
):
805 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);"
806 title="Aperçu du poste"
808 <img src="%simg/loupe.png" />
810 (reverse('poste_apercu', args
=(poste
.id,)),
811 settings
.STATIC_URL
,)
813 _apercu
.allow_tags
= True
814 _apercu
.short_description
= ''
816 def _dae(self
, poste
):
818 postes_dae
= poste
.postes_dae
.all()
819 if len(postes_dae
) > 0:
820 poste_dae
= postes_dae
[0]
822 u
'<a title="Aperçu du dossier" href="%s" ' \
823 u
'onclick="return showAddAnotherPopup(this);">' \
824 u
'<img src="%simg/loupe.png" /></a>' % (reverse(
825 'poste_consulter', args
=("dae-%s" % poste_dae
.id,)
826 ), settings
.STATIC_URL
)
828 _dae
.allow_tags
= True
829 _dae
.short_description
= u
"DAE"
833 _id
.short_description
= '#'
834 _id
.admin_order_field
= 'id'
836 def _service(self
, obj
):
837 if obj
.service
.supprime
:
838 return """<span style="color:red">%s</span>""" % obj
.service
841 _service
.short_description
= 'Service'
842 _service
.allow_tags
= True
844 def _responsable(self
, obj
):
846 responsable
= u
"""<a href="%s"
847 onclick="return showAddAnotherPopup(this)">
848 <img src="%simg/loupe.png"
849 title="Aperçu du poste" />
853 (reverse('poste_apercu', args
=(obj
.responsable
.id,)),
855 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
861 employe_id
= obj
.responsable
.rh_dossiers
.all()[0].id
864 onclick="return showAddAnotherPopup(this)">
865 <img src="%simg/loupe.png"
866 title="Aperçu de l'employé">
868 <a href="%s">%s</a>""" % \
869 (reverse('employe_apercu', args
=(employe_id
,)),
871 reverse('admin:rh_employe_change', args
=(employe_id
,)),
876 return "%s %s" % (responsable
, employe
)
877 _responsable
.short_description
= 'Responsable'
878 _responsable
.allow_tags
= True
880 def _nom(self
, poste
):
881 return """<a href="%s">%s</a>""" % \
882 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
884 _nom
.allow_tags
= True
885 _nom
.short_description
= u
'Nom'
886 _nom
.admin_order_field
= 'nom'
888 def _date_modification(self
, obj
):
889 return date(obj
.date_modification
)
890 _date_modification
.short_description
= u
'date modification'
891 _date_modification
.admin_order_field
= 'date_modification'
893 def _occupe_par(self
, obj
):
894 """Formatte la méthode Poste.occupe_par() pour l'admin"""
896 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.today():
898 employes
= obj
.occupe_par()
902 link
= u
"""<a href='%s'
903 title='Aperçu de l\'employer'
904 onclick='return showAddAnotherPopup(this)'>
905 <img src='%simg/loupe.png' />
907 <a href='%s'>%s</a>""" % \
908 (reverse('employe_apercu', args
=(e
.id,)),
910 reverse('admin:rh_employe_change', args
=(e
.id,)),
913 output
= "\n<br />".join(l
)
915 _occupe_par
.allow_tags
= True
916 _occupe_par
.short_description
= "Occupé par"
918 def save_formset(self
, request
, form
, formset
, change
):
919 instances
= formset
.save(commit
=False)
920 for instance
in instances
:
921 if instance
.__class__
== rh
.PosteCommentaire
:
922 instance
.owner
= request
.user
923 instance
.date_creation
= datetime
.datetime
.now()
928 class PosteCommentaireAdmin(admin
.ModelAdmin
):
932 class PosteFinancementAdmin(admin
.ModelAdmin
):
936 class PostePieceAdmin(admin
.ModelAdmin
):
940 class RemunerationAdmin(admin
.ModelAdmin
):
944 class ResponsableInline(admin
.TabularInline
):
945 model
= rh
.ResponsableImplantation
947 fk_name
= "implantation"
949 class ResponsableImplantationAdmin(admin
.ModelAdmin
):
951 list_filter
= ('region', 'statut', )
952 list_display
= ('nom', 'statut', '_responsable', )
953 readonly_fields
= ('nom', )
955 inlines
= (ResponsableInline
, )
957 def _responsable(self
, obj
):
959 employe
= obj
.responsable
.employe
960 dossiers
= employe
.dossiers_encours()
961 if len(dossiers
) == 0:
962 return u
"<span style='color: red;'>%s %s </span>" % (
963 employe
, u
"sans dossier actif")
967 if obj
.statut
in (1, 2): # ouverte, ouverture imminente
968 css
= "style='color: red;'"
971 return u
"<span %s>Pas de responsable</span>" % css
972 _responsable
.allow_tags
= True
973 _responsable
.short_description
= u
"Responsable"
975 def has_add_permission(self
, request
=None):
978 def has_change_permission(self
, request
, obj
=None):
979 return in_drh_or_admin(request
.user
)
981 def has_delete_permission(self
, request
, obj
=None):
984 class ServiceAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
988 '_date_modification',
991 list_filter
= ('archive', )
992 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
994 'fields': ('nom', 'archive', ),
998 def _date_modification(self
, obj
):
999 return date(obj
.date_modification
) \
1000 if obj
.date_modification
is not None else "(aucune)"
1001 _date_modification
.short_description
= u
'date modification'
1002 _date_modification
.admin_order_field
= 'date_modification'
1004 class ServiceProxyAdmin(ServiceAdmin
):
1005 list_display
= ('nom', '_organigramme', '_archive', )
1008 def __init__(self
, *args
, **kwargs
):
1009 super(ServiceProxyAdmin
, self
).__init__(*args
, **kwargs
)
1010 self
.list_display_links
= (None, )
1012 def has_add_permission(self
, obj
):
1015 def has_change_permission(self
, request
, obj
=None):
1016 return in_drh_or_admin(request
.user
)
1018 def _organigramme(self
, obj
):
1019 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1020 (reverse('rho_service', args
=(obj
.id,)))
1021 _organigramme
.allow_tags
= True
1022 _organigramme
.short_description
= "Organigramme"
1025 class StatutAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1026 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
1027 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1029 'fields': ('code', 'nom', ),
1033 def _date_modification(self
, obj
):
1034 return date(obj
.date_modification
) \
1035 if obj
.date_modification
is not None else "(aucune)"
1036 _date_modification
.short_description
= u
'date modification'
1037 _date_modification
.admin_order_field
= 'date_modification'
1040 class TauxChangeAdmin(admin
.ModelAdmin
):
1045 '_date_modification',
1046 'user_modification',
1048 list_filter
= ('devise', )
1049 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1051 'fields': ('taux', 'devise', 'annee', ),
1055 def _date_modification(self
, obj
):
1056 return date(obj
.date_modification
) \
1057 if obj
.date_modification
is not None else "(aucune)"
1058 _date_modification
.short_description
= u
'date modification'
1059 _date_modification
.admin_order_field
= 'date_modification'
1062 class TypeContratAdmin(admin
.ModelAdmin
):
1066 '_date_modification',
1067 'user_modification',
1069 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1071 'fields': ('nom', 'nom_long', ),
1075 def _date_modification(self
, obj
):
1076 return date(obj
.date_modification
) \
1077 if obj
.date_modification
is not None else "(aucune)"
1078 _date_modification
.short_description
= u
'date modification'
1079 _date_modification
.admin_order_field
= 'date_modification'
1082 class TypePosteAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1083 search_fields
= ('nom', 'nom_feminin', )
1087 '_date_modification',
1088 'user_modification',
1090 list_filter
= ('famille_emploi', )
1091 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1102 def _date_modification(self
, obj
):
1103 return date(obj
.date_modification
) \
1104 if obj
.date_modification
is not None else "(aucune)"
1105 _date_modification
.short_description
= u
'date modification'
1106 _date_modification
.admin_order_field
= 'date_modification'
1109 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
1113 'nature_remuneration',
1115 '_date_modification',
1116 'user_modification',)
1117 list_filter
= ('archive', )
1118 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1119 (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration',
1123 def _date_modification(self
, obj
):
1124 return date(obj
.date_modification
) \
1125 if obj
.date_modification
is not None else "(aucune)"
1126 _date_modification
.short_description
= u
'date modification'
1127 _date_modification
.admin_order_field
= 'date_modification'
1130 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1131 list_display
= ('nom', '_date_modification', 'user_modification', )
1132 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1133 (None, {'fields': ('nom', )}),
1136 def _date_modification(self
, obj
):
1137 return date(obj
.date_modification
) \
1138 if obj
.date_modification
is not None else "(aucune)"
1139 _date_modification
.short_description
= u
'date modification'
1140 _date_modification
.admin_order_field
= 'date_modification'
1143 class ValeurPointAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1150 '_date_modification',
1151 'user_modification',
1153 list_filter
= ('annee', 'devise', 'implantation__region', )
1154 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1155 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}),
1158 def _date_modification(self
, obj
):
1159 return date(obj
.date_modification
) \
1160 if obj
.date_modification
is not None else "(aucune)"
1161 _date_modification
.short_description
= u
'date modification'
1162 _date_modification
.admin_order_field
= 'date_modification'
1164 def _devise_code(self
, obj
):
1165 return obj
.devise
.code
1166 _devise_code
.short_description
= "Code de la devise"
1168 def _devise_nom(self
, obj
):
1169 return obj
.devise
.nom
1170 _devise_nom
.short_description
= "Nom de la devise"
1172 class ImplantationProxyAdmin(admin
.ModelAdmin
):
1173 list_display
= ('nom', '_organigramme')
1176 def __init__(self
, *args
, **kwargs
):
1177 super(ImplantationProxyAdmin
, self
).__init__(*args
, **kwargs
)
1178 self
.list_display_links
= (None, )
1180 def has_add_permission(self
, obj
):
1183 def has_change_permission(self
, request
, obj
=None):
1184 return in_drh_or_admin(request
.user
)
1186 def _organigramme(self
, obj
):
1187 return """<a href="%s"><strong>Organigramme</strong></a>""" % (reverse('rho_implantation', args
=(obj
.id,)))
1188 _organigramme
.allow_tags
= True
1189 _organigramme
.short_description
= "Organigramme"
1191 class RegionProxyAdmin(admin
.ModelAdmin
):
1192 list_display
= ('nom', '_organigramme')
1195 def __init__(self
, *args
, **kwargs
):
1196 super(RegionProxyAdmin
, self
).__init__(*args
, **kwargs
)
1197 self
.list_display_links
= (None, )
1199 def has_add_permission(self
, obj
):
1202 def has_change_permission(self
, request
, obj
=None):
1203 return in_drh_or_admin(request
.user
)
1205 def _organigramme(self
, obj
):
1206 return """<a href="%s"><strong>Organigramme</strong></a>""" % (reverse('rho_region', args
=(obj
.id,)))
1207 _organigramme
.allow_tags
= True
1208 _organigramme
.short_description
= "Organigramme"
1213 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
1214 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
1215 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
1216 admin
.site
.register(EmployeProxy
, EmployeProxyAdmin
)
1217 admin
.site
.register(ServiceProxy
, ServiceProxyAdmin
)
1218 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
1219 admin
.site
.register(rh
.FamilleEmploi
, FamilleEmploiAdmin
)
1220 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
1221 admin
.site
.register(rh
.Poste
, PosteAdmin
)
1222 admin
.site
.register(rh
.ResponsableImplantationProxy
, ResponsableImplantationAdmin
)
1223 admin
.site
.register(rh
.Service
, ServiceAdmin
)
1224 admin
.site
.register(rh
.Statut
, StatutAdmin
)
1225 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
1226 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
1227 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
1228 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
1229 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
1230 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)
1231 admin
.site
.register(ImplantationProxy
, ImplantationProxyAdmin
)
1232 admin
.site
.register(RegionProxy
, RegionProxyAdmin
)