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