Organigramme des postes fonctoinnel
[auf_rh_dae.git] / project / rh / admin.py
1 # -*- encoding: utf-8 -*-
2
3 from collections import defaultdict
4 import datetime
5
6 from django.db import models
7 from django import forms
8 from django.core.urlresolvers import reverse
9 from django.contrib import admin
10 from django.conf import settings
11 from django.db.models import Q
12 from django.template.defaultfilters import date
13 from ajax_select import make_ajax_form
14 from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
15 from forms import ContratForm, AyantDroitForm, EmployeAdminForm, AjaxSelect
16 from dae.utils import get_employe_from_user
17 from change_list import ChangeList
18 from groups import grp_drh
19 import models as rh
20 import filters
21
22 class DateRangeMixin(object):
23 prefixe_recherche_temporelle = ""
24 def get_changelist(self, request, **kwargs):
25 if request.META.has_key('HTTP_REFERER'):
26 referer = request.META['HTTP_REFERER']
27 referer = "/".join(referer.split('/')[3:])
28 referer = "/%s" % referer.split('?')[0]
29 change_list_view = 'admin:%s_%s_changelist' % (self.model._meta.app_label, self.model.__name__.lower())
30 if referer != reverse(change_list_view):
31 params = request.GET.copy()
32 today = datetime.date.today()
33 params.update({'statut' : 'Actif'})
34 request.GET = params
35 return ChangeList
36
37 # Override of the InlineModelAdmin to support the link in the tabular inline
38 class LinkedInline(admin.options.InlineModelAdmin):
39 template = "admin/linked.html"
40 admin_model_path = None
41
42 def __init__(self, *args):
43 super(LinkedInline, self).__init__(*args)
44 if self.admin_model_path is None:
45 self.admin_model_path = self.model.__name__.lower()
46
47
48 class ProtectRegionMixin(object):
49
50 def queryset(self, request):
51 from dae.workflow import grp_drh, grp_correspondants_rh
52 qs = super(ProtectRegionMixin, self).queryset(request)
53
54 if request.user.is_superuser:
55 return qs
56
57 user_groups = request.user.groups.all()
58
59 if grp_drh in user_groups:
60 return qs
61
62 if grp_correspondants_rh in user_groups:
63 employe = get_employe_from_user(request.user)
64 q = Q(**{self.model.prefix_implantation: employe.implantation.region})
65 qs = qs.filter(q).distinct()
66 return qs
67 return qs.none()
68
69 def has_change_permission(self, request, obj=None):
70 user_groups = request.user.groups.all()
71
72 # Lock pour autoriser uniquement les DRH à utiliser RH
73 if not request.user.is_superuser and not grp_drh in user_groups:
74 return False
75
76 if len(user_groups) == 0 and not request.user.is_superuser:
77 return False
78
79 if obj is None:
80 return True
81 ids = [o.id for o in self.queryset(request)]
82 return obj.id in ids
83
84
85 # Inlines
86
87 class ReadOnlyInlineMixin(object):
88 def get_readonly_fields(self, request, obj=None):
89 return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS]
90
91
92 class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline):
93 model = rh.AyantDroit
94 form = AyantDroitForm
95 extra = 0
96
97 fieldsets = (
98 (None, {
99 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', 'lien_parente', )
100 }),
101 )
102
103
104 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
105 readonly_fields = ('owner', )
106 model = rh.AyantDroitCommentaire
107 extra = 1
108
109
110 class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
111 form = ContratForm
112 model = rh.Contrat
113 extra = 1
114
115
116 class DossierROInline(ReadOnlyInlineMixin, LinkedInline):
117 template = "admin/rh/dossier/linked.html"
118 exclude = AUF_METADATA_READONLY_FIELDS
119 model = rh.Dossier
120 extra = 0
121 can_delete = False
122
123 def has_add_permission(self, request=None):
124 return False
125
126 def has_change_permission(self, request, obj=None):
127 return False
128
129 def has_delete_permission(self, request, obj=None):
130 return False
131
132
133 class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
134 readonly_fields = ('owner', )
135 model = rh.DossierCommentaire
136 extra = 1
137
138
139 class DossierPieceInline(admin.TabularInline):
140 model = rh.DossierPiece
141 extra = 4
142
143
144 class EmployeInline(admin.TabularInline):
145 model = rh.Employe
146
147 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
148 readonly_fields = ('owner', )
149 model = rh.EmployeCommentaire
150 extra = 1
151
152
153 class EmployePieceInline(admin.TabularInline):
154 model = rh.EmployePiece
155 extra = 4
156
157
158 class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
159 readonly_fields = ('owner', )
160 model = rh.PosteCommentaire
161 extra = 1
162
163
164 class PosteFinancementInline(admin.TabularInline):
165 model = rh.PosteFinancement
166
167
168 class PostePieceInline(admin.TabularInline):
169 model = rh.PostePiece
170
171
172 class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
173 model = rh.Remuneration
174 extra = 1
175
176
177 class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
178 pass
179
180
181 class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
182 model = rh.TypePoste
183
184
185 class PosteComparaisonInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
186 model = rh.PosteComparaison
187
188
189 class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
190 list_display = ('_classement', '_date_modification', 'user_modification', )
191 fieldsets = AUFMetadataAdminMixin.fieldsets + (
192 (None, {
193 'fields': ('type', 'echelon', 'degre', 'coefficient', )
194 }),
195 )
196
197 def _classement(self, obj):
198 return unicode(obj)
199 _classement.short_description = u"Classement"
200
201 def _date_modification(self, obj):
202 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
203 _date_modification.short_description = u'date modification'
204 _date_modification.admin_order_field = 'date_modification'
205
206 class CommentaireAdmin(admin.ModelAdmin):
207 pass
208
209
210 class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
211 list_display = ('code', 'nom', '_archive', '_date_modification', 'user_modification',)
212 list_filter = ('archive', )
213 fieldsets = AUFMetadataAdminMixin.fieldsets + (
214 (None, {
215 'fields': ('code', 'nom', 'archive', ),
216 }),
217 )
218
219 def queryset(self, request):
220 return self.model._base_manager
221
222 def _archive(self, obj):
223 if obj.archive:
224 return "oui"
225 else:
226 return "non"
227 _archive.short_description = u'Archivé'
228
229 def _date_modification(self, obj):
230 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
231 _date_modification.short_description = u'date modification'
232 _date_modification.admin_order_field = 'date_modification'
233
234 class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect,):
235 alphabet_filter = 'employe__nom'
236 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
237 list_display = (
238 '_id',
239 '_apercu',
240 '_nom',
241 '_poste',
242 '_employe',
243 '_date_debut',
244 '_date_fin',
245 '_date_modification',
246 'user_modification',
247 )
248 list_display_links = ('_nom',)
249 list_filter = (
250 'poste__implantation__region',
251 'poste__implantation',
252 'poste__type_poste__famille_emploi',
253 'poste__type_poste',
254 'rh_contrats__type_contrat',
255 )
256 inlines = (DossierPieceInline, ContratInline,
257 RemunerationInline,
258 DossierCommentaireInline,
259 )
260 fieldsets = AUFMetadataAdminMixin.fieldsets + (
261 (None, {
262 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
263 }),
264 ('Recrutement', {
265 'fields': ('statut_residence', 'remplacement', 'remplacement_de', )
266 }),
267 ('Rémunération', {
268 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),)
269 }),
270 ('Occupation du Poste par cet Employe', {
271 'fields': (('date_debut', 'date_fin'), )
272 }),
273 )
274 form = make_ajax_form(rh.Dossier, {
275 'employe' : 'employes',
276 'poste' : 'postes',
277 'remplacement_de' : 'dossiers',
278 })
279
280 def lookup_allowed(self, key, value):
281 if key in (
282 'employe__nom__istartswith',
283 'poste__implantation__region__id__exact',
284 'poste__implantation__id__exact',
285 'poste__type_poste__id__exact',
286 'poste__type_poste__famille_emploi__id__exact',
287 'rh_contrats__type_contrat__id__exact',
288 ):
289 return True
290
291 def _id(self, obj):
292 return obj.id
293 _id.short_description = u"#"
294 _id.admin_order_field = "id"
295
296 def _nom(self, obj):
297 return "%d : %s %s" % \
298 (obj.date_debut.year, obj.employe.nom.upper(), obj.employe.prenom)
299 _nom.allow_tags = True
300 _nom.short_description = u"Dossier"
301
302
303 def _apercu(self, d):
304 apercu_link = u"""<a title="Aperçu du dossier" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
305 (reverse('dossier_apercu', args=(d.id,)),
306 settings.STATIC_URL,
307 )
308 return apercu_link
309 _apercu.allow_tags = True
310 _apercu.short_description = u""
311
312
313 def _date_debut(self, obj):
314 return date(obj.date_debut)
315
316 _date_debut.short_description = u'Occupation début'
317 _date_debut.admin_order_field = 'date_debut'
318
319 def _date_fin(self, obj):
320 return date(obj.date_fin)
321 _date_fin.short_description = u'Occupation fin'
322 _date_fin.admin_order_field = 'date_fin'
323
324
325 def _date_modification(self, obj):
326 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
327 _date_modification.short_description = u'date modification'
328 _date_modification.admin_order_field = 'date_modification'
329
330 def _poste(self, dossier):
331 link = u"""<a title="Aperçu du poste" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a> <a href="%s" title="Modifier le poste">%s</a>""" % \
332 (reverse('poste_apercu', args=(dossier.poste.id,)),
333 settings.STATIC_URL,
334 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
335 dossier.poste,
336 )
337 return link
338 _poste.allow_tags = True
339 _poste.short_description = u'Poste'
340 _poste.admin_order_field = 'poste__nom'
341
342 def _employe(self, obj):
343 employe = obj.employe
344 view_link = reverse('employe_apercu', args=(employe.id,))
345 edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
346
347 style = ""
348 view = u"""<a href="%s" title="Aperçu l'employé" onclick="return showAddAnotherPopup(this);"><img src="%simg/loupe.png" /></a>""" % (view_link, settings.STATIC_URL,)
349 return u"""%s<a href='%s' style="%s;">%s</a>""" % \
350 (view, edit_link, style, employe)
351 _employe.allow_tags = True
352 _employe.short_description = u"Employé"
353 _employe.admin_order_field = "employe__nom"
354
355 def save_formset(self, request, form, formset, change):
356 instances = formset.save(commit=False)
357 for instance in instances:
358 if instance.__class__ == rh.DossierCommentaire:
359 instance.owner = request.user
360 instance.date_creation = datetime.datetime.now()
361 instance.save()
362
363
364 class DossierPieceAdmin(admin.ModelAdmin):
365 pass
366
367
368 class DossierCommentaireAdmin(admin.ModelAdmin):
369 pass
370
371
372 class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin,):
373 prefixe_recherche_temporelle = "rh_dossiers__"
374 alphabet_filter = 'nom'
375 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
376 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
377 ordering = ('nom', )
378 form = EmployeAdminForm
379 list_display = ('_id', '_apercu', '_nom', '_dossiers_postes', '_date_modification', 'user_modification', )
380 list_display_links = ('_nom',)
381 list_filter = ('rh_dossiers__poste__implantation__region', 'rh_dossiers__poste__implantation', 'nb_postes', )
382 inlines = (AyantDroitInline,
383 DossierROInline,
384 EmployePieceInline,
385 EmployeCommentaireInline)
386 fieldsets = AUFMetadataAdminMixin.fieldsets + (
387 ('Identification', {
388 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
389 }),
390 ('Informations personnelles', {
391 'fields': ('situation_famille', 'date_entree', )
392 }),
393 ('Coordonnées', {
394 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', )
395 }),
396 )
397
398 def _apercu(self, obj):
399 return u"""<a title="Aperçu de l'employé" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
400 (reverse('employe_apercu', args=(obj.id,)), settings.STATIC_URL)
401 _apercu.allow_tags = True
402 _apercu.short_description = u""
403
404 def _nom(self, obj):
405 edit_link = reverse('admin:rh_employe_change', args=(obj.id,))
406 return u"""<a href='%s'><strong>%s</strong></a>""" % \
407 (edit_link, "%s %s" % (obj.nom.upper(), obj.prenom))
408 _nom.allow_tags = True
409 _nom.short_description = u"Employé"
410 _nom.admin_order_field = "nom"
411
412 def _id(self, obj):
413 return obj.id
414 _id.short_description = u"#"
415 _id.admin_order_field = "id"
416
417 def _date_modification(self, obj):
418 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
419 _date_modification.short_description = u'date modification'
420 _date_modification.admin_order_field = 'date_modification'
421
422 def _dossiers_postes(self, obj):
423 l = []
424 for d in obj.rh_dossiers.all().order_by('-date_debut'):
425 dossier = u"""<a title="Aperçu du dossier" href="%s" onclick="return showAddAnotherPopup(this);" title="Aperçu du dossier"><img src="%simg/loupe.png" /></a><a href="%s">Dossier</a>&nbsp;""" % \
426 ( reverse('dossier_apercu', args=(d.id,)),
427 settings.STATIC_URL,
428 reverse('admin:rh_dossier_change', args=(d.id,))
429 )
430
431 poste = u"""<a title="Aperçu du poste" href="%s" onclick="return showAddAnotherPopup(this);" title="Aperçu du poste"><img src="%simg/loupe.png" /></a><a href="%s">Poste</a>&nbsp;""" % \
432 ( reverse('poste_apercu', args=(d.poste.id,)),
433 settings.STATIC_URL,
434 reverse('admin:rh_poste_change', args=(d.poste.id,))
435 )
436 link = u"""<li>%s %s - %s : [%s] %s</li>""" % \
437 (dossier, poste,
438 d.date_debut.year,
439 d.poste.id,
440 d.poste.nom,
441 )
442
443 # Dossier terminé en gris non cliquable
444 if d.date_fin is not None and d.date_fin < datetime.date.today():
445 link = u"""<li style="color: grey">%s : [%s] %s</li>""" % \
446 (d.date_debut.year,
447 d.poste.id,
448 d.poste.nom,
449 )
450
451 l.append(link)
452 return "<ul>%s</ul>" % "\n".join(l)
453 _dossiers_postes.allow_tags = True
454 _dossiers_postes.short_description = u"Dossiers et postes"
455
456 def queryset(self, request):
457 qs = super(EmployeAdmin, self).queryset(request)
458 return qs.select_related(depth=1).order_by('nom')
459
460 def save_formset(self, request, form, formset, change):
461 instances = formset.save(commit=False)
462 for instance in instances:
463 if instance.__class__ == rh.EmployeCommentaire:
464 instance.owner = request.user
465 instance.date_creation = datetime.datetime.now()
466 instance.save()
467
468 class EmployeProxyAdmin(EmployeAdmin):
469 list_display = ('_id', '_apercu', '_nom', '_organigramme')
470 list_display_links = ('_nom',)
471
472 def _organigramme(self, obj):
473 l = []
474 for d in obj.rh_dossiers.all().order_by('-date_debut'):
475 poste = u"""<a title="Aperçu du poste" href="%s" onclick="return showAddAnotherPopup(this);" title="Aperçu du poste"><img src="%simg/loupe.png" /></a><a href="%s">Poste</a>&nbsp;""" % \
476 ( reverse('poste_apercu', args=(d.poste.id,)),
477 settings.STATIC_URL,
478 reverse('admin:rh_poste_change', args=(d.poste.id,))
479 )
480 organigramme = u"""<a href="%s">Organigramme</a>""" % (reverse('rho_employe', args=(d.poste.id,)))
481 link = u"""<li>%s - %s - %s : [%s] %s</li>""" % \
482 (poste, organigramme,
483 d.date_debut.year,
484 d.poste.id,
485 d.poste.nom,
486 )
487 l.append(link)
488 return "<ul>%s</ul>" % "\n".join(l)
489
490 _organigramme.allow_tags = True
491 _organigramme.short_description = "Organigramme"
492
493
494
495 class EmployeCommentaireAdmin(admin.ModelAdmin):
496 pass
497
498
499 class EmployePieceAdmin(admin.ModelAdmin):
500 pass
501
502
503 class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
504 list_display = ('nom', '_date_modification', 'user_modification', )
505 inlines = (TypePosteInline,)
506 fieldsets = AUFMetadataAdminMixin.fieldsets + (
507 (None, {
508 'fields': ('nom', )
509 }),
510 )
511
512 def _date_modification(self, obj):
513 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
514 _date_modification.short_description = u'date modification'
515 _date_modification.admin_order_field = 'date_modification'
516
517 class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
518 search_fields = ('nom',)
519 list_display = ('nom', 'type', 'pays', '_date_modification', 'user_modification', )
520 list_filter = ('type', )
521 inlines = (DossierROInline,)
522 fieldsets = AUFMetadataAdminMixin.fieldsets + (
523 (None, {
524 'fields': ('nom', 'type', 'pays', )
525 }),
526 )
527
528 def _date_modification(self, obj):
529 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
530 _date_modification.short_description = u'date modification'
531 _date_modification.admin_order_field = 'date_modification'
532
533
534 class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect,):
535 form = make_ajax_form(rh.Poste, {
536 'implantation' : 'implantations',
537 'type_poste' : 'typepostes',
538 'responsable' : 'postes',
539 'valeur_point_min' : 'valeurpoints',
540 'valeur_point_max' : 'valeurpoints',
541 })
542 alphabet_filter = 'nom'
543 search_fields = ('nom',
544 'implantation__code',
545 'implantation__nom',
546 'implantation__region__code',
547 'implantation__region__nom',
548 'rh_dossiers__employe__nom',
549 'rh_dossiers__employe__prenom',
550 )
551 list_display = (
552 '_id',
553 '_apercu',
554 '_nom',
555 '_occupe_par',
556 'implantation',
557 '_service',
558 '_responsable',
559 'date_debut',
560 'date_fin',
561 '_date_modification',
562 'user_modification',
563 )
564 list_filter = (
565 'implantation__region',
566 'implantation',
567 'service',
568 'type_poste',
569 'type_poste__famille_emploi',
570 'vacant',
571 )
572 list_display_links = ('_nom',)
573 fieldsets = AUFMetadataAdminMixin.fieldsets + (
574 (None, {
575 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
576 'service', 'responsable')
577 }),
578 ('Contrat', {
579 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
580 }),
581 ('Recrutement', {
582 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
583 }),
584 ('Rémunération', {
585 'fields': (('classement_min', 'valeur_point_min', 'devise_min', 'salaire_min', 'indemn_min', 'autre_min', ),
586 ('classement_max', 'valeur_point_max' ,'devise_max', 'salaire_max', 'indemn_max', 'autre_max', ),
587 )
588 }),
589 ('Comparatifs de rémunération', {
590 'fields': ('devise_comparaison',
591 ('comp_locale_min', 'comp_locale_max'),
592 ('comp_universite_min', 'comp_universite_max'),
593 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
594 ('comp_ong_min', 'comp_ong_max'),
595 ('comp_autre_min', 'comp_autre_max'))
596 }),
597 ('Justification', {
598 'fields': ('justification',)
599 }),
600 ('Autres Méta-données', {
601 'fields': ('date_debut', 'date_fin')
602 }),
603 )
604
605 inlines = (PosteFinancementInline,
606 PostePieceInline,
607 DossierROInline,
608 PosteComparaisonInline,
609 PosteCommentaireInline, )
610
611
612 def lookup_allowed(self, key, value):
613 if key in (
614 'date_debut__gte',
615 'date_debut__isnull',
616 'date_fin__lte',
617 'date_fin__isnull',
618 'implantation__region__id__exact',
619 'implantation__id__exact',
620 'type_poste__id__exact',
621 'type_poste__famille_emploi__id__exact',
622 'service__id__exact',
623 'service__isnull',
624 'vacant__exact',
625 'vacant__isnull',
626 ):
627 return True
628
629
630 def _apercu(self, poste):
631 view_link = u"""<a onclick="return showAddAnotherPopup(this);" title="Aperçu du poste" href='%s'><img src="%simg/loupe.png" /></a>""" % \
632 (reverse('poste_apercu', args=(poste.id,)),
633 settings.STATIC_URL,
634 )
635 return view_link
636 _apercu.allow_tags = True
637 _apercu.short_description = ''
638
639 def _id(self, obj):
640 return "%s" % obj.id
641 _id.short_description = '#'
642 _id.admin_order_field = 'id'
643
644 def _service(self, obj):
645 if obj.service.supprime:
646 return """<span style="color:red">%s</span>""" % obj.service
647 else:
648 return obj.service
649 _service.short_description = 'Service'
650 _service.allow_tags = True
651
652 def _responsable(self, obj):
653 try:
654 responsable = u"""<a href="%s" onclick="return showAddAnotherPopup(this)"><img src="%simg/loupe.png" title="Aperçu du poste"></a> <a href="%s">%s</a><br />""" % \
655 (
656 reverse('poste_apercu', args=(obj.responsable.id,)),
657 settings.STATIC_URL,
658 reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
659 obj.responsable.nom
660 )
661 except:
662 responsable = ''
663
664 try:
665 employeposte_change = "%s %s" % (obj.responsable.rh_dossiers.all()[0].employe.nom.upper(), obj.responsable.rh_dossiers.all()[0].employe.prenom)
666 employe_id = obj.responsable.rh_dossiers.all()[0].id
667 employe = u"""<br /><a href="%s" onclick="return showAddAnotherPopup(this)"><img src="%simg/loupe.png" title="Aperçu de l'employé"></a> <a href="%s">%s</a>""" % \
668 (
669 reverse('employe_apercu', args=(employe_id,)),
670 settings.STATIC_URL,
671 reverse('admin:rh_employe_change', args=(employe_id,)),
672 employe
673 )
674 except:
675 employe = ""
676
677 return "%s %s" % (responsable, employe)
678 _responsable.short_description = 'Responsable'
679 _responsable.allow_tags = True
680
681 def _nom(self, poste):
682 return """<a href="%s">%s</a>""" % \
683 (reverse('admin:rh_poste_change', args=(poste.id,)),
684 poste.nom
685 )
686 _nom.allow_tags = True
687 _nom.short_description = u'Nom'
688 _nom.admin_order_field = 'nom'
689
690 def _date_modification(self, obj):
691 return date(obj.date_modification)
692 _date_modification.short_description = u'date modification'
693 _date_modification.admin_order_field = 'date_modification'
694
695 def _occupe_par(self, obj):
696 """Formatte la méthode Poste.occupe_par() pour l'admin"""
697 output = u"Vacant"
698 if obj.date_fin is not None and obj.date_fin < datetime.date.now():
699 return u"s/o"
700 employes = obj.occupe_par()
701 if employes:
702 l = []
703 for e in employes:
704 link = "<a href='%s' title='Aperçu de l\'employer' onclick='return showAddAnotherPopup(this)'><img src='%simg/loupe.png' /></a> <a href='%s'>%s</a>" % \
705 (reverse('employe_apercu', args=(e.id,)),
706 settings.STATIC_URL,
707 reverse('admin:rh_employe_change', args=(e.id,)),
708 e
709 )
710 l.append(link)
711 output = "\n<br />".join(l)
712 return output
713 _occupe_par.allow_tags = True
714 _occupe_par.short_description = "Occupé par"
715
716 def save_formset(self, request, form, formset, change):
717 instances = formset.save(commit=False)
718 for instance in instances:
719 if instance.__class__ == rh.PosteCommentaire:
720 instance.owner = request.user
721 instance.date_creation = datetime.datetime.now()
722 instance.save()
723 formset.save_m2m()
724
725
726 class PosteCommentaireAdmin(admin.ModelAdmin):
727 pass
728
729
730 class PosteFinancementAdmin(admin.ModelAdmin):
731 pass
732
733
734 class PostePieceAdmin(admin.ModelAdmin):
735 fk_name = 'poste'
736
737
738 class RemunerationAdmin(admin.ModelAdmin):
739 pass
740
741
742 class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
743 fieldsets = AUFMetadataAdminMixin.fieldsets + (
744 (None, {
745 'fields': ('employe', 'implantation', ),
746 }),
747 )
748
749
750 class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
751 list_display = ('nom', '_archive', '_date_modification', 'user_modification', )
752 list_filter = ('archive', )
753 fieldsets = AUFMetadataAdminMixin.fieldsets + (
754 (None, {
755 'fields': ('nom', 'archive', ),
756 }),
757 )
758
759 def _archive(self, obj):
760 if obj.archive:
761 return "oui"
762 else:
763 return "non"
764 _archive.short_description = u'Archivé'
765
766 def _date_modification(self, obj):
767 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
768 _date_modification.short_description = u'date modification'
769 _date_modification.admin_order_field = 'date_modification'
770
771
772 class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
773 list_display = ('code', 'nom', '_date_modification', 'user_modification', )
774 fieldsets = AUFMetadataAdminMixin.fieldsets + (
775 (None, {
776 'fields': ('code', 'nom', ),
777 }),
778 )
779
780 def _date_modification(self, obj):
781 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
782 _date_modification.short_description = u'date modification'
783 _date_modification.admin_order_field = 'date_modification'
784
785 class TauxChangeAdmin(admin.ModelAdmin):
786 list_display = ('taux', 'devise', 'annee', '_date_modification', 'user_modification', )
787 list_filter = ('devise', )
788 fieldsets = AUFMetadataAdminMixin.fieldsets + (
789 (None, {
790 'fields': ('taux', 'devise', 'annee', ),
791 }),
792 )
793
794 def _date_modification(self, obj):
795 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
796 _date_modification.short_description = u'date modification'
797 _date_modification.admin_order_field = 'date_modification'
798
799 class TypeContratAdmin(admin.ModelAdmin):
800 list_display = ('nom', 'nom_long', '_date_modification', 'user_modification', )
801 fieldsets = AUFMetadataAdminMixin.fieldsets + (
802 (None, {
803 'fields': ('nom', 'nom_long', ),
804 }),
805 )
806
807 def _date_modification(self, obj):
808 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
809 _date_modification.short_description = u'date modification'
810 _date_modification.admin_order_field = 'date_modification'
811
812
813 class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
814 search_fields = ('nom', 'nom_feminin', )
815 list_display = ('nom', 'famille_emploi', '_date_modification', 'user_modification', )
816 list_filter = ('famille_emploi', )
817 fieldsets = AUFMetadataAdminMixin.fieldsets + (
818 (None, {
819 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
820 }),
821 )
822
823 def _date_modification(self, obj):
824 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
825 _date_modification.short_description = u'date modification'
826 _date_modification.admin_order_field = 'date_modification'
827
828
829 class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
830 list_display = ('nom', 'type_paiement', 'nature_remuneration', '_date_modification', 'user_modification', )
831 fieldsets = AUFMetadataAdminMixin.fieldsets + (
832 (None, {
833 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
834 }),
835 )
836
837 def _date_modification(self, obj):
838 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
839 _date_modification.short_description = u'date modification'
840 _date_modification.admin_order_field = 'date_modification'
841
842
843 class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
844 list_display = ('nom', '_date_modification', 'user_modification', )
845 fieldsets = AUFMetadataAdminMixin.fieldsets + (
846 (None, {
847 'fields': ('nom', )
848 }),
849 )
850
851 def _date_modification(self, obj):
852 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
853 _date_modification.short_description = u'date modification'
854 _date_modification.admin_order_field = 'date_modification'
855
856
857 class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
858 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', '_date_modification', 'user_modification', )
859 list_filter = ('annee', 'devise', )
860 fieldsets = AUFMetadataAdminMixin.fieldsets + (
861 (None, {
862 'fields': ('valeur', 'devise', 'implantation', 'annee', )
863 }),
864 )
865
866 def _date_modification(self, obj):
867 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
868 _date_modification.short_description = u'date modification'
869 _date_modification.admin_order_field = 'date_modification'
870
871 def _devise_code(self, obj):
872 return obj.devise.code
873 _devise_code.short_description = "Code de la devise"
874
875 def _devise_nom(self, obj):
876 return obj.devise.nom
877 _devise_nom.short_description = "Nom de la devise"
878
879
880 admin.site.register(rh.Classement, ClassementAdmin)
881 admin.site.register(rh.Devise, DeviseAdmin)
882 admin.site.register(rh.Dossier, DossierAdmin)
883 admin.site.register(rh.EmployeProxy, EmployeProxyAdmin)
884 admin.site.register(rh.Employe, EmployeAdmin)
885 admin.site.register(rh.FamilleEmploi, FamilleEmploiAdmin)
886 admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin)
887 admin.site.register(rh.Poste, PosteAdmin)
888 admin.site.register(rh.ResponsableImplantation, ResponsableImplantationAdmin)
889 admin.site.register(rh.Service, ServiceAdmin)
890 admin.site.register(rh.Statut, StatutAdmin)
891 admin.site.register(rh.TauxChange, TauxChangeAdmin)
892 admin.site.register(rh.TypeContrat, TypeContratAdmin)
893 admin.site.register(rh.TypePoste, TypePosteAdmin)
894 admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin)
895 admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin)
896 admin.site.register(rh.ValeurPoint, ValeurPointAdmin)