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