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