devise manager
[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 22class DateRangeMixin(object):
a17e2236 23 prefixe_recherche_temporelle = ""
40b35603
OL
24 def get_changelist(self, request, **kwargs):
25 if request.META.has_key('HTTP_REFERER'):
910e39e5
OL
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
40b35603 35 return ChangeList
3195667e 36
53ae644d
OL
37# Override of the InlineModelAdmin to support the link in the tabular inline
38class 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
48class 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):
20b4867c 70 user_groups = request.user.groups.all()
a0d365ed
OL
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
a18bc295 76 if len(user_groups) == 0 and not request.user.is_superuser:
20b4867c
OL
77 return False
78
53ae644d
OL
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
87class 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
92class 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
104class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
105 readonly_fields = ('owner', )
106 model = rh.AyantDroitCommentaire
107 extra = 1
108
109
110class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
111 form = ContratForm
112 model = rh.Contrat
113 extra = 1
114
115
116class 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
133class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
134 readonly_fields = ('owner', )
135 model = rh.DossierCommentaire
136 extra = 1
137
138
139class DossierPieceInline(admin.TabularInline):
140 model = rh.DossierPiece
141 extra = 4
142
143
144class EmployeInline(admin.TabularInline):
145 model = rh.Employe
146
147class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
148 readonly_fields = ('owner', )
149 model = rh.EmployeCommentaire
150 extra = 1
151
152
153class EmployePieceInline(admin.TabularInline):
154 model = rh.EmployePiece
155 extra = 4
156
157
53ae644d
OL
158class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
159 readonly_fields = ('owner', )
160 model = rh.PosteCommentaire
161 extra = 1
162
163
164class PosteFinancementInline(admin.TabularInline):
165 model = rh.PosteFinancement
166
167
168class PostePieceInline(admin.TabularInline):
169 model = rh.PostePiece
170
171
172class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
173 model = rh.Remuneration
174 extra = 1
175
176
177class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
178 pass
179
180
181class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
182 model = rh.TypePoste
183
184
6f037929
OL
185class PosteComparaisonInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
186 model = rh.PosteComparaison
187
53ae644d
OL
188
189class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 190 list_display = ('_classement', '_date_modification', 'user_modification', )
53ae644d
OL
191 fieldsets = AUFMetadataAdminMixin.fieldsets + (
192 (None, {
193 'fields': ('type', 'echelon', 'degre', 'coefficient', )
194 }),
195 )
196
c5964dc2
OL
197 def _classement(self, obj):
198 return unicode(obj)
199 _classement.short_description = u"Classement"
53ae644d 200
33232787
JPC
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
53ae644d
OL
206class CommentaireAdmin(admin.ModelAdmin):
207 pass
208
209
53ae644d 210class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
734e1e0c 211 list_display = ('code', 'nom', '_archive', '_date_modification', 'user_modification',)
edb35076 212 list_filter = ('archive', )
53ae644d
OL
213 fieldsets = AUFMetadataAdminMixin.fieldsets + (
214 (None, {
edb35076 215 'fields': ('code', 'nom', 'archive', ),
53ae644d
OL
216 }),
217 )
218
734e1e0c
OL
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
33232787
JPC
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'
53ae644d 233
40b35603 234class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect,):
53ae644d
OL
235 alphabet_filter = 'employe__nom'
236 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
237 list_display = (
238 '_id',
e49ac947
JPC
239 '_apercu',
240 '_nom',
53ae644d
OL
241 '_poste',
242 '_employe',
243 '_date_debut',
244 '_date_fin',
33232787 245 '_date_modification',
c5964dc2 246 'user_modification',
53ae644d 247 )
e49ac947 248 list_display_links = ('_nom',)
53ae644d
OL
249 list_filter = (
250 'poste__implantation__region',
251 'poste__implantation',
53ae644d 252 'poste__type_poste__famille_emploi',
7baa5523 253 'poste__type_poste',
53ae644d 254 'rh_contrats__type_contrat',
53ae644d
OL
255 )
256 inlines = (DossierPieceInline, ContratInline,
257 RemunerationInline,
53ae644d
OL
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',
53ae644d
OL
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
e49ac947
JPC
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):
5429c435 304 apercu_link = u"""<a title="Aperçu du dossier" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
b10920ea 305 (reverse('dossier_apercu', args=(d.id,)),
822a2c33 306 settings.STATIC_URL,
b10920ea 307 )
e49ac947
JPC
308 return apercu_link
309 _apercu.allow_tags = True
310 _apercu.short_description = u""
53ae644d
OL
311
312
53ae644d 313 def _date_debut(self, obj):
5f36f262
OL
314 return date(obj.date_debut)
315
53ae644d
OL
316 _date_debut.short_description = u'Occupation début'
317 _date_debut.admin_order_field = 'date_debut'
318
319 def _date_fin(self, obj):
5f36f262 320 return date(obj.date_fin)
53ae644d
OL
321 _date_fin.short_description = u'Occupation fin'
322 _date_fin.admin_order_field = 'date_fin'
323
33232787
JPC
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
53ae644d 330 def _poste(self, dossier):
211a0e56 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>""" % \
53ae644d 332 (reverse('poste_apercu', args=(dossier.poste.id,)),
822a2c33 333 settings.STATIC_URL,
211a0e56
JPC
334 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
335 dossier.poste,
53ae644d
OL
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
f614ca5c
OL
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,)
e6c107de
JPC
349 return u"""%s<a href='%s' style="%s;">%s</a>""" % \
350 (view, edit_link, style, employe)
53ae644d 351 _employe.allow_tags = True
e49ac947 352 _employe.short_description = u"Employé"
53ae644d
OL
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
02e69aa2 360 instance.date_creation = datetime.datetime.now()
53ae644d
OL
361 instance.save()
362
363
364class DossierPieceAdmin(admin.ModelAdmin):
365 pass
366
367
368class DossierCommentaireAdmin(admin.ModelAdmin):
369 pass
370
371
40b35603 372class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin,):
7eb6b687 373 prefixe_recherche_temporelle = "rh_dossiers__"
53ae644d
OL
374 alphabet_filter = 'nom'
375 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
376 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
377 ordering = ('nom', )
378 form = EmployeAdminForm
a7f013f5 379 list_display = ('_id', '_apercu', '_nom', '_dossiers_postes', '_date_modification', 'user_modification', )
e49ac947 380 list_display_links = ('_nom',)
7eb6b687 381 list_filter = ('rh_dossiers__poste__implantation__region', 'rh_dossiers__poste__implantation', 'nb_postes', )
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
a4329fae 444 if d.date_fin is not None and d.date_fin < datetime.date.today():
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',
1ce2ddb9 533 '_responsable',
352fa696 534 'date_debut',
53ae644d 535 'date_fin',
33232787 536 '_date_modification',
53ae644d 537 'user_modification',
53ae644d 538 )
f614ca5c 539 list_filter = (
53ae644d
OL
540 'implantation__region',
541 'implantation',
e8dd3d54 542 'service',
53ae644d
OL
543 'type_poste',
544 'type_poste__famille_emploi',
4c53dda4 545 'vacant',
53ae644d 546 )
e49ac947 547 list_display_links = ('_nom',)
53ae644d
OL
548 fieldsets = AUFMetadataAdminMixin.fieldsets + (
549 (None, {
550 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
551 'service', 'responsable')
552 }),
553 ('Contrat', {
554 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
555 }),
556 ('Recrutement', {
557 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
558 }),
559 ('Rémunération', {
560 'fields': (('classement_min', 'valeur_point_min', 'devise_min', 'salaire_min', 'indemn_min', 'autre_min', ),
561 ('classement_max', 'valeur_point_max' ,'devise_max', 'salaire_max', 'indemn_max', 'autre_max', ),
562 )
563 }),
564 ('Comparatifs de rémunération', {
565 'fields': ('devise_comparaison',
566 ('comp_locale_min', 'comp_locale_max'),
567 ('comp_universite_min', 'comp_universite_max'),
568 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
569 ('comp_ong_min', 'comp_ong_max'),
570 ('comp_autre_min', 'comp_autre_max'))
571 }),
572 ('Justification', {
573 'fields': ('justification',)
574 }),
48a6df80 575 ('Autres Méta-données', {
53ae644d
OL
576 'fields': ('date_debut', 'date_fin')
577 }),
578 )
579
580 inlines = (PosteFinancementInline,
581 PostePieceInline,
582 DossierROInline,
6f037929 583 PosteComparaisonInline,
53ae644d
OL
584 PosteCommentaireInline, )
585
b46d18bc 586
f614ca5c
OL
587 def lookup_allowed(self, key, value):
588 if key in (
589 'date_debut__gte',
590 'date_debut__isnull',
591 'date_fin__lte',
592 'date_fin__isnull',
7f4d1233
OL
593 'implantation__region__id__exact',
594 'implantation__id__exact',
595 'type_poste__id__exact',
596 'type_poste__famille_emploi__id__exact',
597 'service__id__exact',
d48f0922 598 'service__isnull',
7f4d1233 599 'vacant__exact',
c4a762e1 600 'vacant__isnull',
f614ca5c
OL
601 ):
602 return True
603
c5964dc2 604
8f3ca727 605 def _apercu(self, poste):
23de8cea 606 view_link = u"""<a onclick="return showAddAnotherPopup(this);" title="Aperçu du poste" href='%s'><img src="%simg/loupe.png" /></a>""" % \
8f3ca727 607 (reverse('poste_apercu', args=(poste.id,)),
822a2c33 608 settings.STATIC_URL,
23de8cea 609 )
e49ac947 610 return view_link
8f3ca727 611 _apercu.allow_tags = True
e49ac947
JPC
612 _apercu.short_description = ''
613
614 def _id(self, obj):
615 return "%s" % obj.id
616 _id.short_description = '#'
617 _id.admin_order_field = 'id'
8f3ca727 618
c5964dc2 619 def _service(self, obj):
1b130b25
JPC
620 if obj.service.supprime:
621 return """<span style="color:red">%s</span>""" % obj.service
622 else:
623 return obj.service
6c2b1160 624 _service.short_description = 'Service'
1b130b25 625 _service.allow_tags = True
53ae644d 626
1ce2ddb9
JPC
627 def _responsable(self, obj):
628 try:
629 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 />""" % \
630 (
631 reverse('poste_apercu', args=(obj.responsable.id,)),
632 settings.STATIC_URL,
633 reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
634 obj.responsable.nom
635 )
636 except:
637 responsable = ''
638
639 try:
783e077a 640 employeposte_change = "%s %s" % (obj.responsable.rh_dossiers.all()[0].employe.nom.upper(), obj.responsable.rh_dossiers.all()[0].employe.prenom)
1ce2ddb9
JPC
641 employe_id = obj.responsable.rh_dossiers.all()[0].id
642 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>""" % \
643 (
644 reverse('employe_apercu', args=(employe_id,)),
645 settings.STATIC_URL,
646 reverse('admin:rh_employe_change', args=(employe_id,)),
647 employe
648 )
649 except:
650 employe = ""
651
652 return "%s %s" % (responsable, employe)
653 _responsable.short_description = 'Responsable'
654 _responsable.allow_tags = True
655
53ae644d 656 def _nom(self, poste):
e49ac947
JPC
657 return """<a href="%s">%s</a>""" % \
658 (reverse('admin:rh_poste_change', args=(poste.id,)),
659 poste.nom
660 )
53ae644d
OL
661 _nom.allow_tags = True
662 _nom.short_description = u'Nom'
663 _nom.admin_order_field = 'nom'
664
33232787
JPC
665 def _date_modification(self, obj):
666 return date(obj.date_modification)
667 _date_modification.short_description = u'date modification'
668 _date_modification.admin_order_field = 'date_modification'
669
53ae644d
OL
670 def _occupe_par(self, obj):
671 """Formatte la méthode Poste.occupe_par() pour l'admin"""
15c5f55a 672 output = u"Vacant"
3195667e 673 if obj.date_fin is not None and obj.date_fin < datetime.date.now():
954ead19 674 return u"s/o"
53ae644d
OL
675 employes = obj.occupe_par()
676 if employes:
677 l = []
678 for e in employes:
b10920ea
JPC
679 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>" % \
680 (reverse('employe_apercu', args=(e.id,)),
822a2c33 681 settings.STATIC_URL,
b10920ea
JPC
682 reverse('admin:rh_employe_change', args=(e.id,)),
683 e
684 )
53ae644d
OL
685 l.append(link)
686 output = "\n<br />".join(l)
687 return output
688 _occupe_par.allow_tags = True
689 _occupe_par.short_description = "Occupé par"
690
691 def save_formset(self, request, form, formset, change):
692 instances = formset.save(commit=False)
693 for instance in instances:
694 if instance.__class__ == rh.PosteCommentaire:
695 instance.owner = request.user
02e69aa2 696 instance.date_creation = datetime.datetime.now()
53ae644d
OL
697 instance.save()
698 formset.save_m2m()
699
700
701class PosteCommentaireAdmin(admin.ModelAdmin):
702 pass
703
704
705class PosteFinancementAdmin(admin.ModelAdmin):
706 pass
707
708
709class PostePieceAdmin(admin.ModelAdmin):
710 fk_name = 'poste'
711
712
713class RemunerationAdmin(admin.ModelAdmin):
714 pass
715
716
717class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
718 fieldsets = AUFMetadataAdminMixin.fieldsets + (
719 (None, {
720 'fields': ('employe', 'implantation', ),
721 }),
722 )
723
724
725class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cbb0373e
OL
726 list_display = ('nom', '_archive', '_date_modification', 'user_modification', )
727 list_filter = ('archive', )
53ae644d
OL
728 fieldsets = AUFMetadataAdminMixin.fieldsets + (
729 (None, {
cbb0373e 730 'fields': ('nom', 'archive', ),
53ae644d
OL
731 }),
732 )
733
cbb0373e
OL
734 def _archive(self, obj):
735 if obj.archive:
736 return "oui"
737 else:
738 return "non"
739 _archive.short_description = u'Archivé'
740
33232787
JPC
741 def _date_modification(self, obj):
742 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
743 _date_modification.short_description = u'date modification'
744 _date_modification.admin_order_field = 'date_modification'
745
746
53ae644d 747class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 748 list_display = ('code', 'nom', '_date_modification', 'user_modification', )
53ae644d
OL
749 fieldsets = AUFMetadataAdminMixin.fieldsets + (
750 (None, {
751 'fields': ('code', 'nom', ),
752 }),
753 )
754
33232787
JPC
755 def _date_modification(self, obj):
756 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
757 _date_modification.short_description = u'date modification'
758 _date_modification.admin_order_field = 'date_modification'
759
53ae644d 760class TauxChangeAdmin(admin.ModelAdmin):
33232787 761 list_display = ('taux', 'devise', 'annee', '_date_modification', 'user_modification', )
53ae644d
OL
762 list_filter = ('devise', )
763 fieldsets = AUFMetadataAdminMixin.fieldsets + (
764 (None, {
765 'fields': ('taux', 'devise', 'annee', ),
766 }),
767 )
768
33232787
JPC
769 def _date_modification(self, obj):
770 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
771 _date_modification.short_description = u'date modification'
772 _date_modification.admin_order_field = 'date_modification'
773
53ae644d 774class TypeContratAdmin(admin.ModelAdmin):
33232787 775 list_display = ('nom', 'nom_long', '_date_modification', 'user_modification', )
53ae644d
OL
776 fieldsets = AUFMetadataAdminMixin.fieldsets + (
777 (None, {
778 'fields': ('nom', 'nom_long', ),
779 }),
780 )
781
33232787
JPC
782 def _date_modification(self, obj):
783 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
784 _date_modification.short_description = u'date modification'
785 _date_modification.admin_order_field = 'date_modification'
786
53ae644d
OL
787
788class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
789 search_fields = ('nom', 'nom_feminin', )
33232787 790 list_display = ('nom', 'famille_emploi', '_date_modification', 'user_modification', )
53ae644d
OL
791 list_filter = ('famille_emploi', )
792 fieldsets = AUFMetadataAdminMixin.fieldsets + (
793 (None, {
794 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
795 }),
796 )
797
33232787
JPC
798 def _date_modification(self, obj):
799 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
800 _date_modification.short_description = u'date modification'
801 _date_modification.admin_order_field = 'date_modification'
802
53ae644d
OL
803
804class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 805 list_display = ('nom', 'type_paiement', 'nature_remuneration', '_date_modification', 'user_modification', )
53ae644d
OL
806 fieldsets = AUFMetadataAdminMixin.fieldsets + (
807 (None, {
808 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
809 }),
810 )
811
33232787
JPC
812 def _date_modification(self, obj):
813 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
814 _date_modification.short_description = u'date modification'
815 _date_modification.admin_order_field = 'date_modification'
816
53ae644d
OL
817
818class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 819 list_display = ('nom', '_date_modification', 'user_modification', )
53ae644d
OL
820 fieldsets = AUFMetadataAdminMixin.fieldsets + (
821 (None, {
822 'fields': ('nom', )
823 }),
824 )
825
33232787
JPC
826 def _date_modification(self, obj):
827 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
828 _date_modification.short_description = u'date modification'
829 _date_modification.admin_order_field = 'date_modification'
830
53ae644d
OL
831
832class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 833 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', '_date_modification', 'user_modification', )
c5964dc2 834 list_filter = ('annee', 'devise', )
53ae644d
OL
835 fieldsets = AUFMetadataAdminMixin.fieldsets + (
836 (None, {
837 'fields': ('valeur', 'devise', 'implantation', 'annee', )
838 }),
839 )
840
33232787
JPC
841 def _date_modification(self, obj):
842 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
843 _date_modification.short_description = u'date modification'
844 _date_modification.admin_order_field = 'date_modification'
845
53ae644d
OL
846 def _devise_code(self, obj):
847 return obj.devise.code
848 _devise_code.short_description = "Code de la devise"
849
850 def _devise_nom(self, obj):
851 return obj.devise.nom
852 _devise_nom.short_description = "Nom de la devise"
853
854
855admin.site.register(rh.Classement, ClassementAdmin)
856admin.site.register(rh.Devise, DeviseAdmin)
857admin.site.register(rh.Dossier, DossierAdmin)
858admin.site.register(rh.Employe, EmployeAdmin)
859admin.site.register(rh.FamilleEmploi, FamilleEmploiAdmin)
860admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin)
861admin.site.register(rh.Poste, PosteAdmin)
862admin.site.register(rh.ResponsableImplantation, ResponsableImplantationAdmin)
863admin.site.register(rh.Service, ServiceAdmin)
c5964dc2 864admin.site.register(rh.Statut, StatutAdmin)
53ae644d 865admin.site.register(rh.TauxChange, TauxChangeAdmin)
c5964dc2 866admin.site.register(rh.TypeContrat, TypeContratAdmin)
53ae644d
OL
867admin.site.register(rh.TypePoste, TypePosteAdmin)
868admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin)
869admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin)
870admin.site.register(rh.ValeurPoint, ValeurPointAdmin)