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