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