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