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 groups
import grp_correspondants_rh
22 from decorators
import in_drh_or_admin
25 class ArchiveMixin(object):
27 Archive Mixin pour gérer le queryset et le display
28 NON COMPRIS : list_filter, et list_display, field à setter dans la classe.
31 def queryset(self
, request
):
32 return self
.model
._base_manager
34 def _archive(self
, obj
):
39 _archive
.short_description
= u
'Archivé'
40 _archive
.admin_order_field
= 'archive'
43 class RegionProxy(ref
.Region
):
44 """ Proxy utilisé pour les organigrammes par région """
47 verbose_name
= u
"Organigramme par région"
48 verbose_name_plural
= u
"Organigramme par région"
51 class ImplantationProxy(ref
.Implantation
):
52 """ Proxy utilisé pour les organigrammes par implantation """
55 verbose_name
= u
"Organigramme par implantations"
56 verbose_name_plural
= u
"Organigramme par implantations"
59 class ServiceProxy(rh
.Service
):
60 """ Proxy utilisé pour les organigrammes opar service """
63 verbose_name
= u
"Organigramme par services"
64 verbose_name_plural
= u
"Organigramme par services"
67 class EmployeProxy(rh
.Employe
):
68 """ Proxy utilisé pour les organigrammes des employés """
71 verbose_name
= u
"Organigramme des employés"
72 verbose_name_plural
= u
"Organigramme des employés"
75 class DateRangeMixin(object):
76 prefixe_recherche_temporelle
= ""
78 def get_changelist(self
, request
, **kwargs
):
79 if 'HTTP_REFERER' in request
.META
.keys():
80 referer
= request
.META
['HTTP_REFERER']
81 referer
= "/".join(referer
.split('/')[3:])
82 referer
= "/%s" % referer
.split('?')[0]
83 change_list_view
= 'admin:%s_%s_changelist' % (
84 self
.model
._meta
.app_label
,
85 self
.model
.__name__
.lower(),)
86 if referer
!= reverse(change_list_view
):
87 params
= request
.GET
.copy()
88 params
.update({'statut': 'Actif'})
93 # Override of the InlineModelAdmin to support the link in the tabular inline
94 class LinkedInline(admin
.options
.InlineModelAdmin
):
95 template
= "admin/linked.html"
96 admin_model_path
= None
98 def __init__(self
, *args
):
99 super(LinkedInline
, self
).__init__(*args
)
100 if self
.admin_model_path
is None:
101 self
.admin_model_path
= self
.model
.__name__
.lower()
104 class ProtectRegionMixin(object):
106 def queryset(self
, request
):
107 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
109 user_groups
= request
.user
.groups
.all()
110 if in_drh_or_admin(request
.user
):
113 if grp_correspondants_rh
in user_groups
:
114 employe
= get_employe_from_user(request
.user
)
115 q
= Q(**{self
.model
.prefix_implantation
: \
116 employe
.implantation
.region
})
117 qs
= qs
.filter(q
).distinct()
121 def has_add_permission(self
, request
):
122 if not in_drh_or_admin(request
.user
):
127 def has_change_permission(self
, request
, obj
=None):
128 user_groups
= request
.user
.groups
.all()
130 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
135 ids
= [o
.id for o
in self
.queryset(request
)]
141 class ReadOnlyInlineMixin(object):
143 def get_readonly_fields(self
, request
, obj
=None):
144 return [f
.name
for f
in self
.model
._meta
.fields \
145 if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
148 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
149 model
= rh
.AyantDroit
150 form
= AyantDroitForm
157 ('nom_affichage', 'genre'),
165 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, \
166 admin
.TabularInline
):
167 readonly_fields
= ('owner', )
168 model
= rh
.AyantDroitCommentaire
172 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
178 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
179 template
= "admin/rh/dossier/linked.html"
180 exclude
= AUF_METADATA_READONLY_FIELDS
185 def has_add_permission(self
, request
=None):
188 def has_change_permission(self
, request
, obj
=None):
191 def has_delete_permission(self
, request
, obj
=None):
195 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, \
196 admin
.TabularInline
):
197 readonly_fields
= ('owner', )
198 model
= rh
.DossierCommentaire
202 class DossierPieceInline(admin
.TabularInline
):
203 model
= rh
.DossierPiece
207 class EmployeInline(admin
.TabularInline
):
211 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, \
212 admin
.TabularInline
):
213 readonly_fields
= ('owner', )
214 model
= rh
.EmployeCommentaire
218 class EmployePieceInline(admin
.TabularInline
):
219 model
= rh
.EmployePiece
223 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
224 readonly_fields
= ('owner', )
225 model
= rh
.PosteCommentaire
229 class PosteFinancementInline(admin
.TabularInline
):
230 model
= rh
.PosteFinancement
233 class PostePieceInline(admin
.TabularInline
):
234 model
= rh
.PostePiece
237 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
238 model
= rh
.Remuneration
242 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
246 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
250 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
251 model
= rh
.PosteComparaison
254 class ClassementAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
255 list_display
= ('_classement', '_date_modification', 'user_modification', )
256 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
258 'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
261 def _classement(self
, obj
):
263 _classement
.short_description
= u
"Classement"
265 def _date_modification(self
, obj
):
266 return date(obj
.date_modification
) \
267 if obj
.date_modification
is not None else "(aucune)"
268 _date_modification
.short_description
= u
'date modification'
269 _date_modification
.admin_order_field
= 'date_modification'
272 class CommentaireAdmin(admin
.ModelAdmin
):
276 class DeviseAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
281 '_date_modification',
284 list_filter
= ('archive', )
285 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
287 'fields': ('code', 'nom', 'archive', ),
291 def _date_modification(self
, obj
):
292 return date(obj
.date_modification
) \
293 if obj
.date_modification
is not None else "(aucune)"
294 _date_modification
.short_description
= u
'date modification'
295 _date_modification
.admin_order_field
= 'date_modification'
298 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
299 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
300 alphabet_filter
= 'employe__nom'
305 'poste__nom_feminin')
314 '_date_modification',
318 list_display_links
= ('_nom',)
320 'poste__implantation__region',
321 'poste__implantation',
322 'poste__type_poste__categorie_emploi',
324 'rh_contrats__type_contrat',
327 inlines
= (DossierPieceInline
, ContratInline
,
329 DossierCommentaireInline
,
331 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
338 'organisme_bstg',)}),
343 'remplacement_de', )}),
347 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
348 ('Occupation du Poste par cet Employe', {
349 'fields': (('date_debut', 'date_fin'), )}
352 form
= make_ajax_form(rh
.Dossier
, {
353 'employe': 'employes',
355 'remplacement_de': 'dossiers',
356 }, superclass
=DossierForm
)
358 def lookup_allowed(self
, key
, value
):
360 'employe__nom__istartswith',
361 'poste__implantation__region__id__exact',
362 'poste__implantation__id__exact',
363 'poste__type_poste__id__exact',
364 'poste__type_poste__categorie_emploi__id__exact',
365 'rh_contrats__type_contrat__id__exact',
373 _id
.short_description
= u
"#"
374 _id
.admin_order_field
= "id"
377 return "%d : %s %s" % (
379 obj
.employe
.nom
.upper(),
381 _nom
.allow_tags
= True
382 _nom
.short_description
= u
"Dossier"
384 def _apercu(self
, d
):
385 apercu_link
= u
"""<a title="Aperçu du dossier"
386 onclick="return showAddAnotherPopup(this);"
388 <img src="%simg/loupe.png" />
390 (reverse('dossier_apercu', args
=(d
.id,)),
394 _apercu
.allow_tags
= True
395 _apercu
.short_description
= u
""
399 dossiers_dae
= d
.dossiers_dae
.all()
400 if len(dossiers_dae
) > 0:
401 dossier_dae
= dossiers_dae
[0]
402 apercu_link
= u
"""<a title="Aperçu du dossier"
403 onclick="return showAddAnotherPopup(this);"
405 <img src="%simg/loupe.png" />
407 (reverse('embauche_consulter', args
=(dossier_dae
.id,)),
411 _dae
.allow_tags
= True
412 _dae
.short_description
= u
"DAE"
414 def _date_debut(self
, obj
):
415 return date(obj
.date_debut
)
417 _date_debut
.short_description
= u
'Occupation début'
418 _date_debut
.admin_order_field
= 'date_debut'
420 def _date_fin(self
, obj
):
421 return date(obj
.date_fin
)
422 _date_fin
.short_description
= u
'Occupation fin'
423 _date_fin
.admin_order_field
= 'date_fin'
425 def _date_modification(self
, obj
):
426 return date(obj
.date_modification
) \
427 if obj
.date_modification
is not None else "(aucune)"
428 _date_modification
.short_description
= u
'date modification'
429 _date_modification
.admin_order_field
= 'date_modification'
431 def _poste(self
, dossier
):
432 link
= u
"""<a title="Aperçu du poste"
433 onclick="return showAddAnotherPopup(this);"
434 href='%s'><img src="%simg/loupe.png" />
436 <a href="%s" title="Modifier le poste">%s</a>""" % \
437 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
439 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
443 _poste
.allow_tags
= True
444 _poste
.short_description
= u
'Poste'
445 _poste
.admin_order_field
= 'poste__nom'
447 def _employe(self
, obj
):
448 employe
= obj
.employe
449 view_link
= reverse('employe_apercu', args
=(employe
.id,))
450 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
453 view
= u
"""<a href="%s"
454 title="Aperçu l'employé"
455 onclick="return showAddAnotherPopup(this);">
456 <img src="%simg/loupe.png" />
457 </a>""" % (view_link
, settings
.STATIC_URL
,)
458 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
459 (view
, edit_link
, style
, employe
)
460 _employe
.allow_tags
= True
461 _employe
.short_description
= u
"Employé"
462 _employe
.admin_order_field
= "employe__nom"
464 def save_formset(self
, request
, form
, formset
, change
):
465 instances
= formset
.save(commit
=False)
466 for instance
in instances
:
467 if instance
.__class__
== rh
.DossierCommentaire
:
468 instance
.owner
= request
.user
469 instance
.date_creation
= datetime
.datetime
.now()
473 class DossierPieceAdmin(admin
.ModelAdmin
):
477 class DossierCommentaireAdmin(admin
.ModelAdmin
):
481 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
482 ProtectRegionMixin
, admin
.ModelAdmin
,):
483 prefixe_recherche_temporelle
= "rh_dossiers__"
484 alphabet_filter
= 'nom'
485 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
486 search_fields
= ('id', 'nom', 'prenom', 'nom_affichage', )
488 form
= EmployeAdminForm
494 '_date_modification',
497 list_display_links
= ('_nom',)
499 'rh_dossiers__poste__implantation__region',
500 'rh_dossiers__poste__implantation',
503 inlines
= (AyantDroitInline
,
506 EmployeCommentaireInline
)
507 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
511 ('nom_affichage', 'genre'),
516 ('Informations personnelles', {
517 'fields': ('situation_famille', 'date_entree', )}
521 ('tel_domicile', 'tel_cellulaire'),
522 ('adresse', 'ville'),
523 ('code_postal', 'province'),
529 def _apercu(self
, obj
):
530 return u
"""<a title="Aperçu de l'employé"
531 onclick="return showAddAnotherPopup(this);"
533 <img src="%simg/loupe.png" />
535 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
536 _apercu
.allow_tags
= True
537 _apercu
.short_description
= u
""
540 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
541 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
542 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
543 _nom
.allow_tags
= True
544 _nom
.short_description
= u
"Employé"
545 _nom
.admin_order_field
= "nom"
549 _id
.short_description
= u
"#"
550 _id
.admin_order_field
= "id"
552 def _date_modification(self
, obj
):
553 return date(obj
.date_modification
) \
554 if obj
.date_modification
is not None else "(aucune)"
555 _date_modification
.short_description
= u
'date modification'
556 _date_modification
.admin_order_field
= 'date_modification'
558 def _dossiers_postes(self
, obj
):
560 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
561 dossier
= u
"""<a title="Aperçu du dossier"
563 onclick="return showAddAnotherPopup(this);"
564 title="Aperçu du dossier">
565 <img src="%simg/loupe.png" />
567 <a href="%s">Dossier</a>
569 (reverse('dossier_apercu', args
=(d
.id,)),
571 reverse('admin:rh_dossier_change', args
=(d
.id,)))
573 poste
= u
"""<a title="Aperçu du poste"
575 onclick="return showAddAnotherPopup(this);"
576 title="Aperçu du poste">
577 <img src="%simg/loupe.png" />
579 <a href="%s">Poste</a>
581 (reverse('poste_apercu', args
=(d
.poste
.id,)),
583 reverse('admin:rh_poste_change', args
=(d
.poste
.id,)))
584 link
= u
"""<li>%s %s - %s : [%s] %s</li>""" % \
591 # Dossier terminé en gris non cliquable
592 if d
.date_fin
is not None and d
.date_fin
< datetime
.date
.today():
593 link
= u
"""<li style="color: grey">%s : [%s] %s</li>""" % \
600 return "<ul>%s</ul>" % "\n".join(l
)
601 _dossiers_postes
.allow_tags
= True
602 _dossiers_postes
.short_description
= u
"Dossiers et postes"
604 def queryset(self
, request
):
605 qs
= super(EmployeAdmin
, self
).queryset(request
)
606 return qs
.select_related(depth
=1).order_by('nom')
608 def save_formset(self
, request
, form
, formset
, change
):
609 instances
= formset
.save(commit
=False)
610 for instance
in instances
:
611 if instance
.__class__
== rh
.EmployeCommentaire
:
612 instance
.owner
= request
.user
613 instance
.date_creation
= datetime
.datetime
.now()
617 class EmployeProxyAdmin(EmployeAdmin
):
618 list_display
= ('_id', '_apercu', '_nom', '_organigramme')
621 def __init__(self
, *args
, **kwargs
):
622 super(EmployeProxyAdmin
, self
).__init__(*args
, **kwargs
)
623 self
.list_display_links
= (None, )
625 def has_add_permission(self
, obj
):
628 def _organigramme(self
, obj
):
630 for d
in rh
.Dossier
.objects
.filter(
631 Q(date_fin__gt
=datetime
.date
.today()) |
Q(date_fin
=None),
632 Q(date_debut__lt
=datetime
.date
.today()) |
Q(date_debut
=None),
636 u
'Organigramme, niveau: ' \
637 u
'<input type="text" id="level_%s" ' \
638 u
'style="width:30px;height:15px;" /> ' \
639 u
'<input type="button" value="Générer" ' \
640 u
"""onclick="window.location='%s' + """ \
641 u
"""document.getElementById('level_%s').value" />""" % (
643 reverse('rho_employe_sans_niveau', args
=(d
.poste
.id,)),
646 link
= u
"""<li>%s - [%s] %s : %s</li>""" % (
653 return "<ul>%s</ul>" % "\n".join(l
)
655 _organigramme
.allow_tags
= True
656 _organigramme
.short_description
= "Organigramme"
659 class EmployeCommentaireAdmin(admin
.ModelAdmin
):
663 class EmployePieceAdmin(admin
.ModelAdmin
):
667 class CategorieEmploiAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
668 list_display
= ('nom', '_date_modification', 'user_modification', )
669 inlines
= (TypePosteInline
,)
670 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
671 (None, {'fields': ('nom', )}),)
673 def _date_modification(self
, obj
):
674 return date(obj
.date_modification
) \
675 if obj
.date_modification
is not None else "(aucune)"
676 _date_modification
.short_description
= u
'date modification'
677 _date_modification
.admin_order_field
= 'date_modification'
680 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
681 search_fields
= ('nom',)
686 '_date_modification',
689 list_filter
= ('type', )
690 inlines
= (DossierROInline
,)
691 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
692 (None, {'fields': ('nom', 'type', 'pays',)}),
695 def _date_modification(self
, obj
):
696 return date(obj
.date_modification
) \
697 if obj
.date_modification
is not None else "(aucune)"
698 _date_modification
.short_description
= u
'date modification'
699 _date_modification
.admin_order_field
= 'date_modification'
702 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
, \
703 ProtectRegionMixin
, admin
.ModelAdmin
, AjaxSelect
,):
704 form
= make_ajax_form(rh
.Poste
, {
705 'implantation': 'implantations',
706 'type_poste': 'typepostes',
707 'responsable': 'postes',
708 'valeur_point_min': 'valeurpoints',
709 'valeur_point_max': 'valeurpoints',
711 alphabet_filter
= 'nom'
716 'implantation__region__code',
717 'implantation__region__nom',
718 'rh_dossiers__employe__nom',
719 'rh_dossiers__employe__prenom',
731 '_date_modification',
736 'implantation__region',
740 'type_poste__categorie_emploi',
741 'type_poste__famille_professionnelle',
744 list_display_links
= ('_nom',)
745 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
747 ('nom', 'nom_feminin'),
757 'regime_travail_nb_heure_semaine'),
761 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
764 'fields': (('classement_min',
777 ('Comparatifs de rémunération', {
778 'fields': ('devise_comparaison',
779 ('comp_locale_min', 'comp_locale_max'),
780 ('comp_universite_min', 'comp_universite_max'),
781 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
782 ('comp_ong_min', 'comp_ong_max'),
783 ('comp_autre_min', 'comp_autre_max'))}
786 'fields': ('justification',)}
788 ('Autres Méta-données', {
789 'fields': ('date_debut', 'date_fin')}
793 inlines
= (PosteFinancementInline
,
796 PosteComparaisonInline
,
797 PosteCommentaireInline
, )
799 def lookup_allowed(self
, key
, value
):
801 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
802 'date_fin__isnull', 'implantation__region__id__exact',
803 'implantation__id__exact', 'type_poste__id__exact',
804 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
805 'service__isnull', 'vacant__exact', 'vacant__isnull',
806 ) or super(PosteAdmin
, self
).lookup_allowed(key
, value
)
808 def _apercu(self
, poste
):
809 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);"
810 title="Aperçu du poste"
812 <img src="%simg/loupe.png" />
814 (reverse('poste_apercu', args
=(poste
.id,)),
815 settings
.STATIC_URL
,)
817 _apercu
.allow_tags
= True
818 _apercu
.short_description
= ''
820 def _dae(self
, poste
):
822 postes_dae
= poste
.postes_dae
.all()
823 if len(postes_dae
) > 0:
824 poste_dae
= postes_dae
[0]
826 u
'<a title="Aperçu du dossier" href="%s" ' \
827 u
'onclick="return showAddAnotherPopup(this);">' \
828 u
'<img src="%simg/loupe.png" /></a>' % (reverse(
829 'poste_consulter', args
=("dae-%s" % poste_dae
.id,)
830 ), settings
.STATIC_URL
)
832 _dae
.allow_tags
= True
833 _dae
.short_description
= u
"DAE"
837 _id
.short_description
= '#'
838 _id
.admin_order_field
= 'id'
840 def _service(self
, obj
):
841 if obj
.service
.supprime
:
842 return """<span style="color:red">%s</span>""" % obj
.service
845 _service
.short_description
= 'Service'
846 _service
.allow_tags
= True
848 def _responsable(self
, obj
):
850 responsable
= u
"""<a href="%s"
851 onclick="return showAddAnotherPopup(this)">
852 <img src="%simg/loupe.png"
853 title="Aperçu du poste" />
857 (reverse('poste_apercu', args
=(obj
.responsable
.id,)),
859 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
865 employe
= obj
.responsable
.rh_dossiers
.all()[0]
866 employe_id
= obj
.responsable
.rh_dossiers
.all()[0].id
867 employe_html
= u
"""<br />
869 onclick="return showAddAnotherPopup(this)">
870 <img src="%simg/loupe.png"
871 title="Aperçu de l'employé">
873 <a href="%s">%s</a>""" % \
874 (reverse('employe_apercu', args
=(employe_id
,)),
876 reverse('admin:rh_employe_change', args
=(employe_id
,)),
881 return "%s %s" % (responsable
, employe_html
)
882 _responsable
.short_description
= 'Responsable'
883 _responsable
.allow_tags
= True
885 def _nom(self
, poste
):
886 return """<a href="%s">%s</a>""" % \
887 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
889 _nom
.allow_tags
= True
890 _nom
.short_description
= u
'Nom'
891 _nom
.admin_order_field
= 'nom'
893 def _date_modification(self
, obj
):
894 return date(obj
.date_modification
)
895 _date_modification
.short_description
= u
'date modification'
896 _date_modification
.admin_order_field
= 'date_modification'
898 def _occupe_par(self
, obj
):
899 """Formatte la méthode Poste.occupe_par() pour l'admin"""
901 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.today():
903 employes
= obj
.occupe_par()
907 link
= u
"""<a href='%s'
908 title='Aperçu de l\'employer'
909 onclick='return showAddAnotherPopup(this)'>
910 <img src='%simg/loupe.png' />
912 <a href='%s'>%s</a>""" % \
913 (reverse('employe_apercu', args
=(e
.id,)),
915 reverse('admin:rh_employe_change', args
=(e
.id,)),
918 output
= "\n<br />".join(l
)
920 _occupe_par
.allow_tags
= True
921 _occupe_par
.short_description
= "Occupé par"
923 def save_formset(self
, request
, form
, formset
, change
):
924 instances
= formset
.save(commit
=False)
925 for instance
in instances
:
926 if instance
.__class__
== rh
.PosteCommentaire
:
927 instance
.owner
= request
.user
928 instance
.date_creation
= datetime
.datetime
.now()
933 class PosteCommentaireAdmin(admin
.ModelAdmin
):
937 class PosteFinancementAdmin(admin
.ModelAdmin
):
941 class PostePieceAdmin(admin
.ModelAdmin
):
945 class RemunerationAdmin(admin
.ModelAdmin
):
949 class ResponsableInline(admin
.TabularInline
):
950 model
= rh
.ResponsableImplantation
952 fk_name
= "implantation"
955 class ResponsableImplantationAdmin(admin
.ModelAdmin
):
957 list_filter
= ('region', 'statut', )
958 list_display
= ('nom', 'statut', '_responsable', )
959 readonly_fields
= ('nom', )
961 inlines
= (ResponsableInline
, )
963 def _responsable(self
, obj
):
965 employe
= obj
.responsable
.employe
966 dossiers
= employe
.dossiers_encours()
967 if len(dossiers
) == 0:
968 return u
"<span style='color: red;'>%s %s </span>" % (
969 employe
, u
"sans dossier actif")
973 if obj
.statut
in (1, 2): # ouverte, ouverture imminente
974 css
= "style='color: red;'"
977 return u
"<span %s>Pas de responsable</span>" % css
978 _responsable
.allow_tags
= True
979 _responsable
.short_description
= u
"Responsable"
981 def has_add_permission(self
, request
=None):
984 def has_change_permission(self
, request
, obj
=None):
985 return in_drh_or_admin(request
.user
)
987 def has_delete_permission(self
, request
, obj
=None):
991 class ServiceAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
, ArchiveMixin
):
995 '_date_modification',
998 list_filter
= ('archive', )
999 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1001 'fields': ('nom', 'archive', ),
1005 def _date_modification(self
, obj
):
1006 return date(obj
.date_modification
) \
1007 if obj
.date_modification
is not None else "(aucune)"
1008 _date_modification
.short_description
= u
'date modification'
1009 _date_modification
.admin_order_field
= 'date_modification'
1012 class ServiceProxyAdmin(ServiceAdmin
):
1013 list_display
= ('nom', '_organigramme', '_archive', )
1016 def __init__(self
, *args
, **kwargs
):
1017 super(ServiceProxyAdmin
, self
).__init__(*args
, **kwargs
)
1018 self
.list_display_links
= (None, )
1020 def has_add_permission(self
, obj
):
1023 def has_change_permission(self
, request
, obj
=None):
1024 return in_drh_or_admin(request
.user
)
1026 def _organigramme(self
, obj
):
1027 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1028 (reverse('rho_service', args
=(obj
.id,)))
1029 _organigramme
.allow_tags
= True
1030 _organigramme
.short_description
= "Organigramme"
1033 class StatutAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1034 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
1035 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1037 'fields': ('code', 'nom', ),
1041 def _date_modification(self
, obj
):
1042 return date(obj
.date_modification
) \
1043 if obj
.date_modification
is not None else "(aucune)"
1044 _date_modification
.short_description
= u
'date modification'
1045 _date_modification
.admin_order_field
= 'date_modification'
1048 class TauxChangeAdmin(admin
.ModelAdmin
):
1053 '_date_modification',
1054 'user_modification',
1056 list_filter
= ('devise', )
1057 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1059 'fields': ('taux', 'devise', 'annee', ),
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 TypeContratAdmin(admin
.ModelAdmin
):
1074 '_date_modification',
1075 'user_modification',
1077 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1079 'fields': ('nom', 'nom_long', ),
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 TypePosteAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1091 search_fields
= ('nom', 'nom_feminin', )
1095 '_date_modification',
1096 'user_modification',
1098 list_filter
= ('categorie_emploi', 'famille_professionnelle')
1099 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1106 'famille_professionnelle',
1111 def _date_modification(self
, obj
):
1112 return date(obj
.date_modification
) \
1113 if obj
.date_modification
is not None else "(aucune)"
1114 _date_modification
.short_description
= u
'date modification'
1115 _date_modification
.admin_order_field
= 'date_modification'
1118 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
,
1123 'nature_remuneration',
1125 '_date_modification',
1126 'user_modification',)
1127 list_filter
= ('archive', )
1128 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1129 (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration',
1133 def _date_modification(self
, obj
):
1134 return date(obj
.date_modification
) \
1135 if obj
.date_modification
is not None else "(aucune)"
1136 _date_modification
.short_description
= u
'date modification'
1137 _date_modification
.admin_order_field
= 'date_modification'
1140 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1141 list_display
= ('nom', '_date_modification', 'user_modification', )
1142 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1143 (None, {'fields': ('nom', )}),
1146 def _date_modification(self
, obj
):
1147 return date(obj
.date_modification
) \
1148 if obj
.date_modification
is not None else "(aucune)"
1149 _date_modification
.short_description
= u
'date modification'
1150 _date_modification
.admin_order_field
= 'date_modification'
1153 class ValeurPointAdmin(AUFMetadataAdminMixin
, admin
.ModelAdmin
):
1160 '_date_modification',
1161 'user_modification',
1163 list_filter
= ('annee', 'devise', 'implantation__region', )
1164 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1165 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}),
1168 def _date_modification(self
, obj
):
1169 return date(obj
.date_modification
) \
1170 if obj
.date_modification
is not None else "(aucune)"
1171 _date_modification
.short_description
= u
'date modification'
1172 _date_modification
.admin_order_field
= 'date_modification'
1174 def _devise_code(self
, obj
):
1175 return obj
.devise
.code
1176 _devise_code
.short_description
= "Code de la devise"
1178 def _devise_nom(self
, obj
):
1179 return obj
.devise
.nom
1180 _devise_nom
.short_description
= "Nom de la devise"
1183 class ImplantationProxyAdmin(admin
.ModelAdmin
):
1184 list_display
= ('nom', '_organigramme')
1187 def __init__(self
, *args
, **kwargs
):
1188 super(ImplantationProxyAdmin
, self
).__init__(*args
, **kwargs
)
1189 self
.list_display_links
= (None, )
1191 def has_add_permission(self
, obj
):
1194 def has_change_permission(self
, request
, obj
=None):
1195 return in_drh_or_admin(request
.user
)
1197 def _organigramme(self
, obj
):
1198 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1199 reverse('rho_implantation', args
=(obj
.id,))
1201 _organigramme
.allow_tags
= True
1202 _organigramme
.short_description
= "Organigramme"
1205 class RegionProxyAdmin(admin
.ModelAdmin
):
1206 list_display
= ('nom', '_organigramme')
1209 def __init__(self
, *args
, **kwargs
):
1210 super(RegionProxyAdmin
, self
).__init__(*args
, **kwargs
)
1211 self
.list_display_links
= (None, )
1213 def has_add_permission(self
, obj
):
1216 def has_change_permission(self
, request
, obj
=None):
1217 return in_drh_or_admin(request
.user
)
1219 def _organigramme(self
, obj
):
1220 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1221 reverse('rho_region', args
=(obj
.id,))
1223 _organigramme
.allow_tags
= True
1224 _organigramme
.short_description
= "Organigramme"
1227 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
1228 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
1229 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
1230 admin
.site
.register(EmployeProxy
, EmployeProxyAdmin
)
1231 admin
.site
.register(ServiceProxy
, ServiceProxyAdmin
)
1232 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
1233 admin
.site
.register(rh
.CategorieEmploi
, CategorieEmploiAdmin
)
1234 admin
.site
.register(rh
.FamilleProfessionnelle
)
1235 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
1236 admin
.site
.register(rh
.Poste
, PosteAdmin
)
1237 admin
.site
.register(
1238 rh
.ResponsableImplantationProxy
, ResponsableImplantationAdmin
1240 admin
.site
.register(rh
.Service
, ServiceAdmin
)
1241 admin
.site
.register(rh
.Statut
, StatutAdmin
)
1242 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
1243 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
1244 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
1245 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
1246 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
1247 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)
1248 admin
.site
.register(ImplantationProxy
, ImplantationProxyAdmin
)
1249 admin
.site
.register(RegionProxy
, RegionProxyAdmin
)