1 # -*- encoding: utf-8 -*-
5 from django
.core
.urlresolvers
import reverse
6 from django
.contrib
import admin
7 from django
.conf
import settings
8 from django
.db
.models
import Q
, Count
9 from django
.template
.defaultfilters
import date
10 from django
.utils
.formats
import date_format
12 from ajax_select
import make_ajax_form
14 from auf
.django
.metadata
.admin
import \
15 AUFMetadataAdminMixin
, AUFMetadataInlineAdminMixin
, \
16 AUF_METADATA_READONLY_FIELDS
17 import auf
.django
.references
.models
as ref
19 from project
.decorators
import in_drh_or_admin
20 from project
.groups
import grp_correspondants_rh
21 from project
.groups
import get_employe_from_user
23 import project
.rh
.models
as rh
24 from project
.rh
.forms
import ContratForm
, AyantDroitForm
, EmployeAdminForm
, \
25 AjaxSelect
, DossierForm
, ResponsableInlineForm
27 from project
.rh
.change_list
import ChangeList
30 class BaseAdmin(admin
.ModelAdmin
):
34 'css/admin_custom.css',
35 'jquery-autocomplete/jquery.autocomplete.css',
38 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
39 'jquery-autocomplete/jquery.autocomplete.min.js',
43 class ArchiveMixin(object):
45 Archive Mixin pour gérer le queryset et le display
46 NON COMPRIS : list_filter, et list_display, field à setter dans la classe.
49 def queryset(self
, request
):
50 return self
.model
._base_manager
52 def _archive(self
, obj
):
57 _archive
.short_description
= u
'Archivé'
58 _archive
.admin_order_field
= 'archive'
61 class RegionProxy(ref
.Region
):
62 """ Proxy utilisé pour les organigrammes par région """
65 verbose_name
= u
"Organigramme par région"
66 verbose_name_plural
= u
"Organigramme par région"
69 class ImplantationProxy(ref
.Implantation
):
70 """ Proxy utilisé pour les organigrammes par implantation """
73 verbose_name
= u
"Organigramme par implantations"
74 verbose_name_plural
= u
"Organigramme par implantations"
77 class ServiceProxy(rh
.Service
):
78 """ Proxy utilisé pour les organigrammes opar service """
82 verbose_name
= u
"Organigramme par services"
83 verbose_name_plural
= u
"Organigramme par services"
86 class EmployeProxy(rh
.Employe
):
87 """ Proxy utilisé pour les organigrammes des employés """
90 verbose_name
= u
"Organigramme des employés"
91 verbose_name_plural
= u
"Organigramme des employés"
94 class DateRangeMixin(object):
95 prefixe_recherche_temporelle
= ""
97 def get_changelist(self
, request
, **kwargs
):
98 if 'HTTP_REFERER' in request
.META
.keys():
99 referer
= request
.META
['HTTP_REFERER']
100 referer
= "/".join(referer
.split('/')[3:])
101 referer
= "/%s" % referer
.split('?')[0]
102 change_list_view
= 'admin:%s_%s_changelist' % (
103 self
.model
._meta
.app_label
,
104 self
.model
.__name__
.lower(),)
105 if referer
!= reverse(change_list_view
):
106 params
= request
.GET
.copy()
107 params
.update({'statut': 'Actif'})
112 # Override of the InlineModelAdmin to support the link in the tabular inline
113 class LinkedInline(admin
.options
.InlineModelAdmin
):
114 template
= "admin/linked.html"
115 admin_model_path
= None
117 def __init__(self
, *args
):
118 super(LinkedInline
, self
).__init__(*args
)
119 if self
.admin_model_path
is None:
120 self
.admin_model_path
= self
.model
.__name__
.lower()
123 class ProtectRegionMixin(object):
125 def queryset(self
, request
):
126 qs
= super(ProtectRegionMixin
, self
).queryset(request
)
128 user_groups
= request
.user
.groups
.all()
129 if in_drh_or_admin(request
.user
):
132 if grp_correspondants_rh
in user_groups
:
133 employe
= get_employe_from_user(request
.user
)
134 q
= Q(**{self
.model
.prefix_implantation
: \
135 employe
.implantation
.region
})
136 qs
= qs
.filter(q
).distinct()
140 def has_add_permission(self
, request
):
141 if not in_drh_or_admin(request
.user
):
146 def has_change_permission(self
, request
, obj
=None):
147 user_groups
= request
.user
.groups
.all()
149 # Lock pour autoriser uniquement les DRH à utiliser RH
150 if not in_drh_or_admin(request
.user
):
153 if len(user_groups
) == 0 and not request
.user
.is_superuser
:
158 ids
= [o
.id for o
in self
.queryset(request
)]
164 class ReadOnlyInlineMixin(object):
166 def get_readonly_fields(self
, request
, obj
=None):
167 return [f
.name
for f
in self
.model
._meta
.fields \
168 if f
.name
not in AUF_METADATA_READONLY_FIELDS
]
171 class AyantDroitInline(AUFMetadataInlineAdminMixin
, admin
.StackedInline
):
172 model
= rh
.AyantDroit
173 form
= AyantDroitForm
180 ('nom_affichage', 'genre'),
188 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin
, \
189 admin
.TabularInline
):
190 readonly_fields
= ('owner', )
191 model
= rh
.AyantDroitCommentaire
195 class ContratInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
201 class DossierROInline(ReadOnlyInlineMixin
, LinkedInline
):
202 template
= "admin/rh/dossier/linked.html"
203 exclude
= AUF_METADATA_READONLY_FIELDS
208 def has_add_permission(self
, request
=None):
211 def has_change_permission(self
, request
, obj
=None):
214 def has_delete_permission(self
, request
, obj
=None):
218 class DossierCommentaireInline(AUFMetadataInlineAdminMixin
, \
219 admin
.TabularInline
):
220 readonly_fields
= ('owner', )
221 model
= rh
.DossierCommentaire
225 class DossierPieceInline(admin
.TabularInline
):
226 model
= rh
.DossierPiece
230 class EmployeInline(admin
.TabularInline
):
234 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin
, \
235 admin
.TabularInline
):
236 readonly_fields
= ('owner', )
237 model
= rh
.EmployeCommentaire
241 class EmployePieceInline(admin
.TabularInline
):
242 model
= rh
.EmployePiece
246 class PosteCommentaireInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
247 readonly_fields
= ('owner', )
248 model
= rh
.PosteCommentaire
252 class PosteFinancementInline(admin
.TabularInline
):
253 model
= rh
.PosteFinancement
256 class PostePieceInline(admin
.TabularInline
):
257 model
= rh
.PostePiece
260 class RemunerationInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
261 model
= rh
.Remuneration
265 class RemunerationROInline(ReadOnlyInlineMixin
, RemunerationInline
):
269 class TypePosteInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
273 class PosteComparaisonInline(AUFMetadataInlineAdminMixin
, admin
.TabularInline
):
274 model
= rh
.PosteComparaison
277 class ClassementAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
278 list_display
= ('_classement', '_date_modification', 'user_modification', )
279 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
281 'fields': ('type', 'echelon', 'degre', 'coefficient',)}),
284 def _classement(self
, obj
):
286 _classement
.short_description
= u
"Classement"
288 def _date_modification(self
, obj
):
289 return date(obj
.date_modification
) \
290 if obj
.date_modification
is not None else "(aucune)"
291 _date_modification
.short_description
= u
'date modification'
292 _date_modification
.admin_order_field
= 'date_modification'
295 class DeviseAdmin(AUFMetadataAdminMixin
, BaseAdmin
, ArchiveMixin
):
300 '_date_modification',
303 list_filter
= ('archive', )
304 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
306 'fields': ('code', 'nom', 'archive', ),
310 def _date_modification(self
, obj
):
311 return date(obj
.date_modification
) \
312 if obj
.date_modification
is not None else "(aucune)"
313 _date_modification
.short_description
= u
'date modification'
314 _date_modification
.admin_order_field
= 'date_modification'
317 class DossierAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
318 ProtectRegionMixin
, BaseAdmin
, AjaxSelect
):
319 alphabet_filter
= 'employe__nom'
327 'poste__nom_feminin',
328 'poste__implantation__nom',
340 '_date_modification',
343 list_display_links
= ('_nom',)
345 'poste__implantation__region',
346 'poste__implantation',
347 'poste__type_poste__categorie_emploi',
349 'rh_contrats__type_contrat',
352 inlines
= (DossierPieceInline
, ContratInline
,
354 DossierCommentaireInline
,
356 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
363 'organisme_bstg',)}),
368 'remplacement_de', )}),
372 ('regime_travail', 'regime_travail_nb_heure_semaine'),)}),
373 ('Occupation du Poste par cet Employe', {
374 'fields': (('date_debut', 'date_fin'), )}
377 form
= make_ajax_form(rh
.Dossier
, {
378 'employe': 'employes',
380 'remplacement_de': 'dossiers',
381 }, superclass
=DossierForm
)
383 def lookup_allowed(self
, key
, value
):
385 'employe__nom__istartswith',
386 'poste__implantation__region__id__exact',
387 'poste__implantation__id__exact',
388 'poste__type_poste__id__exact',
389 'poste__type_poste__categorie_emploi__id__exact',
390 'rh_contrats__type_contrat__id__exact',
398 _id
.short_description
= u
"#"
399 _id
.admin_order_field
= "id"
401 def _apercu(self
, d
):
402 apercu_link
= u
"""<a title="Aperçu du dossier"
403 onclick="return showAddAnotherPopup(this);"
405 <img src="%simg/dossier-apercu.png" />
407 (reverse('dossier_apercu', args
=(d
.id,)),
411 _apercu
.allow_tags
= True
412 _apercu
.short_description
= u
""
416 _nom
.allow_tags
= True
417 _nom
.short_description
= u
"Dossier"
419 def _employe(self
, obj
):
420 employe
= obj
.employe
421 view_link
= reverse('employe_apercu', args
=(employe
.id,))
422 edit_link
= reverse('admin:rh_employe_change', args
=(employe
.id,))
425 view
= u
"""<a href="%s"
426 title="Aperçu l'employé"
427 onclick="return showAddAnotherPopup(this);">
428 <img src="%simg/employe-apercu.png" />
429 </a>""" % (view_link
, settings
.STATIC_URL
,)
430 return u
"""%s<a href='%s' style="%s;">%s</a>""" % \
431 (view
, edit_link
, style
, employe
)
432 _employe
.allow_tags
= True
433 _employe
.short_description
= u
"Employé"
434 _employe
.admin_order_field
= "employe__nom"
436 def _poste(self
, dossier
):
437 link
= u
"""<a title="Aperçu du poste"
438 onclick="return showAddAnotherPopup(this);"
439 href='%s'><img src="%simg/poste-apercu.png" />
441 <a href="%s" title="Modifier le poste">%s [%d]</a>""" % \
442 (reverse('poste_apercu', args
=(dossier
.poste
.id,)),
444 reverse('admin:rh_poste_change', args
=(dossier
.poste
.id,)),
449 _poste
.allow_tags
= True
450 _poste
.short_description
= u
'Poste'
451 _poste
.admin_order_field
= 'poste__nom'
453 def _region(self
, obj
):
454 return obj
.poste
.implantation
.region
.code
455 _region
.short_description
= u
"Région"
456 _region
.admin_order_field
= 'poste__implantation__region__code'
458 def _implantation(self
, obj
):
459 return obj
.poste
.implantation
.nom
460 _implantation
.short_description
= u
"Implantation"
461 _implantation
.admin_order_field
= 'poste__implantation__nom'
463 def _date_debut(self
, obj
):
464 return date(obj
.date_debut
)
466 _date_debut
.short_description
= u
'Début'
467 _date_debut
.admin_order_field
= 'date_debut'
469 def _date_fin(self
, obj
):
470 return date(obj
.date_fin
)
471 _date_fin
.short_description
= u
'Fin'
472 _date_fin
.admin_order_field
= 'date_fin'
474 def _date_modification(self
, obj
):
475 return date(obj
.date_modification
) \
476 if obj
.date_modification
is not None else "(aucune)"
477 _date_modification
.short_description
= u
'date modification'
478 _date_modification
.admin_order_field
= 'date_modification'
482 dossiers_dae
= d
.dossiers_dae
.all()
483 if len(dossiers_dae
) > 0:
484 dossier_dae
= dossiers_dae
[0]
485 apercu_link
= u
"""<a title="Aperçu du dossier"
486 onclick="return showAddAnotherPopup(this);"
488 <img src="%simg/loupe.png" />
490 (reverse('embauche_consulter', args
=(dossier_dae
.id,)),
494 _dae
.allow_tags
= True
495 _dae
.short_description
= u
"DAE"
497 def save_formset(self
, request
, form
, formset
, change
):
498 instances
= formset
.save(commit
=False)
499 for instance
in instances
:
500 if instance
.__class__
== rh
.DossierCommentaire
:
501 instance
.owner
= request
.user
502 instance
.date_creation
= datetime
.datetime
.now()
506 class EmployeAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
507 ProtectRegionMixin
, BaseAdmin
):
508 prefixe_recherche_temporelle
= "rh_dossiers__"
509 alphabet_filter
= 'nom'
510 DEFAULT_ALPHABET
= u
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
512 'id', 'nom', 'prenom', 'nom_affichage',
513 'rh_dossiers__poste__nom',
514 'rh_dossiers__poste__nom_feminin'
517 form
= EmployeAdminForm
526 '_date_modification',
528 list_display_links
= ('_nom',)
530 'rh_dossiers__poste__implantation__region',
531 'rh_dossiers__poste__implantation',
534 inlines
= (AyantDroitInline
,
537 EmployeCommentaireInline
)
538 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
542 ('nom_affichage', 'genre'),
547 ('Informations personnelles', {
548 'fields': ('situation_famille', 'date_entree', )}
550 ('Coordonnées personnelles', {
552 ('tel_domicile', 'tel_cellulaire'),
553 ('adresse', 'ville'),
554 ('code_postal', 'province'),
563 _id
.short_description
= u
"#"
564 _id
.admin_order_field
= "id"
566 def _apercu(self
, obj
):
567 return u
"""<a title="Aperçu de l'employé"
568 onclick="return showAddAnotherPopup(this);"
570 <img src="%simg/employe-apercu.png" />
572 (reverse('employe_apercu', args
=(obj
.id,)), settings
.STATIC_URL
)
573 _apercu
.allow_tags
= True
574 _apercu
.short_description
= u
""
577 edit_link
= reverse('admin:rh_employe_change', args
=(obj
.id,))
578 return u
"""<a href='%s'><strong>%s</strong></a>""" % \
579 (edit_link
, "%s %s" % (obj
.nom
.upper(), obj
.prenom
))
580 _nom
.allow_tags
= True
581 _nom
.short_description
= u
"Employé"
582 _nom
.admin_order_field
= "nom"
584 def _region(self
, obj
):
586 d
= rh
.Dossier
.objects
.filter(employe
=obj
.id, principal
=True)[0]
587 region
= d
.poste
.implantation
.region
.code
591 _region
.short_description
= u
"Région"
593 def _implantation(self
, obj
):
595 d
= rh
.Dossier
.objects
.filter(employe
=obj
.id, principal
=True)[0]
596 implantation
= d
.poste
.implantation
.nom
600 _implantation
.short_description
= u
"Implantation"
602 def _dossiers_postes(self
, obj
):
604 for d
in obj
.rh_dossiers
.all().order_by('-date_debut'):
608 if d
.date_fin
is not None and d
.date_fin
< datetime
.date
.today():
610 link_style
= u
' style="color:#666;"'
611 list_style
= u
' style="color:grey;"'
613 dossier
= u
"""<a title="Aperçu du dossier"
615 onclick="return showAddAnotherPopup(this);"
616 title="Aperçu du dossier">
617 <img src="%simg/dossier-apercu.png" />
619 <a href="%s"%s>Dossier</a>
621 (reverse('dossier_apercu', args
=(d
.id,)),
623 reverse('admin:rh_dossier_change', args
=(d
.id,)),
626 poste
= u
"""<a title="Aperçu du poste"
628 onclick="return showAddAnotherPopup(this);"
629 title="Aperçu du poste">
630 <img src="%simg/poste-apercu.png" />
632 <a href="%s"%s>%s [%d]</a>
634 (reverse('poste_apercu', args
=(d
.poste
.id,)),
636 reverse('admin:rh_poste_change', args
=(d
.poste
.id,)),
641 link
= u
"""<li%s>%s %s</li>""" % \
642 (list_style
, dossier
, poste
)
645 return "<ul>%s</ul>" % "\n".join(l
)
646 _dossiers_postes
.allow_tags
= True
647 _dossiers_postes
.short_description
= u
"Dossiers et postes"
649 def _date_modification(self
, obj
):
650 return date(obj
.date_modification
) \
651 if obj
.date_modification
is not None else "(aucune)"
652 _date_modification
.short_description
= u
'date modification'
653 _date_modification
.admin_order_field
= 'date_modification'
655 def queryset(self
, request
):
656 qs
= super(EmployeAdmin
, self
).queryset(request
)
657 return qs
.select_related(depth
=1).order_by('nom')
659 def save_formset(self
, request
, form
, formset
, change
):
660 instances
= formset
.save(commit
=False)
661 for instance
in instances
:
662 if instance
.__class__
== rh
.EmployeCommentaire
:
663 instance
.owner
= request
.user
664 instance
.date_creation
= datetime
.datetime
.now()
668 class EmployeProxyAdmin(EmployeAdmin
):
669 list_display
= ('_id', '_apercu', '_nom', '_organigramme')
672 def __init__(self
, *args
, **kwargs
):
673 super(EmployeProxyAdmin
, self
).__init__(*args
, **kwargs
)
674 self
.list_display_links
= (None, )
676 def has_add_permission(self
, obj
):
679 def _organigramme(self
, obj
):
681 for d
in rh
.Dossier
.objects
.filter(
682 Q(date_fin__gt
=datetime
.date
.today()) |
Q(date_fin
=None),
683 Q(date_debut__lt
=datetime
.date
.today()) |
Q(date_debut
=None),
687 u
'Organigramme, niveau: ' \
688 u
'<input type="text" id="level_%s" ' \
689 u
'style="width:30px;height:15px;" /> ' \
690 u
'<input type="button" value="Générer" ' \
691 u
"""onclick="window.location='%s' + """ \
692 u
"""document.getElementById('level_%s').value" />""" % (
694 reverse('rho_employe_sans_niveau', args
=(d
.poste
.id,)),
697 link
= u
"""<li>%s - [%s] %s : %s</li>""" % (
704 return "<ul>%s</ul>" % "\n".join(l
)
706 _organigramme
.allow_tags
= True
707 _organigramme
.short_description
= "Organigramme"
710 class CategorieEmploiAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
711 list_display
= ('nom', '_date_modification', 'user_modification', )
712 inlines
= (TypePosteInline
,)
713 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
714 (None, {'fields': ('nom', )}),)
716 def _date_modification(self
, obj
):
717 return date(obj
.date_modification
) \
718 if obj
.date_modification
is not None else "(aucune)"
719 _date_modification
.short_description
= u
'date modification'
720 _date_modification
.admin_order_field
= 'date_modification'
723 class OrganismeBstgAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
724 search_fields
= ('nom',)
729 '_date_modification',
732 list_filter
= ('type', )
733 inlines
= (DossierROInline
,)
734 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
735 (None, {'fields': ('nom', 'type', 'pays',)}),
738 def _date_modification(self
, obj
):
739 return date(obj
.date_modification
) \
740 if obj
.date_modification
is not None else "(aucune)"
741 _date_modification
.short_description
= u
'date modification'
742 _date_modification
.admin_order_field
= 'date_modification'
745 class PosteAdmin(DateRangeMixin
, AUFMetadataAdminMixin
,
746 ProtectRegionMixin
, BaseAdmin
, AjaxSelect
):
747 form
= make_ajax_form(rh
.Poste
, {
748 'implantation': 'implantations',
749 'type_poste': 'typepostes',
750 'responsable': 'postes',
751 'valeur_point_min': 'valeurpoints',
752 'valeur_point_max': 'valeurpoints',
754 alphabet_filter
= 'nom'
759 'implantation__region__code',
760 'implantation__region__nom',
761 'rh_dossiers__employe__id',
762 'rh_dossiers__employe__nom',
763 'rh_dossiers__employe__prenom',
776 '_date_modification',
780 'implantation__region',
784 'type_poste__categorie_emploi',
785 'type_poste__famille_professionnelle',
788 list_display_links
= ('_nom',)
789 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
791 ('nom', 'nom_feminin'),
801 'regime_travail_nb_heure_semaine'),
805 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)}
808 'fields': (('classement_min',
821 ('Comparatifs de rémunération', {
822 'fields': ('devise_comparaison',
823 ('comp_locale_min', 'comp_locale_max'),
824 ('comp_universite_min', 'comp_universite_max'),
825 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
826 ('comp_ong_min', 'comp_ong_max'),
827 ('comp_autre_min', 'comp_autre_max'))}
830 'fields': ('justification',)}
832 ('Autres Méta-données', {
833 'fields': ('date_debut', 'date_fin')}
837 inlines
= (PosteFinancementInline
,
840 PosteComparaisonInline
,
841 PosteCommentaireInline
, )
843 def lookup_allowed(self
, key
, value
):
845 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
846 'date_fin__isnull', 'implantation__region__id__exact',
847 'implantation__id__exact', 'type_poste__id__exact',
848 'type_poste__categorie_emploi__id__exact', 'service__id__exact',
849 'service__isnull', 'vacant__exact', 'vacant__isnull',
850 ) or super(PosteAdmin
, self
).lookup_allowed(key
, value
)
854 _id
.short_description
= '#'
855 _id
.admin_order_field
= 'id'
857 def _apercu(self
, poste
):
858 view_link
= u
"""<a onclick="return showAddAnotherPopup(this);"
859 title="Aperçu du poste"
861 <img src="%simg/poste-apercu.png" />
863 (reverse('poste_apercu', args
=(poste
.id,)),
864 settings
.STATIC_URL
,)
866 _apercu
.allow_tags
= True
867 _apercu
.short_description
= ''
869 def _nom(self
, poste
):
870 return """<a href="%s">%s</a>""" % \
871 (reverse('admin:rh_poste_change', args
=(poste
.id,)),
873 _nom
.allow_tags
= True
874 _nom
.short_description
= u
'Poste'
875 _nom
.admin_order_field
= 'nom'
877 def _occupe_par(self
, obj
):
878 """Formatte la méthode Poste.occupe_par() pour l'admin"""
880 if obj
.date_fin
is not None and obj
.date_fin
< datetime
.date
.today():
882 employes
= obj
.occupe_par()
886 link
= u
"""<a href='%s'
887 title='Aperçu de l\'employé'
888 onclick='return showAddAnotherPopup(this)'>
889 <img src='%simg/employe-apercu.png' />
891 <a href='%s'>%s</a>""" % \
892 (reverse('employe_apercu', args
=(e
.id,)),
894 reverse('admin:rh_employe_change', args
=(e
.id,)),
897 output
= "\n<br />".join(l
)
899 _occupe_par
.allow_tags
= True
900 _occupe_par
.short_description
= "Occupé par"
902 def _region(self
, poste
):
903 return poste
.implantation
.region
.code
904 _region
.short_description
= 'Région'
905 _region
.admin_order_field
= 'implantation__region__code'
907 def _implantation(self
, poste
):
908 return poste
.implantation
.nom
909 _implantation
.short_description
= 'Implantation'
910 _implantation
.admin_order_field
= 'implantation'
912 def _service(self
, obj
):
913 if obj
.service
.supprime
:
914 return """<span style="color:red">%s</span>""" % obj
.service
917 _service
.short_description
= 'Service'
918 _service
.allow_tags
= True
920 def _responsable(self
, obj
):
922 responsable
= u
"""<a href="%s"
923 onclick="return showAddAnotherPopup(this)">
924 <img src="%simg/poste-apercu.png"
925 title="Aperçu du poste" />
927 <a href="%s">%s [%d]</a>
929 (reverse('poste_apercu', args
=(obj
.responsable
.id,)),
931 reverse('admin:rh_poste_change', args
=(obj
.responsable
.id,)),
938 dossier
= obj
.responsable
.rh_dossiers
.all().order_by('-date_debut')[0]
939 employe_id
= dossier
.employe
.id
940 employe_html
= u
"""<br />
942 onclick="return showAddAnotherPopup(this)">
943 <img src="%simg/employe-apercu.png"
944 title="Aperçu de l'employé">
946 <a href="%s">%s</a>""" % \
947 (reverse('employe_apercu', args
=(employe_id
,)),
949 reverse('admin:rh_employe_change', args
=(employe_id
,)),
954 return "%s %s" % (responsable
, employe_html
)
955 _responsable
.short_description
= 'Responsable'
956 _responsable
.allow_tags
= True
958 def _date_debut(self
, obj
):
959 return date_format(obj
.date_debut
)
960 _date_debut
.short_description
= u
'Début'
961 _date_debut
.admin_order_field
= 'date_debut'
963 def _date_fin(self
, obj
):
964 return date_format(obj
.date_fin
)
965 _date_fin
.short_description
= u
'Fin'
966 _date_fin
.admin_order_field
= 'date_fin'
968 def _date_modification(self
, obj
):
969 return date(obj
.date_modification
)
970 _date_modification
.short_description
= u
'date modification'
971 _date_modification
.admin_order_field
= 'date_modification'
973 def _dae(self
, poste
):
975 postes_dae
= poste
.postes_dae
.all()
976 if len(postes_dae
) > 0:
977 poste_dae
= postes_dae
[0]
979 u
'<a title="Aperçu du dossier" href="%s" ' \
980 u
'onclick="return showAddAnotherPopup(this);">' \
981 u
'<img src="%simg/loupe.png" /></a>' % (reverse(
982 'poste_consulter', args
=("dae-%s" % poste_dae
.id,)
983 ), settings
.STATIC_URL
)
985 _dae
.allow_tags
= True
986 _dae
.short_description
= u
"DAE"
988 def save_formset(self
, request
, form
, formset
, change
):
989 instances
= formset
.save(commit
=False)
990 for instance
in instances
:
991 if instance
.__class__
== rh
.PosteCommentaire
:
992 instance
.owner
= request
.user
993 instance
.date_creation
= datetime
.datetime
.now()
998 class ResponsableInline(admin
.TabularInline
):
999 model
= rh
.ResponsableImplantation
1001 fk_name
= "implantation"
1002 form
= ResponsableInlineForm
1005 class ResponsableImplantationAdmin(BaseAdmin
):
1008 inlines
= (ResponsableInline
, )
1009 list_filter
= ('region', 'statut', )
1010 list_display
= ('_region', '_nom', 'statut', '_responsable', )
1011 list_display_links
= ('_nom',)
1012 readonly_fields
= ('nom', )
1015 'responsable__employe__id',
1016 'responsable__employe__nom',
1017 'responsable__employe__prenom',
1021 def _region(self
, obj
):
1022 return obj
.region
.code
1023 _region
.short_description
= u
"Région"
1024 _region
.admin_order_field
= 'region__code'
1026 def _nom(self
, obj
):
1028 _nom
.short_description
= u
"Implantation"
1029 _nom
.admin_order_field
= 'nom'
1031 def _responsable(self
, obj
):
1033 employe
= obj
.responsable
.employe
1034 dossiers
= employe
.dossiers_encours()
1035 if len(dossiers
) == 0:
1036 return u
"<span style='color: red;'>%s %s </span>" % (
1037 employe
, u
"sans dossier actif")
1041 if obj
.statut
in (1, 2): # ouverte, ouverture imminente
1042 css
= "style='color: red;'"
1045 return u
"<span %s>Pas de responsable</span>" % css
1046 _responsable
.allow_tags
= True
1047 _responsable
.short_description
= u
"Responsable"
1048 _responsable
.admin_order_field
= 'responsable__employe__nom'
1050 def has_add_permission(self
, request
=None):
1053 def has_change_permission(self
, request
, obj
=None):
1054 return in_drh_or_admin(request
.user
)
1056 def has_delete_permission(self
, request
, obj
=None):
1060 class ServiceAdmin(AUFMetadataAdminMixin
, BaseAdmin
, ArchiveMixin
):
1064 '_date_modification',
1065 'user_modification',
1067 list_filter
= ('archive', )
1068 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1070 'fields': ('nom', 'archive', ),
1074 def _date_modification(self
, obj
):
1075 return date(obj
.date_modification
) \
1076 if obj
.date_modification
is not None else "(aucune)"
1077 _date_modification
.short_description
= u
'date modification'
1078 _date_modification
.admin_order_field
= 'date_modification'
1081 class ServiceProxyAdmin(ServiceAdmin
):
1082 list_display
= ('nom', '_organigramme', '_archive', )
1085 def __init__(self
, *args
, **kwargs
):
1086 super(ServiceProxyAdmin
, self
).__init__(*args
, **kwargs
)
1087 self
.list_display_links
= (None, )
1089 def queryset(self
, request
):
1090 return super(ServiceProxyAdmin
, self
).queryset(request
) \
1091 .annotate(num_postes
=Count('rh_postes')) \
1092 .filter(num_postes__gt
=0)
1094 def has_add_permission(self
, obj
):
1097 def has_change_permission(self
, request
, obj
=None):
1098 return in_drh_or_admin(request
.user
)
1100 def _organigramme(self
, obj
):
1101 return """<a href="%s"><strong>Organigramme</strong></a>""" % \
1102 (reverse('rho_service', args
=(obj
.id,)))
1103 _organigramme
.allow_tags
= True
1104 _organigramme
.short_description
= "Organigramme"
1107 class StatutAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1108 list_display
= ('code', 'nom', '_date_modification', 'user_modification', )
1109 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1111 'fields': ('code', 'nom', ),
1115 def _date_modification(self
, obj
):
1116 return date(obj
.date_modification
) \
1117 if obj
.date_modification
is not None else "(aucune)"
1118 _date_modification
.short_description
= u
'date modification'
1119 _date_modification
.admin_order_field
= 'date_modification'
1122 class TauxChangeAdmin(BaseAdmin
):
1127 '_date_modification',
1128 'user_modification',
1130 list_filter
= ('devise', )
1131 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1133 'fields': ('taux', 'devise', 'annee', ),
1137 def _date_modification(self
, obj
):
1138 return date(obj
.date_modification
) \
1139 if obj
.date_modification
is not None else "(aucune)"
1140 _date_modification
.short_description
= u
'date modification'
1141 _date_modification
.admin_order_field
= 'date_modification'
1144 class TypeContratAdmin(BaseAdmin
):
1148 '_date_modification',
1149 'user_modification',
1151 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1153 'fields': ('nom', 'nom_long', ),
1157 def _date_modification(self
, obj
):
1158 return date(obj
.date_modification
) \
1159 if obj
.date_modification
is not None else "(aucune)"
1160 _date_modification
.short_description
= u
'date modification'
1161 _date_modification
.admin_order_field
= 'date_modification'
1164 class TypePosteAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1165 search_fields
= ('nom', 'nom_feminin', )
1169 '_date_modification',
1170 'user_modification',
1172 list_filter
= ('categorie_emploi', 'famille_professionnelle')
1173 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1180 'famille_professionnelle',
1185 def _date_modification(self
, obj
):
1186 return date(obj
.date_modification
) \
1187 if obj
.date_modification
is not None else "(aucune)"
1188 _date_modification
.short_description
= u
'date modification'
1189 _date_modification
.admin_order_field
= 'date_modification'
1192 class TypeRemunerationAdmin(AUFMetadataAdminMixin
, BaseAdmin
,
1197 'nature_remuneration',
1199 '_date_modification',
1200 'user_modification',)
1201 list_filter
= ('archive', )
1202 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1203 (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration',
1207 def _date_modification(self
, obj
):
1208 return date(obj
.date_modification
) \
1209 if obj
.date_modification
is not None else "(aucune)"
1210 _date_modification
.short_description
= u
'date modification'
1211 _date_modification
.admin_order_field
= 'date_modification'
1214 class TypeRevalorisationAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1215 list_display
= ('nom', '_date_modification', 'user_modification', )
1216 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1217 (None, {'fields': ('nom', )}),
1220 def _date_modification(self
, obj
):
1221 return date(obj
.date_modification
) \
1222 if obj
.date_modification
is not None else "(aucune)"
1223 _date_modification
.short_description
= u
'date modification'
1224 _date_modification
.admin_order_field
= 'date_modification'
1227 class ValeurPointAdmin(AUFMetadataAdminMixin
, BaseAdmin
):
1234 '_date_modification',
1235 'user_modification',
1237 list_filter
= ('annee', 'devise', 'implantation__region', )
1238 fieldsets
= AUFMetadataAdminMixin
.fieldsets
+ (
1239 (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}),
1242 def _date_modification(self
, obj
):
1243 return date(obj
.date_modification
) \
1244 if obj
.date_modification
is not None else "(aucune)"
1245 _date_modification
.short_description
= u
'date modification'
1246 _date_modification
.admin_order_field
= 'date_modification'
1248 def _devise_code(self
, obj
):
1249 return obj
.devise
.code
1250 _devise_code
.short_description
= "Code de la devise"
1252 def _devise_nom(self
, obj
):
1253 return obj
.devise
.nom
1254 _devise_nom
.short_description
= "Nom de la devise"
1257 class ImplantationProxyAdmin(BaseAdmin
):
1258 list_display
= ('nom', '_organigramme')
1261 def __init__(self
, *args
, **kwargs
):
1262 super(ImplantationProxyAdmin
, self
).__init__(*args
, **kwargs
)
1263 self
.list_display_links
= (None, )
1265 def has_add_permission(self
, obj
):
1268 def has_change_permission(self
, request
, obj
=None):
1269 return in_drh_or_admin(request
.user
)
1271 def _organigramme(self
, obj
):
1272 return '<a href="%s"><strong>Organigramme</strong></a>' % (
1273 reverse('rho_implantation', args
=(obj
.id,))
1275 _organigramme
.allow_tags
= True
1276 _organigramme
.short_description
= "Organigramme"
1279 class RegionProxyAdmin(BaseAdmin
):
1280 list_display
= ('nom', '_organigramme')
1283 def __init__(self
, *args
, **kwargs
):
1284 super(RegionProxyAdmin
, self
).__init__(*args
, **kwargs
)
1285 self
.list_display_links
= (None, )
1287 def has_add_permission(self
, obj
):
1290 def has_change_permission(self
, request
, obj
=None):
1291 return in_drh_or_admin(request
.user
)
1293 def _organigramme(self
, obj
):
1294 return """<a href="%s"><strong>Organigramme</strong></a>""" % (
1295 reverse('rho_region', args
=(obj
.id,))
1297 _organigramme
.allow_tags
= True
1298 _organigramme
.short_description
= "Organigramme"
1301 admin
.site
.register(rh
.Classement
, ClassementAdmin
)
1302 admin
.site
.register(rh
.Devise
, DeviseAdmin
)
1303 admin
.site
.register(rh
.Dossier
, DossierAdmin
)
1304 admin
.site
.register(EmployeProxy
, EmployeProxyAdmin
)
1305 admin
.site
.register(ServiceProxy
, ServiceProxyAdmin
)
1306 admin
.site
.register(rh
.Employe
, EmployeAdmin
)
1307 admin
.site
.register(rh
.CategorieEmploi
, CategorieEmploiAdmin
)
1308 admin
.site
.register(rh
.FamilleProfessionnelle
)
1309 admin
.site
.register(rh
.OrganismeBstg
, OrganismeBstgAdmin
)
1310 admin
.site
.register(rh
.Poste
, PosteAdmin
)
1311 admin
.site
.register(
1312 rh
.ResponsableImplantationProxy
, ResponsableImplantationAdmin
1314 admin
.site
.register(rh
.Service
, ServiceAdmin
)
1315 admin
.site
.register(rh
.Statut
, StatutAdmin
)
1316 admin
.site
.register(rh
.TauxChange
, TauxChangeAdmin
)
1317 admin
.site
.register(rh
.TypeContrat
, TypeContratAdmin
)
1318 admin
.site
.register(rh
.TypePoste
, TypePosteAdmin
)
1319 admin
.site
.register(rh
.TypeRemuneration
, TypeRemunerationAdmin
)
1320 admin
.site
.register(rh
.TypeRevalorisation
, TypeRevalorisationAdmin
)
1321 admin
.site
.register(rh
.ValeurPoint
, ValeurPointAdmin
)
1322 admin
.site
.register(ImplantationProxy
, ImplantationProxyAdmin
)
1323 admin
.site
.register(RegionProxy
, RegionProxyAdmin
)