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