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