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 | ||
53ae644d OL |
130 | class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
131 | readonly_fields = ('owner', ) | |
132 | model = rh.PosteCommentaire | |
133 | extra = 1 | |
134 | ||
135 | ||
136 | class PosteFinancementInline(admin.TabularInline): | |
137 | model = rh.PosteFinancement | |
138 | ||
139 | ||
140 | class PostePieceInline(admin.TabularInline): | |
141 | model = rh.PostePiece | |
142 | ||
143 | ||
144 | class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline): | |
145 | model = rh.Remuneration | |
146 | extra = 1 | |
147 | ||
148 | ||
149 | class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline): | |
150 | pass | |
151 | ||
152 | ||
153 | class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline): | |
154 | model = rh.TypePoste | |
155 | ||
156 | ||
157 | class AyantDroitAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin): | |
158 | """ | |
159 | L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé. | |
160 | """ | |
161 | alphabet_filter = 'nom' | |
162 | search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', ) | |
163 | list_display = ('_employe', 'lien_parente', '_ayantdroit', ) | |
164 | inlines = (AyantDroitCommentaireInline,) | |
165 | readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',) | |
166 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
167 | ("Lien avec l'employé", { | |
168 | 'fields': (('employe', 'lien_parente'), ) | |
169 | }), | |
170 | ||
171 | ('Identification', { | |
172 | 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', ) | |
173 | }), | |
174 | ) | |
175 | ||
176 | def save_formset(self, request, form, formset, change): | |
177 | instances = formset.save(commit=False) | |
178 | for instance in instances: | |
179 | if instance.__class__ == rh.AyantDroitCommentaire: | |
180 | instance.owner = request.user | |
181 | instance.save() | |
182 | ||
183 | def _ayantdroit(self, obj): | |
184 | return unicode(obj) | |
185 | _ayantdroit.short_description = u'Ayant droit' | |
186 | ||
187 | def _employe(self, obj): | |
188 | return unicode(obj.employe) | |
189 | _employe.short_description = u'Employé' | |
190 | ||
191 | def has_add_permission(self, request): | |
192 | return False | |
193 | ||
194 | class AyantDroitCommentaireAdmin(admin.ModelAdmin): | |
195 | pass | |
196 | ||
197 | ||
198 | class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
c5964dc2 | 199 | list_display = ('_classement', 'date_modification', 'user_modification', ) |
53ae644d OL |
200 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
201 | (None, { | |
202 | 'fields': ('type', 'echelon', 'degre', 'coefficient', ) | |
203 | }), | |
204 | ) | |
205 | ||
c5964dc2 OL |
206 | def _classement(self, obj): |
207 | return unicode(obj) | |
208 | _classement.short_description = u"Classement" | |
53ae644d OL |
209 | |
210 | class CommentaireAdmin(admin.ModelAdmin): | |
211 | pass | |
212 | ||
213 | ||
53ae644d | 214 | class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
c5964dc2 | 215 | list_display = ('code', 'nom', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
216 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
217 | (None, { | |
218 | 'fields': ('code', 'nom', ), | |
219 | }), | |
220 | ) | |
221 | ||
222 | ||
223 | class DossierAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect): | |
224 | alphabet_filter = 'employe__nom' | |
225 | search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin') | |
226 | list_display = ( | |
227 | '_id', | |
228 | '_poste', | |
229 | '_employe', | |
230 | '_date_debut', | |
231 | '_date_fin', | |
232 | 'date_modification', | |
c5964dc2 | 233 | 'user_modification', |
53ae644d OL |
234 | 'actif', |
235 | ) | |
236 | list_filter = ( | |
237 | 'poste__implantation__region', | |
238 | 'poste__implantation', | |
239 | 'poste__type_poste', | |
240 | 'poste__type_poste__famille_emploi', | |
241 | 'rh_contrats__type_contrat', | |
242 | 'actif', | |
243 | ) | |
244 | inlines = (DossierPieceInline, ContratInline, | |
245 | RemunerationInline, | |
53ae644d OL |
246 | DossierCommentaireInline, |
247 | ) | |
248 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
249 | (None, { | |
250 | 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',) | |
251 | }), | |
252 | ('Recrutement', { | |
253 | 'fields': ('statut_residence', 'remplacement', 'remplacement_de', ) | |
254 | }), | |
255 | ('Rémunération', { | |
256 | 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),) | |
257 | }), | |
258 | ('Occupation du Poste par cet Employe', { | |
259 | 'fields': (('date_debut', 'date_fin'), ) | |
260 | }), | |
261 | ) | |
262 | form = make_ajax_form(rh.Dossier, { | |
263 | 'employe' : 'employes', | |
264 | 'poste' : 'postes', | |
265 | 'remplacement_de' : 'dossiers', | |
266 | }) | |
267 | ||
268 | def lookup_allowed(self, key, value): | |
269 | if key in ( | |
270 | 'employe__nom__istartswith', | |
271 | 'actif__exact', | |
272 | 'poste__implantation__region__id__exact', | |
273 | 'poste__implantation__id__exact', | |
274 | 'poste__type_poste__id__exact', | |
275 | 'poste__type_poste__famille_emploi__id__exact', | |
276 | 'rh_contrats__type_contrat__id__exact', | |
277 | ): | |
278 | return True | |
279 | ||
280 | def _id(self, d): | |
281 | 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>""" % \ | |
282 | (reverse('dossier_apercu', args=(d.id,)), | |
283 | d.id, | |
284 | reverse('admin:rh_dossier_change', args=(d.id,)), | |
285 | settings.MEDIA_URL, | |
286 | ) | |
287 | return link | |
288 | _id.allow_tags = True | |
289 | _id.short_description = u'#' | |
290 | _id.admin_order_field = 'id' | |
291 | ||
292 | ||
293 | def _actif(self, dossier): | |
294 | if dossier.employe.actif: | |
295 | html = """<img alt="True" src="%simg/admin/icon-yes.gif">""" | |
296 | else: | |
297 | html = """<img alt="False" src="%simg/admin/icon-no.gif">""" | |
298 | return html % settings.ADMIN_MEDIA_PREFIX | |
299 | _actif.allow_tags = True | |
300 | _actif.short_description = u'Employé actif' | |
301 | _actif.admin_order_field = 'employe__actif' | |
302 | ||
303 | def _date_debut(self, obj): | |
304 | return obj.date_debut | |
305 | _date_debut.short_description = u'Occupation début' | |
306 | _date_debut.admin_order_field = 'date_debut' | |
307 | ||
308 | def _date_fin(self, obj): | |
309 | return obj.date_fin | |
310 | _date_fin.short_description = u'Occupation fin' | |
311 | _date_fin.admin_order_field = 'date_fin' | |
312 | ||
313 | def _poste(self, dossier): | |
314 | 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>""" % \ | |
315 | (reverse('poste_apercu', args=(dossier.poste.id,)), | |
316 | dossier.poste, | |
317 | reverse('admin:rh_poste_change', args=(dossier.poste.id,)), | |
318 | settings.MEDIA_URL, | |
319 | ) | |
320 | return link | |
321 | _poste.allow_tags = True | |
322 | _poste.short_description = u'Poste' | |
323 | _poste.admin_order_field = 'poste__nom' | |
324 | ||
325 | def _employe(self, obj): | |
326 | employe = obj.employe | |
327 | view_link = reverse('employe_apercu', args=(employe.id,)) | |
328 | edit_link = reverse('admin:rh_employe_change', args=(employe.id,)) | |
329 | ||
330 | if employe.actif == False: | |
331 | style = "color: grey"; | |
332 | edit = "" | |
333 | else: | |
334 | style = "" | |
335 | edit = u"""<a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % (edit_link, settings.MEDIA_URL,) | |
336 | return u"""<a onclick="return showAddAnotherPopup(this);" href='%s' style="%s;">[%s] %s %s</a>%s | |
337 | """ % \ | |
338 | (view_link, style, employe.id, employe.nom.upper(), employe.prenom.title(), edit) | |
339 | _employe.allow_tags = True | |
340 | _employe.short_description = u"Employé ([code] NOM Prénom)" | |
341 | _employe.admin_order_field = "employe__nom" | |
342 | ||
343 | def save_formset(self, request, form, formset, change): | |
344 | instances = formset.save(commit=False) | |
345 | for instance in instances: | |
346 | if instance.__class__ == rh.DossierCommentaire: | |
347 | instance.owner = request.user | |
348 | instance.save() | |
349 | ||
350 | ||
351 | class DossierPieceAdmin(admin.ModelAdmin): | |
352 | pass | |
353 | ||
354 | ||
355 | class DossierCommentaireAdmin(admin.ModelAdmin): | |
356 | pass | |
357 | ||
358 | ||
359 | class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin): | |
360 | alphabet_filter = 'nom' | |
361 | DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
362 | search_fields = ('id', 'nom', 'prenom', 'nom_affichage', ) | |
363 | ordering = ('nom', ) | |
364 | form = EmployeAdminForm | |
365 | list_display = ('_nom', '_dossiers', 'date_modification', 'user_modification', 'actif',) | |
366 | list_filter = ('rh_dossiers__poste__implantation__region', 'rh_dossiers__poste__implantation', 'actif', ) | |
367 | inlines = (AyantDroitInline, | |
368 | DossierROInline, | |
369 | EmployePieceInline, | |
370 | EmployeCommentaireInline) | |
371 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
372 | ('Identification', { | |
373 | 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', ) | |
374 | }), | |
375 | ('Informations personnelles', { | |
376 | 'fields': ('situation_famille', 'date_entree', ) | |
377 | }), | |
378 | ('Coordonnées', { | |
379 | 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', ) | |
380 | }), | |
381 | ) | |
382 | ||
383 | def _nom(self, obj): | |
384 | view_link = reverse('employe_apercu', args=(obj.id,)) | |
385 | edit_link = reverse('admin:rh_employe_change', args=(obj.id,)) | |
386 | return u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>[%s] %s %s</a> | |
387 | <a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % \ | |
388 | (view_link, obj.id, obj.nom.upper(), obj.prenom.title(), edit_link, settings.MEDIA_URL,) | |
389 | _nom.allow_tags = True | |
390 | _nom.short_description = u"Employé ([code] NOM Prénom)" | |
391 | _nom.admin_order_field = "nom" | |
392 | ||
393 | def _dossiers(self, obj): | |
394 | l = [] | |
395 | for d in obj.rh_dossiers.all().order_by('-date_debut'): | |
396 | style = "" | |
397 | 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,) | |
398 | if d.date_fin is not None: | |
399 | edit = "" | |
400 | style = u"color: grey"; | |
401 | link = u"""<li><a style="%s;" onclick="return showAddAnotherPopup(this);" href='%s'>%s : %s</a>%s</li>""" % \ | |
402 | (style, | |
403 | reverse('dossier_apercu', args=(d.id,)), | |
404 | d.date_debut.year, | |
405 | d.poste, | |
406 | edit, | |
407 | ) | |
408 | l.append(link) | |
409 | return "<ul>%s</ul>" % "\n".join(l) | |
410 | _dossiers.allow_tags = True | |
411 | _dossiers.short_description = u"Dossiers" | |
412 | ||
413 | def queryset(self, request): | |
414 | qs = super(EmployeAdmin, self).queryset(request) | |
415 | return qs.select_related(depth=1).order_by('nom') | |
416 | ||
417 | def save_formset(self, request, form, formset, change): | |
418 | instances = formset.save(commit=False) | |
419 | for instance in instances: | |
420 | if instance.__class__ == rh.EmployeCommentaire: | |
421 | instance.owner = request.user | |
422 | instance.save() | |
423 | ||
424 | ||
425 | ||
426 | class EmployeCommentaireAdmin(admin.ModelAdmin): | |
427 | pass | |
428 | ||
429 | ||
430 | class EmployePieceAdmin(admin.ModelAdmin): | |
431 | pass | |
432 | ||
433 | ||
434 | class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
c5964dc2 | 435 | list_display = ('nom', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
436 | inlines = (TypePosteInline,) |
437 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
438 | (None, { | |
439 | 'fields': ('nom', ) | |
440 | }), | |
441 | ) | |
442 | ||
443 | ||
444 | class OrganismeBstgAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin): | |
c5964dc2 OL |
445 | search_fields = ('nom',) |
446 | list_display = ('nom', 'type', 'pays', 'date_modification', 'user_modification', 'actif', ) | |
447 | list_filter = ('type', ) | |
53ae644d OL |
448 | inlines = (DossierROInline,) |
449 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
450 | (None, { | |
451 | 'fields': ('nom', 'type', 'pays', ) | |
452 | }), | |
453 | ) | |
454 | ||
455 | ||
456 | class PosteAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect): | |
457 | form = make_ajax_form(rh.Poste, { | |
458 | 'implantation' : 'implantations', | |
459 | 'type_poste' : 'typepostes', | |
460 | 'responsable' : 'postes', | |
461 | 'valeur_point_min' : 'valeurpoints', | |
462 | 'valeur_point_max' : 'valeurpoints', | |
463 | }) | |
464 | alphabet_filter = 'nom' | |
465 | search_fields = ('nom', | |
466 | 'implantation__code', | |
467 | 'implantation__nom', | |
468 | 'implantation__region__code', | |
469 | 'implantation__region__nom', | |
470 | ) | |
471 | list_display = ( | |
472 | '_nom', | |
473 | '_occupe_par', | |
474 | 'implantation', | |
c5964dc2 | 475 | '_service', |
53ae644d OL |
476 | 'date_debut', |
477 | 'date_fin', | |
478 | 'date_modification', | |
479 | 'user_modification', | |
480 | 'actif', | |
481 | ) | |
482 | list_filter = ('service', | |
483 | 'implantation__region', | |
484 | 'implantation', | |
485 | 'type_poste', | |
486 | 'type_poste__famille_emploi', | |
4c53dda4 | 487 | 'vacant', |
53ae644d OL |
488 | 'actif', |
489 | ) | |
490 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
491 | (None, { | |
492 | 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste', | |
493 | 'service', 'responsable') | |
494 | }), | |
495 | ('Contrat', { | |
496 | 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), ) | |
497 | }), | |
498 | ('Recrutement', { | |
499 | 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),) | |
500 | }), | |
501 | ('Rémunération', { | |
502 | 'fields': (('classement_min', 'valeur_point_min', 'devise_min', 'salaire_min', 'indemn_min', 'autre_min', ), | |
503 | ('classement_max', 'valeur_point_max' ,'devise_max', 'salaire_max', 'indemn_max', 'autre_max', ), | |
504 | ) | |
505 | }), | |
506 | ('Comparatifs de rémunération', { | |
507 | 'fields': ('devise_comparaison', | |
508 | ('comp_locale_min', 'comp_locale_max'), | |
509 | ('comp_universite_min', 'comp_universite_max'), | |
510 | ('comp_fonctionpub_min', 'comp_fonctionpub_max'), | |
511 | ('comp_ong_min', 'comp_ong_max'), | |
512 | ('comp_autre_min', 'comp_autre_max')) | |
513 | }), | |
514 | ('Justification', { | |
515 | 'fields': ('justification',) | |
516 | }), | |
517 | ('Autres Metadata', { | |
518 | 'fields': ('date_debut', 'date_fin') | |
519 | }), | |
520 | ) | |
521 | ||
522 | inlines = (PosteFinancementInline, | |
523 | PostePieceInline, | |
524 | DossierROInline, | |
525 | PosteCommentaireInline, ) | |
526 | ||
c5964dc2 OL |
527 | |
528 | def _service(self, obj): | |
529 | return obj.service | |
53ae644d OL |
530 | |
531 | def _nom(self, poste): | |
532 | 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>""" % \ | |
533 | (reverse('poste_apercu', args=(poste.id,)), | |
534 | poste.nom, | |
535 | reverse('admin:rh_poste_change', args=(poste.id,)), | |
536 | settings.MEDIA_URL, | |
537 | ) | |
538 | return link | |
539 | _nom.allow_tags = True | |
540 | _nom.short_description = u'Nom' | |
541 | _nom.admin_order_field = 'nom' | |
542 | ||
543 | def _occupe_par(self, obj): | |
544 | """Formatte la méthode Poste.occupe_par() pour l'admin""" | |
15c5f55a | 545 | output = u"Vacant" |
bdc6d9ff OL |
546 | if obj.actif is False: |
547 | return u"-" | |
53ae644d OL |
548 | employes = obj.occupe_par() |
549 | if employes: | |
550 | l = [] | |
551 | for e in employes: | |
552 | link = "<a href='%s'>%s</a>" % \ | |
553 | (reverse('admin:rh_employe_change', args=(e.id,)), | |
554 | e) | |
555 | l.append(link) | |
556 | output = "\n<br />".join(l) | |
557 | return output | |
558 | _occupe_par.allow_tags = True | |
559 | _occupe_par.short_description = "Occupé par" | |
560 | ||
561 | def save_formset(self, request, form, formset, change): | |
562 | instances = formset.save(commit=False) | |
563 | for instance in instances: | |
564 | if instance.__class__ == rh.PosteCommentaire: | |
565 | instance.owner = request.user | |
566 | instance.save() | |
567 | formset.save_m2m() | |
568 | ||
569 | ||
570 | class PosteCommentaireAdmin(admin.ModelAdmin): | |
571 | pass | |
572 | ||
573 | ||
574 | class PosteFinancementAdmin(admin.ModelAdmin): | |
575 | pass | |
576 | ||
577 | ||
578 | class PostePieceAdmin(admin.ModelAdmin): | |
579 | fk_name = 'poste' | |
580 | ||
581 | ||
582 | class RemunerationAdmin(admin.ModelAdmin): | |
583 | pass | |
584 | ||
585 | ||
586 | class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
587 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
588 | (None, { | |
589 | 'fields': ('employe', 'implantation', ), | |
590 | }), | |
591 | ) | |
592 | ||
593 | ||
594 | class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
c5964dc2 | 595 | list_display = ('nom', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
596 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
597 | (None, { | |
598 | 'fields': ('nom', ), | |
599 | }), | |
600 | ) | |
601 | ||
602 | class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
c5964dc2 | 603 | list_display = ('code', 'nom', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
604 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
605 | (None, { | |
606 | 'fields': ('code', 'nom', ), | |
607 | }), | |
608 | ) | |
609 | ||
610 | class TauxChangeAdmin(admin.ModelAdmin): | |
c5964dc2 | 611 | list_display = ('taux', 'devise', 'annee', 'date_modification', 'user_modification', ) |
53ae644d OL |
612 | list_filter = ('devise', ) |
613 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
614 | (None, { | |
615 | 'fields': ('taux', 'devise', 'annee', ), | |
616 | }), | |
617 | ) | |
618 | ||
619 | class TypeContratAdmin(admin.ModelAdmin): | |
c5964dc2 | 620 | list_display = ('nom', 'nom_long', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
621 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
622 | (None, { | |
623 | 'fields': ('nom', 'nom_long', ), | |
624 | }), | |
625 | ) | |
626 | ||
627 | ||
628 | class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
629 | search_fields = ('nom', 'nom_feminin', ) | |
c5964dc2 | 630 | list_display = ('nom', 'famille_emploi', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
631 | list_filter = ('famille_emploi', ) |
632 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
633 | (None, { | |
634 | 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', ) | |
635 | }), | |
636 | ) | |
637 | ||
638 | ||
639 | class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
c5964dc2 | 640 | list_display = ('nom', 'type_paiement', 'nature_remuneration', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
641 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
642 | (None, { | |
643 | 'fields': ('nom', 'type_paiement', 'nature_remuneration', ) | |
644 | }), | |
645 | ) | |
646 | ||
647 | ||
648 | class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
c5964dc2 | 649 | list_display = ('nom', 'date_modification', 'user_modification', 'actif', ) |
53ae644d OL |
650 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
651 | (None, { | |
652 | 'fields': ('nom', ) | |
653 | }), | |
654 | ) | |
655 | ||
656 | ||
657 | class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): | |
c5964dc2 OL |
658 | list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', 'date_modification', 'user_modification', ) |
659 | list_filter = ('annee', 'devise', ) | |
53ae644d OL |
660 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
661 | (None, { | |
662 | 'fields': ('valeur', 'devise', 'implantation', 'annee', ) | |
663 | }), | |
664 | ) | |
665 | ||
666 | def _devise_code(self, obj): | |
667 | return obj.devise.code | |
668 | _devise_code.short_description = "Code de la devise" | |
669 | ||
670 | def _devise_nom(self, obj): | |
671 | return obj.devise.nom | |
672 | _devise_nom.short_description = "Nom de la devise" | |
673 | ||
674 | ||
675 | admin.site.register(rh.Classement, ClassementAdmin) | |
676 | admin.site.register(rh.Devise, DeviseAdmin) | |
677 | admin.site.register(rh.Dossier, DossierAdmin) | |
678 | admin.site.register(rh.Employe, EmployeAdmin) | |
679 | admin.site.register(rh.FamilleEmploi, FamilleEmploiAdmin) | |
680 | admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin) | |
681 | admin.site.register(rh.Poste, PosteAdmin) | |
682 | admin.site.register(rh.ResponsableImplantation, ResponsableImplantationAdmin) | |
683 | admin.site.register(rh.Service, ServiceAdmin) | |
c5964dc2 | 684 | admin.site.register(rh.Statut, StatutAdmin) |
53ae644d | 685 | admin.site.register(rh.TauxChange, TauxChangeAdmin) |
c5964dc2 | 686 | admin.site.register(rh.TypeContrat, TypeContratAdmin) |
53ae644d OL |
687 | admin.site.register(rh.TypePoste, TypePosteAdmin) |
688 | admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin) | |
689 | admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin) | |
690 | admin.site.register(rh.ValeurPoint, ValeurPointAdmin) |