Commit | Line | Data |
---|---|---|
53ae644d OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
53ae644d | 3 | import datetime |
6fb68b2f | 4 | |
53ae644d | 5 | from django.core.urlresolvers import reverse |
50fa9bc1 | 6 | from django.contrib import admin |
53ae644d | 7 | from django.conf import settings |
f7badf51 | 8 | from django.db.models import Q, Count |
5f36f262 | 9 | from django.template.defaultfilters import date |
5db1c5a3 | 10 | from django.utils.formats import date_format |
fc4bf968 | 11 | |
75f0e87b | 12 | from ajax_select import make_ajax_form |
d41d8e47 | 13 | |
75f0e87b DB |
14 | from auf.django.metadata.admin import \ |
15 | AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, \ | |
16 | AUF_METADATA_READONLY_FIELDS | |
fc4bf968 | 17 | import auf.django.references.models as ref |
75f0e87b | 18 | |
018c8eaf | 19 | from project.decorators import in_drh_or_admin |
d41d8e47 | 20 | from project.groups import grp_correspondants_rh |
afd3be54 | 21 | from project.groups import get_employe_from_user |
75f0e87b | 22 | import project.rh.models as rh |
6fb68b2f DB |
23 | from project.rh.forms import ContratForm, AyantDroitForm, EmployeAdminForm, \ |
24 | AjaxSelect, DossierForm, ResponsableInlineForm | |
75f0e87b | 25 | from project.rh.change_list import ChangeList |
fc4bf968 | 26 | |
82af5c19 | 27 | |
08a9b6fc EMS |
28 | class BaseAdmin(admin.ModelAdmin): |
29 | ||
30 | class Media: | |
c05a135e EMS |
31 | css = {'screen': ( |
32 | 'css/admin_custom.css', | |
33 | 'jquery-autocomplete/jquery.autocomplete.css', | |
34 | )} | |
35 | js = ( | |
36 | 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', | |
37 | 'jquery-autocomplete/jquery.autocomplete.min.js', | |
38 | ) | |
08a9b6fc EMS |
39 | |
40 | ||
7ba822a6 OL |
41 | class ArchiveMixin(object): |
42 | """ | |
43 | Archive Mixin pour gérer le queryset et le display | |
44 | NON COMPRIS : list_filter, et list_display, field à setter dans la classe. | |
45 | """ | |
46 | ||
47 | def queryset(self, request): | |
48 | return self.model._base_manager | |
49 | ||
50 | def _archive(self, obj): | |
51 | if obj.archive: | |
52 | return "oui" | |
53 | else: | |
54 | return "non" | |
55 | _archive.short_description = u'Archivé' | |
56 | _archive.admin_order_field = 'archive' | |
57 | ||
fc4bf968 | 58 | |
9da4c195 JPC |
59 | class RegionProxy(ref.Region): |
60 | """ Proxy utilisé pour les organigrammes par région """ | |
61 | class Meta: | |
62 | proxy = True | |
63 | verbose_name = u"Organigramme par région" | |
64 | verbose_name_plural = u"Organigramme par région" | |
65 | ||
66 | ||
82af5c19 JPC |
67 | class ImplantationProxy(ref.Implantation): |
68 | """ Proxy utilisé pour les organigrammes par implantation """ | |
69 | class Meta: | |
70 | proxy = True | |
71 | verbose_name = u"Organigramme par implantations" | |
72 | verbose_name_plural = u"Organigramme par implantations" | |
73 | ||
22343fe7 | 74 | |
5c0f1778 JPC |
75 | class ServiceProxy(rh.Service): |
76 | """ Proxy utilisé pour les organigrammes opar service """ | |
f7badf51 | 77 | |
5c0f1778 JPC |
78 | class Meta: |
79 | proxy = True | |
80 | verbose_name = u"Organigramme par services" | |
81 | verbose_name_plural = u"Organigramme par services" | |
82 | ||
22343fe7 | 83 | |
5c0f1778 JPC |
84 | class EmployeProxy(rh.Employe): |
85 | """ Proxy utilisé pour les organigrammes des employés """ | |
22343fe7 OL |
86 | class Meta: |
87 | proxy = True | |
88 | verbose_name = u"Organigramme des employés" | |
89 | verbose_name_plural = u"Organigramme des employés" | |
90 | ||
f614ca5c | 91 | |
40b35603 | 92 | class DateRangeMixin(object): |
a17e2236 | 93 | prefixe_recherche_temporelle = "" |
22343fe7 | 94 | |
40b35603 | 95 | def get_changelist(self, request, **kwargs): |
22343fe7 | 96 | if 'HTTP_REFERER' in request.META.keys(): |
910e39e5 OL |
97 | referer = request.META['HTTP_REFERER'] |
98 | referer = "/".join(referer.split('/')[3:]) | |
99 | referer = "/%s" % referer.split('?')[0] | |
22343fe7 OL |
100 | change_list_view = 'admin:%s_%s_changelist' % ( |
101 | self.model._meta.app_label, | |
102 | self.model.__name__.lower(),) | |
910e39e5 OL |
103 | if referer != reverse(change_list_view): |
104 | params = request.GET.copy() | |
22343fe7 | 105 | params.update({'statut': 'Actif'}) |
910e39e5 | 106 | request.GET = params |
40b35603 | 107 | return ChangeList |
3195667e | 108 | |
22343fe7 | 109 | |
53ae644d OL |
110 | # Override of the InlineModelAdmin to support the link in the tabular inline |
111 | class LinkedInline(admin.options.InlineModelAdmin): | |
112 | template = "admin/linked.html" | |
113 | admin_model_path = None | |
114 | ||
115 | def __init__(self, *args): | |
116 | super(LinkedInline, self).__init__(*args) | |
117 | if self.admin_model_path is None: | |
118 | self.admin_model_path = self.model.__name__.lower() | |
119 | ||
120 | ||
121 | class ProtectRegionMixin(object): | |
122 | ||
123 | def queryset(self, request): | |
53ae644d OL |
124 | qs = super(ProtectRegionMixin, self).queryset(request) |
125 | ||
53ae644d | 126 | user_groups = request.user.groups.all() |
a12ddd52 | 127 | if in_drh_or_admin(request.user): |
53ae644d OL |
128 | return qs |
129 | ||
130 | if grp_correspondants_rh in user_groups: | |
131 | employe = get_employe_from_user(request.user) | |
22343fe7 OL |
132 | q = Q(**{self.model.prefix_implantation: \ |
133 | employe.implantation.region}) | |
53ae644d OL |
134 | qs = qs.filter(q).distinct() |
135 | return qs | |
136 | return qs.none() | |
137 | ||
c0be8705 OL |
138 | def has_add_permission(self, request): |
139 | if not in_drh_or_admin(request.user): | |
140 | return False | |
141 | else: | |
142 | return True | |
143 | ||
53ae644d | 144 | def has_change_permission(self, request, obj=None): |
20b4867c | 145 | user_groups = request.user.groups.all() |
a0d365ed | 146 | |
0309aeb4 DB |
147 | # Lock pour autoriser uniquement les DRH à utiliser RH |
148 | if not in_drh_or_admin(request.user): | |
149 | return False | |
150 | ||
a18bc295 | 151 | if len(user_groups) == 0 and not request.user.is_superuser: |
20b4867c OL |
152 | return False |
153 | ||
53ae644d OL |
154 | if obj is None: |
155 | return True | |
156 | ids = [o.id for o in self.queryset(request)] | |
157 | return obj.id in ids | |
158 | ||
159 | ||
160 | # Inlines | |
161 | ||
162 | class ReadOnlyInlineMixin(object): | |
22343fe7 | 163 | |
53ae644d | 164 | def get_readonly_fields(self, request, obj=None): |
22343fe7 OL |
165 | return [f.name for f in self.model._meta.fields \ |
166 | if f.name not in AUF_METADATA_READONLY_FIELDS] | |
53ae644d OL |
167 | |
168 | ||
169 | class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline): | |
170 | model = rh.AyantDroit | |
171 | form = AyantDroitForm | |
172 | extra = 0 | |
173 | ||
174 | fieldsets = ( | |
175 | (None, { | |
22343fe7 OL |
176 | 'fields': ( |
177 | ('nom', 'prenom'), | |
178 | ('nom_affichage', 'genre'), | |
179 | 'nationalite', | |
180 | 'date_naissance', | |
181 | 'lien_parente', | |
182 | )}), | |
53ae644d OL |
183 | ) |
184 | ||
185 | ||
22343fe7 OL |
186 | class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, \ |
187 | admin.TabularInline): | |
53ae644d OL |
188 | readonly_fields = ('owner', ) |
189 | model = rh.AyantDroitCommentaire | |
190 | extra = 1 | |
191 | ||
192 | ||
193 | class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline): | |
194 | form = ContratForm | |
195 | model = rh.Contrat | |
196 | extra = 1 | |
197 | ||
198 | ||
199 | class DossierROInline(ReadOnlyInlineMixin, LinkedInline): | |
200 | template = "admin/rh/dossier/linked.html" | |
201 | exclude = AUF_METADATA_READONLY_FIELDS | |
202 | model = rh.Dossier | |
203 | extra = 0 | |
204 | can_delete = False | |
205 | ||
206 | def has_add_permission(self, request=None): | |
207 | return False | |
208 | ||
209 | def has_change_permission(self, request, obj=None): | |
210 | return False | |
211 | ||
212 | def has_delete_permission(self, request, obj=None): | |
213 | return False | |
214 | ||
215 | ||
22343fe7 OL |
216 | class DossierCommentaireInline(AUFMetadataInlineAdminMixin, \ |
217 | admin.TabularInline): | |
53ae644d OL |
218 | readonly_fields = ('owner', ) |
219 | model = rh.DossierCommentaire | |
220 | extra = 1 | |
221 | ||
222 | ||
223 | class DossierPieceInline(admin.TabularInline): | |
224 | model = rh.DossierPiece | |
225 | extra = 4 | |
226 | ||
227 | ||
228 | class EmployeInline(admin.TabularInline): | |
229 | model = rh.Employe | |
230 | ||
22343fe7 OL |
231 | |
232 | class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, \ | |
233 | admin.TabularInline): | |
53ae644d OL |
234 | readonly_fields = ('owner', ) |
235 | model = rh.EmployeCommentaire | |
236 | extra = 1 | |
237 | ||
238 | ||
239 | class EmployePieceInline(admin.TabularInline): | |
240 | model = rh.EmployePiece | |
241 | extra = 4 | |
242 | ||
243 | ||
53ae644d OL |
244 | class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
245 | readonly_fields = ('owner', ) | |
246 | model = rh.PosteCommentaire | |
247 | extra = 1 | |
248 | ||
249 | ||
250 | class PosteFinancementInline(admin.TabularInline): | |
251 | model = rh.PosteFinancement | |
252 | ||
253 | ||
254 | class PostePieceInline(admin.TabularInline): | |
255 | model = rh.PostePiece | |
256 | ||
257 | ||
258 | class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline): | |
259 | model = rh.Remuneration | |
260 | extra = 1 | |
261 | ||
262 | ||
263 | class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline): | |
264 | pass | |
265 | ||
266 | ||
267 | class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline): | |
268 | model = rh.TypePoste | |
269 | ||
270 | ||
6f037929 OL |
271 | class PosteComparaisonInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
272 | model = rh.PosteComparaison | |
273 | ||
53ae644d | 274 | |
08a9b6fc | 275 | class ClassementAdmin(AUFMetadataAdminMixin, BaseAdmin): |
33232787 | 276 | list_display = ('_classement', '_date_modification', 'user_modification', ) |
53ae644d OL |
277 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
278 | (None, { | |
22343fe7 | 279 | 'fields': ('type', 'echelon', 'degre', 'coefficient',)}), |
53ae644d OL |
280 | ) |
281 | ||
c5964dc2 OL |
282 | def _classement(self, obj): |
283 | return unicode(obj) | |
284 | _classement.short_description = u"Classement" | |
53ae644d | 285 | |
33232787 | 286 | def _date_modification(self, obj): |
22343fe7 OL |
287 | return date(obj.date_modification) \ |
288 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
289 | _date_modification.short_description = u'date modification' |
290 | _date_modification.admin_order_field = 'date_modification' | |
291 | ||
22343fe7 | 292 | |
08a9b6fc | 293 | class DeviseAdmin(AUFMetadataAdminMixin, BaseAdmin, ArchiveMixin): |
22343fe7 OL |
294 | list_display = ( |
295 | 'code', | |
296 | 'nom', | |
297 | '_archive', | |
298 | '_date_modification', | |
299 | 'user_modification', | |
300 | ) | |
edb35076 | 301 | list_filter = ('archive', ) |
53ae644d OL |
302 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
303 | (None, { | |
edb35076 | 304 | 'fields': ('code', 'nom', 'archive', ), |
53ae644d OL |
305 | }), |
306 | ) | |
307 | ||
33232787 | 308 | def _date_modification(self, obj): |
22343fe7 OL |
309 | return date(obj.date_modification) \ |
310 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
311 | _date_modification.short_description = u'date modification' |
312 | _date_modification.admin_order_field = 'date_modification' | |
53ae644d | 313 | |
22343fe7 | 314 | |
08a9b6fc EMS |
315 | class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin, |
316 | ProtectRegionMixin, BaseAdmin, AjaxSelect): | |
53ae644d | 317 | alphabet_filter = 'employe__nom' |
22343fe7 | 318 | search_fields = ( |
35cff4a7 EMS |
319 | 'id', |
320 | 'employe__id', | |
321 | 'poste__id', | |
322 | 'employe__nom', | |
323 | 'employe__prenom', | |
324 | 'poste__nom', | |
325 | 'poste__nom_feminin', | |
326 | 'poste__implantation__nom', | |
327 | ) | |
53ae644d OL |
328 | list_display = ( |
329 | '_id', | |
e49ac947 JPC |
330 | '_apercu', |
331 | '_nom', | |
53ae644d | 332 | '_employe', |
5db1c5a3 DB |
333 | '_poste', |
334 | '_region', | |
335 | '_implantation', | |
53ae644d OL |
336 | '_date_debut', |
337 | '_date_fin', | |
33232787 | 338 | '_date_modification', |
a47ed016 | 339 | '_dae', |
53ae644d | 340 | ) |
e49ac947 | 341 | list_display_links = ('_nom',) |
53ae644d OL |
342 | list_filter = ( |
343 | 'poste__implantation__region', | |
344 | 'poste__implantation', | |
7bf28694 | 345 | 'poste__type_poste__categorie_emploi', |
7baa5523 | 346 | 'poste__type_poste', |
53ae644d | 347 | 'rh_contrats__type_contrat', |
6bee05ff | 348 | 'principal', |
53ae644d OL |
349 | ) |
350 | inlines = (DossierPieceInline, ContratInline, | |
351 | RemunerationInline, | |
53ae644d OL |
352 | DossierCommentaireInline, |
353 | ) | |
354 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
355 | (None, { | |
22343fe7 OL |
356 | 'fields': ( |
357 | 'employe', | |
358 | 'poste', | |
6bee05ff | 359 | 'principal', |
22343fe7 OL |
360 | 'statut', |
361 | 'organisme_bstg',)}), | |
53ae644d | 362 | ('Recrutement', { |
22343fe7 OL |
363 | 'fields': ( |
364 | 'statut_residence', | |
365 | 'remplacement', | |
366 | 'remplacement_de', )}), | |
53ae644d | 367 | ('Rémunération', { |
22343fe7 OL |
368 | 'fields': ( |
369 | 'classement', | |
370 | ('regime_travail', 'regime_travail_nb_heure_semaine'),)}), | |
53ae644d | 371 | ('Occupation du Poste par cet Employe', { |
22343fe7 OL |
372 | 'fields': (('date_debut', 'date_fin'), )} |
373 | ), | |
53ae644d | 374 | ) |
22343fe7 OL |
375 | form = make_ajax_form(rh.Dossier, { |
376 | 'employe': 'employes', | |
377 | 'poste': 'postes', | |
378 | 'remplacement_de': 'dossiers', | |
6bee05ff | 379 | }, superclass=DossierForm) |
53ae644d OL |
380 | |
381 | def lookup_allowed(self, key, value): | |
382 | if key in ( | |
383 | 'employe__nom__istartswith', | |
53ae644d OL |
384 | 'poste__implantation__region__id__exact', |
385 | 'poste__implantation__id__exact', | |
386 | 'poste__type_poste__id__exact', | |
7bf28694 | 387 | 'poste__type_poste__categorie_emploi__id__exact', |
53ae644d | 388 | 'rh_contrats__type_contrat__id__exact', |
6bee05ff OL |
389 | 'principal__exact', |
390 | 'principal__isnull', | |
53ae644d OL |
391 | ): |
392 | return True | |
393 | ||
e49ac947 JPC |
394 | def _id(self, obj): |
395 | return obj.id | |
396 | _id.short_description = u"#" | |
397 | _id.admin_order_field = "id" | |
398 | ||
e49ac947 | 399 | def _apercu(self, d): |
22343fe7 OL |
400 | apercu_link = u"""<a title="Aperçu du dossier" |
401 | onclick="return showAddAnotherPopup(this);" | |
402 | href='%s'> | |
9533bd15 | 403 | <img src="%simg/dossier-apercu.png" /> |
22343fe7 | 404 | </a>""" % \ |
b10920ea | 405 | (reverse('dossier_apercu', args=(d.id,)), |
822a2c33 | 406 | settings.STATIC_URL, |
b10920ea | 407 | ) |
e49ac947 JPC |
408 | return apercu_link |
409 | _apercu.allow_tags = True | |
410 | _apercu.short_description = u"" | |
53ae644d | 411 | |
5db1c5a3 DB |
412 | def _nom(self, obj): |
413 | return "Dossier" | |
414 | _nom.allow_tags = True | |
415 | _nom.short_description = u"Dossier" | |
53ae644d | 416 | |
5db1c5a3 DB |
417 | def _employe(self, obj): |
418 | employe = obj.employe | |
419 | view_link = reverse('employe_apercu', args=(employe.id,)) | |
420 | edit_link = reverse('admin:rh_employe_change', args=(employe.id,)) | |
53ae644d | 421 | |
5db1c5a3 DB |
422 | style = "" |
423 | view = u"""<a href="%s" | |
424 | title="Aperçu l'employé" | |
425 | onclick="return showAddAnotherPopup(this);"> | |
426 | <img src="%simg/employe-apercu.png" /> | |
427 | </a>""" % (view_link, settings.STATIC_URL,) | |
428 | return u"""%s<a href='%s' style="%s;">%s</a>""" % \ | |
429 | (view, edit_link, style, employe) | |
430 | _employe.allow_tags = True | |
431 | _employe.short_description = u"Employé" | |
432 | _employe.admin_order_field = "employe__nom" | |
33232787 | 433 | |
53ae644d | 434 | def _poste(self, dossier): |
22343fe7 OL |
435 | link = u"""<a title="Aperçu du poste" |
436 | onclick="return showAddAnotherPopup(this);" | |
9533bd15 | 437 | href='%s'><img src="%simg/poste-apercu.png" /> |
22343fe7 | 438 | </a> |
5db1c5a3 | 439 | <a href="%s" title="Modifier le poste">%s [%d]</a>""" % \ |
53ae644d | 440 | (reverse('poste_apercu', args=(dossier.poste.id,)), |
822a2c33 | 441 | settings.STATIC_URL, |
211a0e56 | 442 | reverse('admin:rh_poste_change', args=(dossier.poste.id,)), |
5db1c5a3 DB |
443 | dossier.poste.nom, |
444 | dossier.poste.id, | |
53ae644d OL |
445 | ) |
446 | return link | |
447 | _poste.allow_tags = True | |
448 | _poste.short_description = u'Poste' | |
449 | _poste.admin_order_field = 'poste__nom' | |
450 | ||
5db1c5a3 DB |
451 | def _region(self, obj): |
452 | return obj.poste.implantation.region.code | |
453 | _region.short_description = u"Région" | |
454 | _region.admin_order_field = 'poste__implantation__region__code' | |
53ae644d | 455 | |
5db1c5a3 DB |
456 | def _implantation(self, obj): |
457 | return obj.poste.implantation.nom | |
458 | _implantation.short_description = u"Implantation" | |
459 | _implantation.admin_order_field = 'poste__implantation__nom' | |
460 | ||
461 | def _date_debut(self, obj): | |
462 | return date(obj.date_debut) | |
463 | ||
464 | _date_debut.short_description = u'Début' | |
465 | _date_debut.admin_order_field = 'date_debut' | |
466 | ||
467 | def _date_fin(self, obj): | |
468 | return date(obj.date_fin) | |
469 | _date_fin.short_description = u'Fin' | |
470 | _date_fin.admin_order_field = 'date_fin' | |
471 | ||
472 | def _date_modification(self, obj): | |
473 | return date(obj.date_modification) \ | |
474 | if obj.date_modification is not None else "(aucune)" | |
475 | _date_modification.short_description = u'date modification' | |
476 | _date_modification.admin_order_field = 'date_modification' | |
477 | ||
478 | def _dae(self, d): | |
479 | apercu_link = "" | |
480 | dossiers_dae = d.dossiers_dae.all() | |
481 | if len(dossiers_dae) > 0: | |
482 | dossier_dae = dossiers_dae[0] | |
483 | apercu_link = u"""<a title="Aperçu du dossier" | |
484 | onclick="return showAddAnotherPopup(this);" | |
485 | href='%s'> | |
486 | <img src="%simg/loupe.png" /> | |
487 | </a>""" % \ | |
488 | (reverse('embauche_consulter', args=(dossier_dae.id,)), | |
489 | settings.STATIC_URL, | |
490 | ) | |
491 | return apercu_link | |
492 | _dae.allow_tags = True | |
493 | _dae.short_description = u"DAE" | |
22343fe7 | 494 | |
53ae644d OL |
495 | def save_formset(self, request, form, formset, change): |
496 | instances = formset.save(commit=False) | |
497 | for instance in instances: | |
498 | if instance.__class__ == rh.DossierCommentaire: | |
499 | instance.owner = request.user | |
02e69aa2 | 500 | instance.date_creation = datetime.datetime.now() |
53ae644d OL |
501 | instance.save() |
502 | ||
503 | ||
08a9b6fc EMS |
504 | class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin, |
505 | ProtectRegionMixin, BaseAdmin): | |
7eb6b687 | 506 | prefixe_recherche_temporelle = "rh_dossiers__" |
53ae644d OL |
507 | alphabet_filter = 'nom' |
508 | DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
e23da9c3 EMS |
509 | search_fields = ( |
510 | 'id', 'nom', 'prenom', 'nom_affichage', | |
511 | 'rh_dossiers__poste__nom', | |
512 | 'rh_dossiers__poste__nom_feminin' | |
513 | ) | |
53ae644d OL |
514 | ordering = ('nom', ) |
515 | form = EmployeAdminForm | |
22343fe7 OL |
516 | list_display = ( |
517 | '_id', | |
518 | '_apercu', | |
519 | '_nom', | |
520 | '_dossiers_postes', | |
5db1c5a3 DB |
521 | '_region', |
522 | '_implantation', | |
5aface22 | 523 | 'date_entree', |
22343fe7 | 524 | '_date_modification', |
22343fe7 | 525 | ) |
e49ac947 | 526 | list_display_links = ('_nom',) |
22343fe7 OL |
527 | list_filter = ( |
528 | 'rh_dossiers__poste__implantation__region', | |
529 | 'rh_dossiers__poste__implantation', | |
530 | 'nb_postes', | |
531 | ) | |
53ae644d OL |
532 | inlines = (AyantDroitInline, |
533 | DossierROInline, | |
534 | EmployePieceInline, | |
535 | EmployeCommentaireInline) | |
536 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
537 | ('Identification', { | |
22343fe7 OL |
538 | 'fields': ( |
539 | ('nom', 'prenom'), | |
540 | ('nom_affichage', 'genre'), | |
541 | 'nationalite', | |
542 | 'date_naissance', | |
543 | )} | |
544 | ), | |
53ae644d | 545 | ('Informations personnelles', { |
22343fe7 OL |
546 | 'fields': ('situation_famille', 'date_entree', )} |
547 | ), | |
89a8df07 | 548 | ('Coordonnées personnelles', { |
22343fe7 OL |
549 | 'fields': ( |
550 | ('tel_domicile', 'tel_cellulaire'), | |
551 | ('adresse', 'ville'), | |
552 | ('code_postal', 'province'), | |
553 | 'pays', | |
89a8df07 | 554 | 'courriel_perso' |
22343fe7 OL |
555 | )} |
556 | ), | |
53ae644d OL |
557 | ) |
558 | ||
5db1c5a3 DB |
559 | def _id(self, obj): |
560 | return obj.id | |
561 | _id.short_description = u"#" | |
562 | _id.admin_order_field = "id" | |
563 | ||
b10920ea | 564 | def _apercu(self, obj): |
22343fe7 OL |
565 | return u"""<a title="Aperçu de l'employé" |
566 | onclick="return showAddAnotherPopup(this);" | |
567 | href='%s'> | |
9533bd15 | 568 | <img src="%simg/employe-apercu.png" /> |
22343fe7 OL |
569 | </a>""" % \ |
570 | (reverse('employe_apercu', args=(obj.id,)), settings.STATIC_URL) | |
b10920ea JPC |
571 | _apercu.allow_tags = True |
572 | _apercu.short_description = u"" | |
b10920ea | 573 | |
53ae644d | 574 | def _nom(self, obj): |
53ae644d | 575 | edit_link = reverse('admin:rh_employe_change', args=(obj.id,)) |
e6c107de | 576 | return u"""<a href='%s'><strong>%s</strong></a>""" % \ |
e49ac947 | 577 | (edit_link, "%s %s" % (obj.nom.upper(), obj.prenom)) |
53ae644d | 578 | _nom.allow_tags = True |
e49ac947 | 579 | _nom.short_description = u"Employé" |
53ae644d OL |
580 | _nom.admin_order_field = "nom" |
581 | ||
5db1c5a3 DB |
582 | def _region(self, obj): |
583 | try: | |
584 | d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0] | |
585 | region = d.poste.implantation.region.code | |
586 | except: | |
587 | region = None | |
588 | return region | |
589 | _region.short_description = u"Région" | |
e49ac947 | 590 | |
5db1c5a3 DB |
591 | def _implantation(self, obj): |
592 | try: | |
593 | d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0] | |
594 | implantation = d.poste.implantation.nom | |
595 | except: | |
596 | implantation = None | |
597 | return implantation | |
598 | _implantation.short_description = u"Implantation" | |
33232787 | 599 | |
a7f013f5 | 600 | def _dossiers_postes(self, obj): |
53ae644d OL |
601 | l = [] |
602 | for d in obj.rh_dossiers.all().order_by('-date_debut'): | |
5db1c5a3 DB |
603 | link_style = u'' |
604 | list_style = u'' | |
605 | if d.date_fin is not None and d.date_fin < datetime.date.today(): | |
5db1c5a3 DB |
606 | link_style = u' style="color:#666;"' |
607 | list_style = u' style="color:grey;"' | |
08ecf07e | 608 | |
22343fe7 OL |
609 | dossier = u"""<a title="Aperçu du dossier" |
610 | href="%s" | |
611 | onclick="return showAddAnotherPopup(this);" | |
612 | title="Aperçu du dossier"> | |
9533bd15 | 613 | <img src="%simg/dossier-apercu.png" /> |
22343fe7 | 614 | </a> |
5db1c5a3 | 615 | <a href="%s"%s>Dossier</a> |
22343fe7 OL |
616 | """ % \ |
617 | (reverse('dossier_apercu', args=(d.id,)), | |
618 | settings.STATIC_URL, | |
5db1c5a3 DB |
619 | reverse('admin:rh_dossier_change', args=(d.id,)), |
620 | link_style,) | |
22343fe7 OL |
621 | |
622 | poste = u"""<a title="Aperçu du poste" | |
623 | href="%s" | |
624 | onclick="return showAddAnotherPopup(this);" | |
625 | title="Aperçu du poste"> | |
9533bd15 | 626 | <img src="%simg/poste-apercu.png" /> |
22343fe7 | 627 | </a> |
5db1c5a3 | 628 | <a href="%s"%s>%s [%d]</a> |
22343fe7 OL |
629 | """ % \ |
630 | (reverse('poste_apercu', args=(d.poste.id,)), | |
631 | settings.STATIC_URL, | |
5db1c5a3 DB |
632 | reverse('admin:rh_poste_change', args=(d.poste.id,)), |
633 | link_style, | |
a7f013f5 | 634 | d.poste.nom, |
5db1c5a3 | 635 | d.poste.id) |
08ecf07e | 636 | |
5db1c5a3 DB |
637 | link = u"""<li%s>%s %s</li>""" % \ |
638 | (list_style, dossier, poste) | |
b5cc0357 | 639 | |
53ae644d OL |
640 | l.append(link) |
641 | return "<ul>%s</ul>" % "\n".join(l) | |
a7f013f5 JPC |
642 | _dossiers_postes.allow_tags = True |
643 | _dossiers_postes.short_description = u"Dossiers et postes" | |
53ae644d | 644 | |
5db1c5a3 DB |
645 | def _date_modification(self, obj): |
646 | return date(obj.date_modification) \ | |
647 | if obj.date_modification is not None else "(aucune)" | |
648 | _date_modification.short_description = u'date modification' | |
649 | _date_modification.admin_order_field = 'date_modification' | |
650 | ||
53ae644d | 651 | def queryset(self, request): |
22343fe7 | 652 | qs = super(EmployeAdmin, self).queryset(request) |
53ae644d OL |
653 | return qs.select_related(depth=1).order_by('nom') |
654 | ||
655 | def save_formset(self, request, form, formset, change): | |
656 | instances = formset.save(commit=False) | |
657 | for instance in instances: | |
658 | if instance.__class__ == rh.EmployeCommentaire: | |
659 | instance.owner = request.user | |
02e69aa2 | 660 | instance.date_creation = datetime.datetime.now() |
53ae644d OL |
661 | instance.save() |
662 | ||
22343fe7 | 663 | |
08faf06e | 664 | class EmployeProxyAdmin(EmployeAdmin): |
22343fe7 | 665 | list_display = ('_id', '_apercu', '_nom', '_organigramme') |
664bdc2f | 666 | list_per_page = 500 |
bd917a45 JPC |
667 | actions = None |
668 | ||
669 | def __init__(self, *args, **kwargs): | |
670 | super(EmployeProxyAdmin, self).__init__(*args, **kwargs) | |
671 | self.list_display_links = (None, ) | |
08faf06e | 672 | |
22343fe7 OL |
673 | def has_add_permission(self, obj): |
674 | return False | |
675 | ||
08faf06e JPC |
676 | def _organigramme(self, obj): |
677 | l = [] | |
fc4bf968 EMS |
678 | for d in rh.Dossier.objects.filter( |
679 | Q(date_fin__gt=datetime.date.today()) | Q(date_fin=None), | |
680 | Q(date_debut__lt=datetime.date.today()) | Q(date_debut=None), | |
681 | employe=obj.id | |
682 | ): | |
683 | organigramme = \ | |
684 | u'Organigramme, niveau: ' \ | |
685 | u'<input type="text" id="level_%s" ' \ | |
686 | u'style="width:30px;height:15px;" /> ' \ | |
687 | u'<input type="button" value="Générer" ' \ | |
688 | u"""onclick="window.location='%s' + """ \ | |
689 | u"""document.getElementById('level_%s').value" />""" % ( | |
690 | d.poste.id, | |
691 | reverse('rho_employe_sans_niveau', args=(d.poste.id,)), | |
692 | d.poste.id | |
693 | ) | |
e4fa851f | 694 | link = u"""<li>%s [%s]:<br />%s</li>""" % ( |
fc4bf968 | 695 | d.poste.nom, |
e4fa851f | 696 | d.poste.id, |
fc4bf968 EMS |
697 | organigramme |
698 | ) | |
08faf06e JPC |
699 | l.append(link) |
700 | return "<ul>%s</ul>" % "\n".join(l) | |
701 | ||
702 | _organigramme.allow_tags = True | |
703 | _organigramme.short_description = "Organigramme" | |
704 | ||
53ae644d | 705 | |
08a9b6fc | 706 | class CategorieEmploiAdmin(AUFMetadataAdminMixin, BaseAdmin): |
33232787 | 707 | list_display = ('nom', '_date_modification', 'user_modification', ) |
53ae644d | 708 | inlines = (TypePosteInline,) |
22343fe7 OL |
709 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
710 | (None, {'fields': ('nom', )}),) | |
53ae644d | 711 | |
33232787 | 712 | def _date_modification(self, obj): |
22343fe7 OL |
713 | return date(obj.date_modification) \ |
714 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
715 | _date_modification.short_description = u'date modification' |
716 | _date_modification.admin_order_field = 'date_modification' | |
53ae644d | 717 | |
22343fe7 | 718 | |
08a9b6fc | 719 | class OrganismeBstgAdmin(AUFMetadataAdminMixin, BaseAdmin): |
c5964dc2 | 720 | search_fields = ('nom',) |
22343fe7 OL |
721 | list_display = ( |
722 | 'nom', | |
723 | 'type', | |
724 | 'pays', | |
725 | '_date_modification', | |
726 | 'user_modification', | |
727 | ) | |
c5964dc2 | 728 | list_filter = ('type', ) |
53ae644d | 729 | inlines = (DossierROInline,) |
22343fe7 OL |
730 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
731 | (None, {'fields': ('nom', 'type', 'pays',)}), | |
53ae644d OL |
732 | ) |
733 | ||
33232787 | 734 | def _date_modification(self, obj): |
22343fe7 OL |
735 | return date(obj.date_modification) \ |
736 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
737 | _date_modification.short_description = u'date modification' |
738 | _date_modification.admin_order_field = 'date_modification' | |
739 | ||
53ae644d | 740 | |
08a9b6fc EMS |
741 | class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin, |
742 | ProtectRegionMixin, BaseAdmin, AjaxSelect): | |
22343fe7 OL |
743 | form = make_ajax_form(rh.Poste, { |
744 | 'implantation': 'implantations', | |
745 | 'type_poste': 'typepostes', | |
746 | 'responsable': 'postes', | |
747 | 'valeur_point_min': 'valeurpoints', | |
748 | 'valeur_point_max': 'valeurpoints', | |
53ae644d OL |
749 | }) |
750 | alphabet_filter = 'nom' | |
22343fe7 | 751 | search_fields = ( |
397bf8dd | 752 | 'id', |
22343fe7 | 753 | 'nom', |
22343fe7 OL |
754 | 'implantation__nom', |
755 | 'implantation__region__code', | |
756 | 'implantation__region__nom', | |
19a32e71 | 757 | 'rh_dossiers__employe__id', |
22343fe7 OL |
758 | 'rh_dossiers__employe__nom', |
759 | 'rh_dossiers__employe__prenom', | |
760 | ) | |
53ae644d | 761 | list_display = ( |
e49ac947 | 762 | '_id', |
8f3ca727 | 763 | '_apercu', |
22343fe7 | 764 | '_nom', |
53ae644d | 765 | '_occupe_par', |
5db1c5a3 | 766 | '_region', |
f3e3ac6f | 767 | '_implantation', |
22343fe7 | 768 | '_service', |
1ce2ddb9 | 769 | '_responsable', |
5db1c5a3 DB |
770 | '_date_debut', |
771 | '_date_fin', | |
33232787 | 772 | '_date_modification', |
a47ed016 | 773 | '_dae', |
53ae644d | 774 | ) |
f614ca5c | 775 | list_filter = ( |
22343fe7 | 776 | 'implantation__region', |
53ae644d | 777 | 'implantation', |
22343fe7 | 778 | 'service', |
53ae644d | 779 | 'type_poste', |
7bf28694 | 780 | 'type_poste__categorie_emploi', |
118efe7a | 781 | 'type_poste__famille_professionnelle', |
4c53dda4 | 782 | 'vacant', |
53ae644d | 783 | ) |
e49ac947 | 784 | list_display_links = ('_nom',) |
53ae644d | 785 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
22343fe7 OL |
786 | (None, {'fields': ( |
787 | ('nom', 'nom_feminin'), | |
788 | 'implantation', | |
789 | 'type_poste', | |
790 | 'service', | |
791 | 'responsable', | |
792 | )} | |
793 | ), | |
53ae644d | 794 | ('Contrat', { |
22343fe7 OL |
795 | 'fields': (( |
796 | 'regime_travail', | |
797 | 'regime_travail_nb_heure_semaine'), | |
798 | )} | |
799 | ), | |
53ae644d | 800 | ('Recrutement', { |
22343fe7 OL |
801 | 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)} |
802 | ), | |
53ae644d | 803 | ('Rémunération', { |
22343fe7 OL |
804 | 'fields': (('classement_min', |
805 | 'valeur_point_min', | |
806 | 'devise_min', | |
807 | 'salaire_min', | |
808 | 'indemn_min', | |
809 | 'autre_min',), | |
810 | ('classement_max', | |
811 | 'valeur_point_max', | |
812 | 'devise_max', | |
813 | 'salaire_max', | |
814 | 'indemn_max', | |
815 | 'autre_max',), | |
816 | )}), | |
53ae644d OL |
817 | ('Comparatifs de rémunération', { |
818 | 'fields': ('devise_comparaison', | |
819 | ('comp_locale_min', 'comp_locale_max'), | |
820 | ('comp_universite_min', 'comp_universite_max'), | |
821 | ('comp_fonctionpub_min', 'comp_fonctionpub_max'), | |
822 | ('comp_ong_min', 'comp_ong_max'), | |
22343fe7 OL |
823 | ('comp_autre_min', 'comp_autre_max'))} |
824 | ), | |
53ae644d | 825 | ('Justification', { |
22343fe7 OL |
826 | 'fields': ('justification',)} |
827 | ), | |
48a6df80 | 828 | ('Autres Méta-données', { |
22343fe7 OL |
829 | 'fields': ('date_debut', 'date_fin')} |
830 | ), | |
53ae644d OL |
831 | ) |
832 | ||
833 | inlines = (PosteFinancementInline, | |
834 | PostePieceInline, | |
835 | DossierROInline, | |
6f037929 | 836 | PosteComparaisonInline, |
53ae644d OL |
837 | PosteCommentaireInline, ) |
838 | ||
f614ca5c | 839 | def lookup_allowed(self, key, value): |
118efe7a EMS |
840 | return key in ( |
841 | 'date_debut__gte', 'date_debut__isnull', 'date_fin__lte', | |
842 | 'date_fin__isnull', 'implantation__region__id__exact', | |
843 | 'implantation__id__exact', 'type_poste__id__exact', | |
844 | 'type_poste__categorie_emploi__id__exact', 'service__id__exact', | |
845 | 'service__isnull', 'vacant__exact', 'vacant__isnull', | |
846 | ) or super(PosteAdmin, self).lookup_allowed(key, value) | |
f614ca5c | 847 | |
5db1c5a3 DB |
848 | def _id(self, obj): |
849 | return "%s" % obj.id | |
850 | _id.short_description = '#' | |
851 | _id.admin_order_field = 'id' | |
852 | ||
8f3ca727 | 853 | def _apercu(self, poste): |
22343fe7 OL |
854 | view_link = u"""<a onclick="return showAddAnotherPopup(this);" |
855 | title="Aperçu du poste" | |
856 | href='%s'> | |
9533bd15 | 857 | <img src="%simg/poste-apercu.png" /> |
22343fe7 | 858 | </a>""" % \ |
8f3ca727 | 859 | (reverse('poste_apercu', args=(poste.id,)), |
22343fe7 OL |
860 | settings.STATIC_URL,) |
861 | return view_link | |
8f3ca727 | 862 | _apercu.allow_tags = True |
e49ac947 JPC |
863 | _apercu.short_description = '' |
864 | ||
5db1c5a3 DB |
865 | def _nom(self, poste): |
866 | return """<a href="%s">%s</a>""" % \ | |
867 | (reverse('admin:rh_poste_change', args=(poste.id,)), | |
868 | poste.nom) | |
869 | _nom.allow_tags = True | |
870 | _nom.short_description = u'Poste' | |
871 | _nom.admin_order_field = 'nom' | |
a47ed016 | 872 | |
5db1c5a3 DB |
873 | def _occupe_par(self, obj): |
874 | """Formatte la méthode Poste.occupe_par() pour l'admin""" | |
875 | output = u"Vacant" | |
876 | if obj.date_fin is not None and obj.date_fin < datetime.date.today(): | |
877 | return u"s/o" | |
878 | employes = obj.occupe_par() | |
879 | if employes: | |
880 | l = [] | |
881 | for e in employes: | |
882 | link = u"""<a href='%s' | |
883 | title='Aperçu de l\'employé' | |
884 | onclick='return showAddAnotherPopup(this)'> | |
885 | <img src='%simg/employe-apercu.png' /> | |
886 | </a> | |
887 | <a href='%s'>%s</a>""" % \ | |
888 | (reverse('employe_apercu', args=(e.id,)), | |
889 | settings.STATIC_URL, | |
890 | reverse('admin:rh_employe_change', args=(e.id,)), | |
891 | e) | |
892 | l.append(link) | |
893 | output = "\n<br />".join(l) | |
894 | return output | |
895 | _occupe_par.allow_tags = True | |
896 | _occupe_par.short_description = "Occupé par" | |
897 | ||
898 | def _region(self, poste): | |
899 | return poste.implantation.region.code | |
900 | _region.short_description = 'Région' | |
901 | _region.admin_order_field = 'implantation__region__code' | |
902 | ||
903 | def _implantation(self, poste): | |
904 | return poste.implantation.nom | |
905 | _implantation.short_description = 'Implantation' | |
906 | _implantation.admin_order_field = 'implantation' | |
8f3ca727 | 907 | |
c5964dc2 | 908 | def _service(self, obj): |
1b130b25 JPC |
909 | if obj.service.supprime: |
910 | return """<span style="color:red">%s</span>""" % obj.service | |
911 | else: | |
912 | return obj.service | |
6c2b1160 | 913 | _service.short_description = 'Service' |
1b130b25 | 914 | _service.allow_tags = True |
53ae644d | 915 | |
1ce2ddb9 JPC |
916 | def _responsable(self, obj): |
917 | try: | |
22343fe7 OL |
918 | responsable = u"""<a href="%s" |
919 | onclick="return showAddAnotherPopup(this)"> | |
9533bd15 | 920 | <img src="%simg/poste-apercu.png" |
22343fe7 OL |
921 | title="Aperçu du poste" /> |
922 | </a> | |
5db1c5a3 | 923 | <a href="%s">%s [%d]</a> |
22343fe7 OL |
924 | <br />""" % \ |
925 | (reverse('poste_apercu', args=(obj.responsable.id,)), | |
926 | settings.STATIC_URL, | |
927 | reverse('admin:rh_poste_change', args=(obj.responsable.id,)), | |
5db1c5a3 DB |
928 | obj.responsable.nom, |
929 | obj.responsable.id) | |
1ce2ddb9 JPC |
930 | except: |
931 | responsable = '' | |
932 | ||
933 | try: | |
08ecf07e EMS |
934 | dossier = obj.responsable.rh_dossiers.all() \ |
935 | .order_by('-date_debut')[0] | |
60f34330 | 936 | employe_id = dossier.employe.id |
fc4bf968 | 937 | employe_html = u"""<br /> |
22343fe7 OL |
938 | <a href="%s" |
939 | onclick="return showAddAnotherPopup(this)"> | |
9533bd15 | 940 | <img src="%simg/employe-apercu.png" |
22343fe7 OL |
941 | title="Aperçu de l'employé"> |
942 | </a> | |
943 | <a href="%s">%s</a>""" % \ | |
944 | (reverse('employe_apercu', args=(employe_id,)), | |
945 | settings.STATIC_URL, | |
946 | reverse('admin:rh_employe_change', args=(employe_id,)), | |
60f34330 | 947 | dossier.employe) |
1ce2ddb9 | 948 | except: |
fc4bf968 | 949 | employe_html = "" |
1ce2ddb9 | 950 | |
fc4bf968 | 951 | return "%s %s" % (responsable, employe_html) |
1ce2ddb9 JPC |
952 | _responsable.short_description = 'Responsable' |
953 | _responsable.allow_tags = True | |
954 | ||
5db1c5a3 DB |
955 | def _date_debut(self, obj): |
956 | return date_format(obj.date_debut) | |
957 | _date_debut.short_description = u'Début' | |
958 | _date_debut.admin_order_field = 'date_debut' | |
f3e3ac6f | 959 | |
5db1c5a3 DB |
960 | def _date_fin(self, obj): |
961 | return date_format(obj.date_fin) | |
962 | _date_fin.short_description = u'Fin' | |
963 | _date_fin.admin_order_field = 'date_fin' | |
53ae644d | 964 | |
33232787 JPC |
965 | def _date_modification(self, obj): |
966 | return date(obj.date_modification) | |
967 | _date_modification.short_description = u'date modification' | |
968 | _date_modification.admin_order_field = 'date_modification' | |
969 | ||
5db1c5a3 DB |
970 | def _dae(self, poste): |
971 | apercu_link = "" | |
972 | postes_dae = poste.postes_dae.all() | |
973 | if len(postes_dae) > 0: | |
974 | poste_dae = postes_dae[0] | |
975 | apercu_link = \ | |
976 | u'<a title="Aperçu du dossier" href="%s" ' \ | |
977 | u'onclick="return showAddAnotherPopup(this);">' \ | |
978 | u'<img src="%simg/loupe.png" /></a>' % (reverse( | |
979 | 'poste_consulter', args=("dae-%s" % poste_dae.id,) | |
980 | ), settings.STATIC_URL) | |
981 | return apercu_link | |
982 | _dae.allow_tags = True | |
983 | _dae.short_description = u"DAE" | |
53ae644d OL |
984 | |
985 | def save_formset(self, request, form, formset, change): | |
986 | instances = formset.save(commit=False) | |
987 | for instance in instances: | |
988 | if instance.__class__ == rh.PosteCommentaire: | |
989 | instance.owner = request.user | |
02e69aa2 | 990 | instance.date_creation = datetime.datetime.now() |
53ae644d OL |
991 | instance.save() |
992 | formset.save_m2m() | |
993 | ||
994 | ||
8c8ffc4f OL |
995 | class ResponsableInline(admin.TabularInline): |
996 | model = rh.ResponsableImplantation | |
997 | extra = 0 | |
fc4bf968 | 998 | fk_name = "implantation" |
6fb68b2f | 999 | form = ResponsableInlineForm |
fc4bf968 | 1000 | |
22343fe7 | 1001 | |
08a9b6fc | 1002 | class ResponsableImplantationAdmin(BaseAdmin): |
8c8ffc4f | 1003 | actions = None |
6fb68b2f DB |
1004 | fields = ('nom', ) |
1005 | inlines = (ResponsableInline, ) | |
8c8ffc4f | 1006 | list_filter = ('region', 'statut', ) |
30dabdc3 | 1007 | list_display = ('_region', '_nom', 'statut', '_responsable', ) |
6fb68b2f | 1008 | list_display_links = ('_nom',) |
664bdc2f | 1009 | list_per_page = 500 |
8c8ffc4f | 1010 | readonly_fields = ('nom', ) |
6fb68b2f DB |
1011 | search_fields = ( |
1012 | 'nom', | |
1013 | 'responsable__employe__id', | |
1014 | 'responsable__employe__nom', | |
1015 | 'responsable__employe__prenom', | |
1016 | ) | |
1017 | ordering = ('nom',) | |
08ecf07e | 1018 | |
30dabdc3 DB |
1019 | def _region(self, obj): |
1020 | return obj.region.code | |
1021 | _region.short_description = u"Région" | |
1022 | _region.admin_order_field = 'region__code' | |
08ecf07e | 1023 | |
30dabdc3 DB |
1024 | def _nom(self, obj): |
1025 | return obj.nom | |
1026 | _nom.short_description = u"Implantation" | |
1027 | _nom.admin_order_field = 'nom' | |
08ecf07e | 1028 | |
8c8ffc4f OL |
1029 | def _responsable(self, obj): |
1030 | try: | |
1031 | employe = obj.responsable.employe | |
1032 | dossiers = employe.dossiers_encours() | |
1033 | if len(dossiers) == 0: | |
1034 | return u"<span style='color: red;'>%s %s </span>" % ( | |
1035 | employe, u"sans dossier actif") | |
1036 | else: | |
1037 | return employe | |
fc4bf968 EMS |
1038 | except Exception: |
1039 | if obj.statut in (1, 2): # ouverte, ouverture imminente | |
8c8ffc4f OL |
1040 | css = "style='color: red;'" |
1041 | else: | |
1042 | css = "" | |
1043 | return u"<span %s>Pas de responsable</span>" % css | |
1044 | _responsable.allow_tags = True | |
1045 | _responsable.short_description = u"Responsable" | |
6fb68b2f | 1046 | _responsable.admin_order_field = 'responsable__employe__nom' |
8c8ffc4f OL |
1047 | |
1048 | def has_add_permission(self, request=None): | |
1049 | return False | |
1050 | ||
1051 | def has_change_permission(self, request, obj=None): | |
1052 | return in_drh_or_admin(request.user) | |
1053 | ||
1054 | def has_delete_permission(self, request, obj=None): | |
1055 | return False | |
53ae644d | 1056 | |
fc4bf968 | 1057 | |
08a9b6fc | 1058 | class ServiceAdmin(AUFMetadataAdminMixin, BaseAdmin, ArchiveMixin): |
22343fe7 OL |
1059 | list_display = ( |
1060 | 'nom', | |
1061 | '_archive', | |
1062 | '_date_modification', | |
1063 | 'user_modification', | |
1064 | ) | |
cbb0373e | 1065 | list_filter = ('archive', ) |
22343fe7 | 1066 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
53ae644d | 1067 | (None, { |
cbb0373e | 1068 | 'fields': ('nom', 'archive', ), |
53ae644d OL |
1069 | }), |
1070 | ) | |
1071 | ||
33232787 | 1072 | def _date_modification(self, obj): |
22343fe7 OL |
1073 | return date(obj.date_modification) \ |
1074 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1075 | _date_modification.short_description = u'date modification' |
1076 | _date_modification.admin_order_field = 'date_modification' | |
1077 | ||
fc4bf968 | 1078 | |
5c0f1778 | 1079 | class ServiceProxyAdmin(ServiceAdmin): |
cfd5ac68 | 1080 | list_display = ('nom', '_organigramme', '_archive', ) |
8135fc65 JPC |
1081 | actions = None |
1082 | ||
1083 | def __init__(self, *args, **kwargs): | |
1084 | super(ServiceProxyAdmin, self).__init__(*args, **kwargs) | |
1085 | self.list_display_links = (None, ) | |
5c0f1778 | 1086 | |
f7badf51 EMS |
1087 | def queryset(self, request): |
1088 | return super(ServiceProxyAdmin, self).queryset(request) \ | |
1089 | .annotate(num_postes=Count('rh_postes')) \ | |
1090 | .filter(num_postes__gt=0) | |
1091 | ||
5c0f1778 JPC |
1092 | def has_add_permission(self, obj): |
1093 | return False | |
1094 | ||
aa2c508e JPC |
1095 | def has_change_permission(self, request, obj=None): |
1096 | return in_drh_or_admin(request.user) | |
1097 | ||
5c0f1778 | 1098 | def _organigramme(self, obj): |
8135fc65 JPC |
1099 | return """<a href="%s"><strong>Organigramme</strong></a>""" % \ |
1100 | (reverse('rho_service', args=(obj.id,))) | |
5c0f1778 JPC |
1101 | _organigramme.allow_tags = True |
1102 | _organigramme.short_description = "Organigramme" | |
1103 | ||
8135fc65 | 1104 | |
08a9b6fc | 1105 | class StatutAdmin(AUFMetadataAdminMixin, BaseAdmin): |
33232787 | 1106 | list_display = ('code', 'nom', '_date_modification', 'user_modification', ) |
22343fe7 | 1107 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
53ae644d OL |
1108 | (None, { |
1109 | 'fields': ('code', 'nom', ), | |
1110 | }), | |
1111 | ) | |
1112 | ||
33232787 | 1113 | def _date_modification(self, obj): |
22343fe7 OL |
1114 | return date(obj.date_modification) \ |
1115 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1116 | _date_modification.short_description = u'date modification' |
1117 | _date_modification.admin_order_field = 'date_modification' | |
1118 | ||
22343fe7 | 1119 | |
08a9b6fc | 1120 | class TauxChangeAdmin(BaseAdmin): |
22343fe7 OL |
1121 | list_display = ( |
1122 | 'taux', | |
1123 | 'devise', | |
1124 | 'annee', | |
1125 | '_date_modification', | |
1126 | 'user_modification', | |
1127 | ) | |
53ae644d | 1128 | list_filter = ('devise', ) |
22343fe7 | 1129 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
53ae644d OL |
1130 | (None, { |
1131 | 'fields': ('taux', 'devise', 'annee', ), | |
1132 | }), | |
1133 | ) | |
1134 | ||
33232787 | 1135 | def _date_modification(self, obj): |
22343fe7 OL |
1136 | return date(obj.date_modification) \ |
1137 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1138 | _date_modification.short_description = u'date modification' |
1139 | _date_modification.admin_order_field = 'date_modification' | |
1140 | ||
22343fe7 | 1141 | |
08a9b6fc | 1142 | class TypeContratAdmin(BaseAdmin): |
22343fe7 OL |
1143 | list_display = ( |
1144 | 'nom', | |
1145 | 'nom_long', | |
1146 | '_date_modification', | |
1147 | 'user_modification', | |
1148 | ) | |
1149 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
53ae644d OL |
1150 | (None, { |
1151 | 'fields': ('nom', 'nom_long', ), | |
1152 | }), | |
1153 | ) | |
1154 | ||
33232787 | 1155 | def _date_modification(self, obj): |
22343fe7 OL |
1156 | return date(obj.date_modification) \ |
1157 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1158 | _date_modification.short_description = u'date modification' |
1159 | _date_modification.admin_order_field = 'date_modification' | |
1160 | ||
53ae644d | 1161 | |
08a9b6fc | 1162 | class TypePosteAdmin(AUFMetadataAdminMixin, BaseAdmin): |
53ae644d | 1163 | search_fields = ('nom', 'nom_feminin', ) |
22343fe7 OL |
1164 | list_display = ( |
1165 | 'nom', | |
7bf28694 | 1166 | 'categorie_emploi', |
22343fe7 OL |
1167 | '_date_modification', |
1168 | 'user_modification', | |
1169 | ) | |
321fe481 | 1170 | list_filter = ('categorie_emploi', 'famille_professionnelle') |
22343fe7 | 1171 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
53ae644d | 1172 | (None, { |
22343fe7 OL |
1173 | 'fields': ( |
1174 | 'nom', | |
1175 | 'nom_feminin', | |
1176 | 'is_responsable', | |
7bf28694 | 1177 | 'categorie_emploi', |
321fe481 | 1178 | 'famille_professionnelle', |
22343fe7 OL |
1179 | )} |
1180 | ), | |
53ae644d OL |
1181 | ) |
1182 | ||
33232787 | 1183 | def _date_modification(self, obj): |
22343fe7 OL |
1184 | return date(obj.date_modification) \ |
1185 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1186 | _date_modification.short_description = u'date modification' |
1187 | _date_modification.admin_order_field = 'date_modification' | |
1188 | ||
53ae644d | 1189 | |
08a9b6fc | 1190 | class TypeRemunerationAdmin(AUFMetadataAdminMixin, BaseAdmin, |
fc4bf968 | 1191 | ArchiveMixin): |
22343fe7 OL |
1192 | list_display = ( |
1193 | 'nom', | |
1194 | 'type_paiement', | |
1195 | 'nature_remuneration', | |
7ba822a6 | 1196 | '_archive', |
22343fe7 OL |
1197 | '_date_modification', |
1198 | 'user_modification',) | |
7ba822a6 | 1199 | list_filter = ('archive', ) |
22343fe7 | 1200 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
7ba822a6 OL |
1201 | (None, {'fields': ('nom', 'type_paiement', 'nature_remuneration', |
1202 | 'archive')}), | |
53ae644d OL |
1203 | ) |
1204 | ||
33232787 | 1205 | def _date_modification(self, obj): |
22343fe7 OL |
1206 | return date(obj.date_modification) \ |
1207 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1208 | _date_modification.short_description = u'date modification' |
1209 | _date_modification.admin_order_field = 'date_modification' | |
1210 | ||
53ae644d | 1211 | |
08a9b6fc | 1212 | class TypeRevalorisationAdmin(AUFMetadataAdminMixin, BaseAdmin): |
33232787 | 1213 | list_display = ('nom', '_date_modification', 'user_modification', ) |
22343fe7 OL |
1214 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
1215 | (None, {'fields': ('nom', )}), | |
53ae644d OL |
1216 | ) |
1217 | ||
33232787 | 1218 | def _date_modification(self, obj): |
22343fe7 OL |
1219 | return date(obj.date_modification) \ |
1220 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1221 | _date_modification.short_description = u'date modification' |
1222 | _date_modification.admin_order_field = 'date_modification' | |
1223 | ||
53ae644d | 1224 | |
08a9b6fc | 1225 | class ValeurPointAdmin(AUFMetadataAdminMixin, BaseAdmin): |
22343fe7 OL |
1226 | list_display = ( |
1227 | '_devise_code', | |
1228 | '_devise_nom', | |
1229 | 'annee', | |
88202dc3 | 1230 | 'implantation', |
22343fe7 OL |
1231 | 'valeur', |
1232 | '_date_modification', | |
1233 | 'user_modification', | |
1234 | ) | |
88202dc3 | 1235 | list_filter = ('annee', 'devise', 'implantation__region', ) |
22343fe7 OL |
1236 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
1237 | (None, {'fields': ('valeur', 'devise', 'implantation', 'annee', )}), | |
53ae644d OL |
1238 | ) |
1239 | ||
33232787 | 1240 | def _date_modification(self, obj): |
22343fe7 OL |
1241 | return date(obj.date_modification) \ |
1242 | if obj.date_modification is not None else "(aucune)" | |
33232787 JPC |
1243 | _date_modification.short_description = u'date modification' |
1244 | _date_modification.admin_order_field = 'date_modification' | |
1245 | ||
53ae644d OL |
1246 | def _devise_code(self, obj): |
1247 | return obj.devise.code | |
1248 | _devise_code.short_description = "Code de la devise" | |
1249 | ||
1250 | def _devise_nom(self, obj): | |
1251 | return obj.devise.nom | |
1252 | _devise_nom.short_description = "Nom de la devise" | |
1253 | ||
fc4bf968 | 1254 | |
08a9b6fc | 1255 | class ImplantationProxyAdmin(BaseAdmin): |
82af5c19 | 1256 | list_display = ('nom', '_organigramme') |
8135fc65 JPC |
1257 | actions = None |
1258 | ||
1259 | def __init__(self, *args, **kwargs): | |
1260 | super(ImplantationProxyAdmin, self).__init__(*args, **kwargs) | |
1261 | self.list_display_links = (None, ) | |
82af5c19 JPC |
1262 | |
1263 | def has_add_permission(self, obj): | |
1264 | return False | |
1265 | ||
aa2c508e JPC |
1266 | def has_change_permission(self, request, obj=None): |
1267 | return in_drh_or_admin(request.user) | |
1268 | ||
82af5c19 | 1269 | def _organigramme(self, obj): |
fc4bf968 EMS |
1270 | return '<a href="%s"><strong>Organigramme</strong></a>' % ( |
1271 | reverse('rho_implantation', args=(obj.id,)) | |
1272 | ) | |
82af5c19 JPC |
1273 | _organigramme.allow_tags = True |
1274 | _organigramme.short_description = "Organigramme" | |
1275 | ||
fc4bf968 | 1276 | |
08a9b6fc | 1277 | class RegionProxyAdmin(BaseAdmin): |
9da4c195 | 1278 | list_display = ('nom', '_organigramme') |
8135fc65 JPC |
1279 | actions = None |
1280 | ||
1281 | def __init__(self, *args, **kwargs): | |
1282 | super(RegionProxyAdmin, self).__init__(*args, **kwargs) | |
1283 | self.list_display_links = (None, ) | |
9da4c195 JPC |
1284 | |
1285 | def has_add_permission(self, obj): | |
1286 | return False | |
1287 | ||
aa2c508e JPC |
1288 | def has_change_permission(self, request, obj=None): |
1289 | return in_drh_or_admin(request.user) | |
1290 | ||
9da4c195 | 1291 | def _organigramme(self, obj): |
fc4bf968 EMS |
1292 | return """<a href="%s"><strong>Organigramme</strong></a>""" % ( |
1293 | reverse('rho_region', args=(obj.id,)) | |
1294 | ) | |
9da4c195 JPC |
1295 | _organigramme.allow_tags = True |
1296 | _organigramme.short_description = "Organigramme" | |
1297 | ||
1298 | ||
53ae644d OL |
1299 | admin.site.register(rh.Classement, ClassementAdmin) |
1300 | admin.site.register(rh.Devise, DeviseAdmin) | |
1301 | admin.site.register(rh.Dossier, DossierAdmin) | |
22343fe7 | 1302 | admin.site.register(EmployeProxy, EmployeProxyAdmin) |
5c0f1778 | 1303 | admin.site.register(ServiceProxy, ServiceProxyAdmin) |
53ae644d | 1304 | admin.site.register(rh.Employe, EmployeAdmin) |
7bf28694 | 1305 | admin.site.register(rh.CategorieEmploi, CategorieEmploiAdmin) |
321fe481 | 1306 | admin.site.register(rh.FamilleProfessionnelle) |
53ae644d OL |
1307 | admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin) |
1308 | admin.site.register(rh.Poste, PosteAdmin) | |
fc4bf968 EMS |
1309 | admin.site.register( |
1310 | rh.ResponsableImplantationProxy, ResponsableImplantationAdmin | |
1311 | ) | |
53ae644d | 1312 | admin.site.register(rh.Service, ServiceAdmin) |
c5964dc2 | 1313 | admin.site.register(rh.Statut, StatutAdmin) |
53ae644d | 1314 | admin.site.register(rh.TauxChange, TauxChangeAdmin) |
c5964dc2 | 1315 | admin.site.register(rh.TypeContrat, TypeContratAdmin) |
53ae644d OL |
1316 | admin.site.register(rh.TypePoste, TypePosteAdmin) |
1317 | admin.site.register(rh.TypeRemuneration, TypeRemunerationAdmin) | |
1318 | admin.site.register(rh.TypeRevalorisation, TypeRevalorisationAdmin) | |
1319 | admin.site.register(rh.ValeurPoint, ValeurPointAdmin) | |
82af5c19 | 1320 | admin.site.register(ImplantationProxy, ImplantationProxyAdmin) |
9da4c195 | 1321 | admin.site.register(RegionProxy, RegionProxyAdmin) |