Merge branch 'dev' of ssh://git.auf/auf_rh_dae into dev
[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):
1ce2ddb9 211 list_display = ('code', 'nom', '_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
33232787
JPC
219 def _date_modification(self, obj):
220 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
221 _date_modification.short_description = u'date modification'
222 _date_modification.admin_order_field = 'date_modification'
53ae644d 223
40b35603 224class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect,):
53ae644d
OL
225 alphabet_filter = 'employe__nom'
226 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
227 list_display = (
228 '_id',
e49ac947
JPC
229 '_apercu',
230 '_nom',
53ae644d
OL
231 '_poste',
232 '_employe',
233 '_date_debut',
234 '_date_fin',
33232787 235 '_date_modification',
c5964dc2 236 'user_modification',
53ae644d 237 )
e49ac947 238 list_display_links = ('_nom',)
53ae644d
OL
239 list_filter = (
240 'poste__implantation__region',
241 'poste__implantation',
53ae644d 242 'poste__type_poste__famille_emploi',
7baa5523 243 'poste__type_poste',
53ae644d 244 'rh_contrats__type_contrat',
53ae644d
OL
245 )
246 inlines = (DossierPieceInline, ContratInline,
247 RemunerationInline,
53ae644d
OL
248 DossierCommentaireInline,
249 )
250 fieldsets = AUFMetadataAdminMixin.fieldsets + (
251 (None, {
252 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
253 }),
254 ('Recrutement', {
255 'fields': ('statut_residence', 'remplacement', 'remplacement_de', )
256 }),
257 ('Rémunération', {
258 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),)
259 }),
260 ('Occupation du Poste par cet Employe', {
261 'fields': (('date_debut', 'date_fin'), )
262 }),
263 )
264 form = make_ajax_form(rh.Dossier, {
265 'employe' : 'employes',
266 'poste' : 'postes',
267 'remplacement_de' : 'dossiers',
268 })
269
270 def lookup_allowed(self, key, value):
271 if key in (
272 'employe__nom__istartswith',
53ae644d
OL
273 'poste__implantation__region__id__exact',
274 'poste__implantation__id__exact',
275 'poste__type_poste__id__exact',
276 'poste__type_poste__famille_emploi__id__exact',
277 'rh_contrats__type_contrat__id__exact',
278 ):
279 return True
280
e49ac947
JPC
281 def _id(self, obj):
282 return obj.id
283 _id.short_description = u"#"
284 _id.admin_order_field = "id"
285
286 def _nom(self, obj):
287 return "%d : %s %s" % \
288 (obj.date_debut.year, obj.employe.nom.upper(), obj.employe.prenom)
289 _nom.allow_tags = True
290 _nom.short_description = u"Dossier"
291
292
293 def _apercu(self, d):
5429c435 294 apercu_link = u"""<a title="Aperçu du dossier" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
b10920ea 295 (reverse('dossier_apercu', args=(d.id,)),
822a2c33 296 settings.STATIC_URL,
b10920ea 297 )
e49ac947
JPC
298 return apercu_link
299 _apercu.allow_tags = True
300 _apercu.short_description = u""
53ae644d
OL
301
302
53ae644d 303 def _date_debut(self, obj):
5f36f262
OL
304 return date(obj.date_debut)
305
53ae644d
OL
306 _date_debut.short_description = u'Occupation début'
307 _date_debut.admin_order_field = 'date_debut'
308
309 def _date_fin(self, obj):
5f36f262 310 return date(obj.date_fin)
53ae644d
OL
311 _date_fin.short_description = u'Occupation fin'
312 _date_fin.admin_order_field = 'date_fin'
313
33232787
JPC
314
315 def _date_modification(self, obj):
316 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
317 _date_modification.short_description = u'date modification'
318 _date_modification.admin_order_field = 'date_modification'
319
53ae644d 320 def _poste(self, dossier):
211a0e56 321 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 322 (reverse('poste_apercu', args=(dossier.poste.id,)),
822a2c33 323 settings.STATIC_URL,
211a0e56
JPC
324 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
325 dossier.poste,
53ae644d
OL
326 )
327 return link
328 _poste.allow_tags = True
329 _poste.short_description = u'Poste'
330 _poste.admin_order_field = 'poste__nom'
331
332 def _employe(self, obj):
333 employe = obj.employe
334 view_link = reverse('employe_apercu', args=(employe.id,))
335 edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
336
f614ca5c
OL
337 style = ""
338 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
339 return u"""%s<a href='%s' style="%s;">%s</a>""" % \
340 (view, edit_link, style, employe)
53ae644d 341 _employe.allow_tags = True
e49ac947 342 _employe.short_description = u"Employé"
53ae644d
OL
343 _employe.admin_order_field = "employe__nom"
344
345 def save_formset(self, request, form, formset, change):
346 instances = formset.save(commit=False)
347 for instance in instances:
348 if instance.__class__ == rh.DossierCommentaire:
349 instance.owner = request.user
02e69aa2 350 instance.date_creation = datetime.datetime.now()
53ae644d
OL
351 instance.save()
352
353
354class DossierPieceAdmin(admin.ModelAdmin):
355 pass
356
357
358class DossierCommentaireAdmin(admin.ModelAdmin):
359 pass
360
361
40b35603 362class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin,):
7eb6b687 363 prefixe_recherche_temporelle = "rh_dossiers__"
53ae644d
OL
364 alphabet_filter = 'nom'
365 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
366 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
367 ordering = ('nom', )
368 form = EmployeAdminForm
a7f013f5 369 list_display = ('_id', '_apercu', '_nom', '_dossiers_postes', '_date_modification', 'user_modification', )
e49ac947 370 list_display_links = ('_nom',)
7eb6b687 371 list_filter = ('rh_dossiers__poste__implantation__region', 'rh_dossiers__poste__implantation', 'nb_postes', )
53ae644d
OL
372 inlines = (AyantDroitInline,
373 DossierROInline,
374 EmployePieceInline,
375 EmployeCommentaireInline)
376 fieldsets = AUFMetadataAdminMixin.fieldsets + (
377 ('Identification', {
378 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
379 }),
380 ('Informations personnelles', {
381 'fields': ('situation_famille', 'date_entree', )
382 }),
383 ('Coordonnées', {
384 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', )
385 }),
386 )
387
b10920ea
JPC
388 def _apercu(self, obj):
389 return u"""<a title="Aperçu de l'employé" onclick="return showAddAnotherPopup(this);" href='%s'><img src="%simg/loupe.png" /></a>""" % \
822a2c33 390 (reverse('employe_apercu', args=(obj.id,)), settings.STATIC_URL)
b10920ea
JPC
391 _apercu.allow_tags = True
392 _apercu.short_description = u""
b10920ea 393
53ae644d 394 def _nom(self, obj):
53ae644d 395 edit_link = reverse('admin:rh_employe_change', args=(obj.id,))
e6c107de 396 return u"""<a href='%s'><strong>%s</strong></a>""" % \
e49ac947 397 (edit_link, "%s %s" % (obj.nom.upper(), obj.prenom))
53ae644d 398 _nom.allow_tags = True
e49ac947 399 _nom.short_description = u"Employé"
53ae644d
OL
400 _nom.admin_order_field = "nom"
401
e49ac947
JPC
402 def _id(self, obj):
403 return obj.id
404 _id.short_description = u"#"
405 _id.admin_order_field = "id"
406
33232787
JPC
407 def _date_modification(self, obj):
408 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
409 _date_modification.short_description = u'date modification'
410 _date_modification.admin_order_field = 'date_modification'
411
a7f013f5 412 def _dossiers_postes(self, obj):
53ae644d
OL
413 l = []
414 for d in obj.rh_dossiers.all().order_by('-date_debut'):
a7f013f5
JPC
415 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;""" % \
416 ( reverse('dossier_apercu', args=(d.id,)),
417 settings.STATIC_URL,
418 reverse('admin:rh_dossier_change', args=(d.id,))
419 )
420
421 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;""" % \
422 ( reverse('poste_apercu', args=(d.poste.id,)),
423 settings.STATIC_URL,
424 reverse('admin:rh_poste_change', args=(d.poste.id,))
425 )
426 link = u"""<li>%s %s - %s : [%s] %s</li>""" % \
427 (dossier, poste,
53ae644d 428 d.date_debut.year,
a7f013f5
JPC
429 d.poste.id,
430 d.poste.nom,
53ae644d 431 )
b5cc0357
OL
432
433 # Dossier terminé en gris non cliquable
434 if d.date_fin is not None:
a7f013f5 435 link = u"""<li style="color: grey">%s : [%s] %s</li>""" % \
b5cc0357 436 (d.date_debut.year,
a7f013f5
JPC
437 d.poste.id,
438 d.poste.nom,
b5cc0357
OL
439 )
440
53ae644d
OL
441 l.append(link)
442 return "<ul>%s</ul>" % "\n".join(l)
a7f013f5
JPC
443 _dossiers_postes.allow_tags = True
444 _dossiers_postes.short_description = u"Dossiers et postes"
53ae644d
OL
445
446 def queryset(self, request):
447 qs = super(EmployeAdmin, self).queryset(request)
448 return qs.select_related(depth=1).order_by('nom')
449
450 def save_formset(self, request, form, formset, change):
451 instances = formset.save(commit=False)
452 for instance in instances:
453 if instance.__class__ == rh.EmployeCommentaire:
454 instance.owner = request.user
02e69aa2 455 instance.date_creation = datetime.datetime.now()
53ae644d
OL
456 instance.save()
457
458
459
460class EmployeCommentaireAdmin(admin.ModelAdmin):
461 pass
462
463
464class EmployePieceAdmin(admin.ModelAdmin):
465 pass
466
467
468class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 469 list_display = ('nom', '_date_modification', 'user_modification', )
53ae644d
OL
470 inlines = (TypePosteInline,)
471 fieldsets = AUFMetadataAdminMixin.fieldsets + (
472 (None, {
473 'fields': ('nom', )
474 }),
475 )
476
33232787
JPC
477 def _date_modification(self, obj):
478 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
479 _date_modification.short_description = u'date modification'
480 _date_modification.admin_order_field = 'date_modification'
53ae644d 481
95b630cf 482class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
c5964dc2 483 search_fields = ('nom',)
33232787 484 list_display = ('nom', 'type', 'pays', '_date_modification', 'user_modification', )
c5964dc2 485 list_filter = ('type', )
53ae644d
OL
486 inlines = (DossierROInline,)
487 fieldsets = AUFMetadataAdminMixin.fieldsets + (
488 (None, {
489 'fields': ('nom', 'type', 'pays', )
490 }),
491 )
492
33232787
JPC
493 def _date_modification(self, obj):
494 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
495 _date_modification.short_description = u'date modification'
496 _date_modification.admin_order_field = 'date_modification'
497
53ae644d 498
40b35603 499class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect,):
53ae644d
OL
500 form = make_ajax_form(rh.Poste, {
501 'implantation' : 'implantations',
502 'type_poste' : 'typepostes',
503 'responsable' : 'postes',
504 'valeur_point_min' : 'valeurpoints',
505 'valeur_point_max' : 'valeurpoints',
506 })
507 alphabet_filter = 'nom'
508 search_fields = ('nom',
509 'implantation__code',
510 'implantation__nom',
511 'implantation__region__code',
512 'implantation__region__nom',
1ce71322
JPC
513 'rh_dossiers__employe__nom',
514 'rh_dossiers__employe__prenom',
53ae644d
OL
515 )
516 list_display = (
e49ac947 517 '_id',
8f3ca727 518 '_apercu',
53ae644d
OL
519 '_nom',
520 '_occupe_par',
521 'implantation',
c5964dc2 522 '_service',
1ce2ddb9 523 '_responsable',
352fa696 524 'date_debut',
53ae644d 525 'date_fin',
33232787 526 '_date_modification',
53ae644d 527 'user_modification',
53ae644d 528 )
f614ca5c 529 list_filter = (
53ae644d
OL
530 'implantation__region',
531 'implantation',
e8dd3d54 532 'service',
53ae644d
OL
533 'type_poste',
534 'type_poste__famille_emploi',
4c53dda4 535 'vacant',
53ae644d 536 )
e49ac947 537 list_display_links = ('_nom',)
53ae644d
OL
538 fieldsets = AUFMetadataAdminMixin.fieldsets + (
539 (None, {
540 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
541 'service', 'responsable')
542 }),
543 ('Contrat', {
544 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
545 }),
546 ('Recrutement', {
547 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
548 }),
549 ('Rémunération', {
550 'fields': (('classement_min', 'valeur_point_min', 'devise_min', 'salaire_min', 'indemn_min', 'autre_min', ),
551 ('classement_max', 'valeur_point_max' ,'devise_max', 'salaire_max', 'indemn_max', 'autre_max', ),
552 )
553 }),
554 ('Comparatifs de rémunération', {
555 'fields': ('devise_comparaison',
556 ('comp_locale_min', 'comp_locale_max'),
557 ('comp_universite_min', 'comp_universite_max'),
558 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
559 ('comp_ong_min', 'comp_ong_max'),
560 ('comp_autre_min', 'comp_autre_max'))
561 }),
562 ('Justification', {
563 'fields': ('justification',)
564 }),
48a6df80 565 ('Autres Méta-données', {
53ae644d
OL
566 'fields': ('date_debut', 'date_fin')
567 }),
568 )
569
570 inlines = (PosteFinancementInline,
571 PostePieceInline,
572 DossierROInline,
6f037929 573 PosteComparaisonInline,
53ae644d
OL
574 PosteCommentaireInline, )
575
b46d18bc 576
f614ca5c
OL
577 def lookup_allowed(self, key, value):
578 if key in (
579 'date_debut__gte',
580 'date_debut__isnull',
581 'date_fin__lte',
582 'date_fin__isnull',
7f4d1233
OL
583 'implantation__region__id__exact',
584 'implantation__id__exact',
585 'type_poste__id__exact',
586 'type_poste__famille_emploi__id__exact',
587 'service__id__exact',
d48f0922 588 'service__isnull',
7f4d1233 589 'vacant__exact',
f614ca5c
OL
590 ):
591 return True
592
c5964dc2 593
8f3ca727 594 def _apercu(self, poste):
23de8cea 595 view_link = u"""<a onclick="return showAddAnotherPopup(this);" title="Aperçu du poste" href='%s'><img src="%simg/loupe.png" /></a>""" % \
8f3ca727 596 (reverse('poste_apercu', args=(poste.id,)),
822a2c33 597 settings.STATIC_URL,
23de8cea 598 )
e49ac947 599 return view_link
8f3ca727 600 _apercu.allow_tags = True
e49ac947
JPC
601 _apercu.short_description = ''
602
603 def _id(self, obj):
604 return "%s" % obj.id
605 _id.short_description = '#'
606 _id.admin_order_field = 'id'
8f3ca727 607
c5964dc2
OL
608 def _service(self, obj):
609 return obj.service
6c2b1160 610 _service.short_description = 'Service'
53ae644d 611
1ce2ddb9
JPC
612 def _responsable(self, obj):
613 try:
614 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 />""" % \
615 (
616 reverse('poste_apercu', args=(obj.responsable.id,)),
617 settings.STATIC_URL,
618 reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
619 obj.responsable.nom
620 )
621 except:
622 responsable = ''
623
624 try:
783e077a 625 employeposte_change = "%s %s" % (obj.responsable.rh_dossiers.all()[0].employe.nom.upper(), obj.responsable.rh_dossiers.all()[0].employe.prenom)
1ce2ddb9
JPC
626 employe_id = obj.responsable.rh_dossiers.all()[0].id
627 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>""" % \
628 (
629 reverse('employe_apercu', args=(employe_id,)),
630 settings.STATIC_URL,
631 reverse('admin:rh_employe_change', args=(employe_id,)),
632 employe
633 )
634 except:
635 employe = ""
636
637 return "%s %s" % (responsable, employe)
638 _responsable.short_description = 'Responsable'
639 _responsable.allow_tags = True
640
53ae644d 641 def _nom(self, poste):
e49ac947
JPC
642 return """<a href="%s">%s</a>""" % \
643 (reverse('admin:rh_poste_change', args=(poste.id,)),
644 poste.nom
645 )
53ae644d
OL
646 _nom.allow_tags = True
647 _nom.short_description = u'Nom'
648 _nom.admin_order_field = 'nom'
649
33232787
JPC
650 def _date_modification(self, obj):
651 return date(obj.date_modification)
652 _date_modification.short_description = u'date modification'
653 _date_modification.admin_order_field = 'date_modification'
654
53ae644d
OL
655 def _occupe_par(self, obj):
656 """Formatte la méthode Poste.occupe_par() pour l'admin"""
15c5f55a 657 output = u"Vacant"
3195667e 658 if obj.date_fin is not None and obj.date_fin < datetime.date.now():
954ead19 659 return u"s/o"
53ae644d
OL
660 employes = obj.occupe_par()
661 if employes:
662 l = []
663 for e in employes:
b10920ea
JPC
664 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>" % \
665 (reverse('employe_apercu', args=(e.id,)),
822a2c33 666 settings.STATIC_URL,
b10920ea
JPC
667 reverse('admin:rh_employe_change', args=(e.id,)),
668 e
669 )
53ae644d
OL
670 l.append(link)
671 output = "\n<br />".join(l)
672 return output
673 _occupe_par.allow_tags = True
674 _occupe_par.short_description = "Occupé par"
675
676 def save_formset(self, request, form, formset, change):
677 instances = formset.save(commit=False)
678 for instance in instances:
679 if instance.__class__ == rh.PosteCommentaire:
680 instance.owner = request.user
02e69aa2 681 instance.date_creation = datetime.datetime.now()
53ae644d
OL
682 instance.save()
683 formset.save_m2m()
684
685
686class PosteCommentaireAdmin(admin.ModelAdmin):
687 pass
688
689
690class PosteFinancementAdmin(admin.ModelAdmin):
691 pass
692
693
694class PostePieceAdmin(admin.ModelAdmin):
695 fk_name = 'poste'
696
697
698class RemunerationAdmin(admin.ModelAdmin):
699 pass
700
701
702class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
703 fieldsets = AUFMetadataAdminMixin.fieldsets + (
704 (None, {
705 'fields': ('employe', 'implantation', ),
706 }),
707 )
708
709
710class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 711 list_display = ('nom', '_date_modification', 'user_modification', )
53ae644d
OL
712 fieldsets = AUFMetadataAdminMixin.fieldsets + (
713 (None, {
714 'fields': ('nom', ),
715 }),
716 )
717
33232787
JPC
718 def _date_modification(self, obj):
719 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
720 _date_modification.short_description = u'date modification'
721 _date_modification.admin_order_field = 'date_modification'
722
723
53ae644d 724class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 725 list_display = ('code', 'nom', '_date_modification', 'user_modification', )
53ae644d
OL
726 fieldsets = AUFMetadataAdminMixin.fieldsets + (
727 (None, {
728 'fields': ('code', 'nom', ),
729 }),
730 )
731
33232787
JPC
732 def _date_modification(self, obj):
733 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
734 _date_modification.short_description = u'date modification'
735 _date_modification.admin_order_field = 'date_modification'
736
53ae644d 737class TauxChangeAdmin(admin.ModelAdmin):
33232787 738 list_display = ('taux', 'devise', 'annee', '_date_modification', 'user_modification', )
53ae644d
OL
739 list_filter = ('devise', )
740 fieldsets = AUFMetadataAdminMixin.fieldsets + (
741 (None, {
742 'fields': ('taux', 'devise', 'annee', ),
743 }),
744 )
745
33232787
JPC
746 def _date_modification(self, obj):
747 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
748 _date_modification.short_description = u'date modification'
749 _date_modification.admin_order_field = 'date_modification'
750
53ae644d 751class TypeContratAdmin(admin.ModelAdmin):
33232787 752 list_display = ('nom', 'nom_long', '_date_modification', 'user_modification', )
53ae644d
OL
753 fieldsets = AUFMetadataAdminMixin.fieldsets + (
754 (None, {
755 'fields': ('nom', 'nom_long', ),
756 }),
757 )
758
33232787
JPC
759 def _date_modification(self, obj):
760 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
761 _date_modification.short_description = u'date modification'
762 _date_modification.admin_order_field = 'date_modification'
763
53ae644d
OL
764
765class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
766 search_fields = ('nom', 'nom_feminin', )
33232787 767 list_display = ('nom', 'famille_emploi', '_date_modification', 'user_modification', )
53ae644d
OL
768 list_filter = ('famille_emploi', )
769 fieldsets = AUFMetadataAdminMixin.fieldsets + (
770 (None, {
771 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
772 }),
773 )
774
33232787
JPC
775 def _date_modification(self, obj):
776 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
777 _date_modification.short_description = u'date modification'
778 _date_modification.admin_order_field = 'date_modification'
779
53ae644d
OL
780
781class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 782 list_display = ('nom', 'type_paiement', 'nature_remuneration', '_date_modification', 'user_modification', )
53ae644d
OL
783 fieldsets = AUFMetadataAdminMixin.fieldsets + (
784 (None, {
785 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
786 }),
787 )
788
33232787
JPC
789 def _date_modification(self, obj):
790 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
791 _date_modification.short_description = u'date modification'
792 _date_modification.admin_order_field = 'date_modification'
793
53ae644d
OL
794
795class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 796 list_display = ('nom', '_date_modification', 'user_modification', )
53ae644d
OL
797 fieldsets = AUFMetadataAdminMixin.fieldsets + (
798 (None, {
799 'fields': ('nom', )
800 }),
801 )
802
33232787
JPC
803 def _date_modification(self, obj):
804 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
805 _date_modification.short_description = u'date modification'
806 _date_modification.admin_order_field = 'date_modification'
807
53ae644d
OL
808
809class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
33232787 810 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', '_date_modification', 'user_modification', )
c5964dc2 811 list_filter = ('annee', 'devise', )
53ae644d
OL
812 fieldsets = AUFMetadataAdminMixin.fieldsets + (
813 (None, {
814 'fields': ('valeur', 'devise', 'implantation', 'annee', )
815 }),
816 )
817
33232787
JPC
818 def _date_modification(self, obj):
819 return date(obj.date_modification) if obj.date_modification is not None else "(aucune)"
820 _date_modification.short_description = u'date modification'
821 _date_modification.admin_order_field = 'date_modification'
822
53ae644d
OL
823 def _devise_code(self, obj):
824 return obj.devise.code
825 _devise_code.short_description = "Code de la devise"
826
827 def _devise_nom(self, obj):
828 return obj.devise.nom
829 _devise_nom.short_description = "Nom de la devise"
830
831
832admin.site.register(rh.Classement, ClassementAdmin)
833admin.site.register(rh.Devise, DeviseAdmin)
834admin.site.register(rh.Dossier, DossierAdmin)
835admin.site.register(rh.Employe, EmployeAdmin)
836admin.site.register(rh.FamilleEmploi, FamilleEmploiAdmin)
837admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin)
838admin.site.register(rh.Poste, PosteAdmin)
839admin.site.register(rh.ResponsableImplantation, ResponsableImplantationAdmin)
840admin.site.register(rh.Service, ServiceAdmin)
c5964dc2 841admin.site.register(rh.Statut, StatutAdmin)
53ae644d 842admin.site.register(rh.TauxChange, TauxChangeAdmin)
c5964dc2 843admin.site.register(rh.TypeContrat, TypeContratAdmin)
53ae644d
OL
844admin.site.register(rh.TypePoste, TypePosteAdmin)
845admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin)
846admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin)
847admin.site.register(rh.ValeurPoint, ValeurPointAdmin)