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