cache dans le tableau de bord des modeles peu utilisés
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
6e7c919b
NC
1# -*- encoding: utf-8 -*-
2
babf71ec 3from django.db import models
6e7c919b 4from django.contrib import admin
49449367 5from django.conf import settings
d6985a3a 6from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 7from project.rh import models as rh
6e7c919b 8
d6985a3a 9# Inlines
6e7c919b 10
d6985a3a
OL
11class ReadOnlyInlineMixin(object):
12 def get_readonly_fields(self, request, obj=None):
13 return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS]
6e7c919b
NC
14
15
51ab4c2c 16class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline):
babf71ec 17 model = models.Model # à remplacer dans admin.py
51ab4c2c 18 extra = 0
54d04eed 19
d6985a3a
OL
20
21class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 22 readonly_fields = ('owner', )
babf71ec 23 model = models.Model # à remplacer dans admin.py
cf786fb2 24 extra = 1
6e7c919b 25
54d04eed 26
d6985a3a 27class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 28 model = models.Model # à remplacer dans admin.py
1f2979b8 29 extra = 1
babf71ec
NC
30
31
d6985a3a
OL
32class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
33 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 34 model = models.Model # à remplacer dans admin.py
babf71ec 35
d6985a3a
OL
36
37class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 38 readonly_fields = ('owner', )
babf71ec 39 model = models.Model # à remplacer dans admin.py
1f2979b8 40 extra = 1
babf71ec 41
d6985a3a 42
babf71ec
NC
43class DossierPieceInline(admin.TabularInline):
44 model = models.Model # à remplacer dans admin.py
45
46
47class EmployeInline(admin.TabularInline):
48 model = models.Model # à remplacer dans admin.py
49
d6985a3a 50class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 51 readonly_fields = ('owner', )
babf71ec 52 model = models.Model # à remplacer dans admin.py
cf786fb2 53 extra = 1
babf71ec
NC
54
55
56class EmployePieceInline(admin.TabularInline):
57 model = models.Model # à remplacer dans admin.py
58
59
d6985a3a 60class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 61 model = models.Model # à remplacer dans admin.py
1f2979b8 62 extra = 1
babf71ec
NC
63
64
d6985a3a 65class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 66 model = models.Model # à remplacer dans admin.py
1f2979b8 67 extra = 1
babf71ec
NC
68
69
d6985a3a 70class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 71 readonly_fields = ('owner', )
babf71ec 72 model = models.Model # à remplacer dans admin.py
70561dc2 73 extra = 1
babf71ec
NC
74
75
76class PosteFinancementInline(admin.TabularInline):
77 model = models.Model # à remplacer dans admin.py
78
79
80class PostePieceInline(admin.TabularInline):
81 model = models.Model # à remplacer dans admin.py
82
83
d6985a3a 84class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 85 model = models.Model # à remplacer dans admin.py
1f2979b8 86 extra = 1
babf71ec
NC
87
88
d6985a3a 89class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
90 pass
91
54d04eed 92
26dacccc 93class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec
NC
94 model = models.Model # à remplacer dans admin.py
95
96
97# Admins
98
d6985a3a 99class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cf786fb2
OL
100 """
101 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
102 """
387ab827 103 alphabet_filter = 'nom'
cf786fb2 104 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
1a89b1f3 105 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
babf71ec 106 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
107 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
108 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
109 ("Lien avec l'employé", {
110 'fields': ('employe', 'lien_parente', )
111 }),
112
113 ('Identification', {
114 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
115 }),
116 )
117
118 def save_formset(self, request, form, formset, change):
119 instances = formset.save(commit=False)
120 for instance in instances:
121 if instance.__class__ == rh.AyantDroitCommentaire:
122 instance.owner = request.user
123 instance.save()
cf786fb2
OL
124
125 def _ayantdroit(self, obj):
126 return unicode(obj)
127 _ayantdroit.short_description = u'Ayant droit'
babf71ec 128
cf786fb2
OL
129 def _employe(self, obj):
130 return unicode(obj.employe)
131 _employe.short_description = u'Employé'
132
133 def has_add_permission(self, request):
134 return False
babf71ec
NC
135
136class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
137 pass
138
54d04eed 139
324bf312
OL
140class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
141 fieldsets = AUFMetadataAdminMixin.fieldsets + (
142 (None, {
143 'fields': ('type', 'echelon', 'degre', 'coefficient', )
144 }),
145 )
146
6e7c919b 147
6e7c919b
NC
148class CommentaireAdmin(admin.ModelAdmin):
149 pass
150
151
20468a70 152class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387ab827 153 alphabet_filter = 'dossier__employe__nom'
d8d7985b 154 search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', )
b35fe629 155 list_display = ('id', '_employe', '_poste', 'date_debut', 'date_fin', '_implantation', )
20468a70
OL
156 fieldsets = AUFMetadataAdminMixin.fieldsets + (
157 (None, {
158 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', )
159 }),
160 )
c41b7fcc 161
387ab827
OL
162 def lookup_allowed(self, key, value):
163 if key in ('dossier__employe__nom__istartswith', ):
164 return True
165
b35fe629
OL
166 def _employe(self, obj):
167 return unicode(obj.dossier.employe)
168 _employe.short_description = "Employé"
169
c41b7fcc 170 def _poste(self, obj):
b35fe629 171 return obj.dossier.poste.nom
c41b7fcc 172 _poste.short_description = "Poste"
6e7c919b 173
b35fe629
OL
174 def _implantation(self, obj):
175 return obj.dossier.poste.implantation
176 _poste.short_description = "Implantation"
54d04eed 177
84fc088b
OL
178class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
179 fieldsets = AUFMetadataAdminMixin.fieldsets + (
180 (None, {
181 'fields': ('code', 'nom', ),
182 }),
183 )
6e7c919b 184
54d04eed 185
d6985a3a 186class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
387ab827 187 alphabet_filter = 'employe__nom'
d8d7985b 188 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
49449367 189 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', '_actif')
1f2979b8 190 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
191 RemunerationInline,
192 #EvenementInline,
193 DossierCommentaireInline,
1f2979b8 194 )
d6985a3a 195 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
196 ('Identification', {
197 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
198 }),
199 ('Recrutement', {
200 'fields': ('remplacement', 'statut_residence', )
201 }),
202 ('Rémunération', {
203 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
204 }),
205 ('Occupation du Poste par cet Employe', {
206 'fields': ('date_debut', 'date_fin', )
207 }),
208 )
54d04eed 209
387ab827 210 def lookup_allowed(self, key, value):
49449367 211 if key in ('employe__nom__istartswith', 'actif__exact', ):
387ab827
OL
212 return True
213
49449367
OL
214 def _actif(self, dossier):
215 if dossier.employe.actif:
216 html = """<img alt="True" src="%simg/admin/icon-yes.gif">"""
217 else:
218 html = """<img alt="False" src="%simg/admin/icon-no.gif">"""
219 return html % settings.ADMIN_MEDIA_PREFIX
220 _actif.allow_tags = u'Employé actif'
221 _actif.short_description = u'Employé actif'
222 _actif.admin_order_field = 'employe__actif'
387ab827 223
54d04eed
NC
224 def _poste(self, dossier):
225 return unicode(dossier.poste.nom)
226 _poste.short_description = u'Poste'
d9836879 227 _poste.admin_order_field = 'poste__nom'
54d04eed
NC
228
229 def _employe(self, dossier):
230 return unicode(dossier.employe)
231 _employe.short_description = u'Employé'
d9836879
OL
232 _employe.admin_order_field = 'employe__nom'
233
1f2979b8
OL
234 def save_formset(self, request, form, formset, change):
235 instances = formset.save(commit=False)
236 for instance in instances:
237 if instance.__class__ == rh.DossierCommentaire:
238 instance.owner = request.user
239 instance.save()
6e7c919b
NC
240
241class DossierPieceAdmin(admin.ModelAdmin):
242 pass
243
54d04eed 244
6e7c919b
NC
245class DossierCommentaireAdmin(admin.ModelAdmin):
246 pass
247
54d04eed 248
d6985a3a 249class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
7ffc5aa4 250 alphabet_filter = 'nom'
49449367
OL
251 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', 'actif', )
252 list_filter = ('actif', )
253 ordering = ('nom', )
254 actions = ('desactiver', )
255 list_display = ('nom', 'prenom', 'actif', )
babf71ec
NC
256 inlines = (AyantDroitInline,
257 DossierROInline,
258 EmployePieceInline,
259 EmployeCommentaireInline)
d6985a3a 260 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
261 ('Identification', {
262 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
263 }),
264 ('Informations personnelles', {
265 'fields': ('situation_famille', 'date_entree', )
266 }),
267 ('Coordonnées', {
268 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
269 }),
270 )
babf71ec 271
cf786fb2
OL
272 def save_formset(self, request, form, formset, change):
273 instances = formset.save(commit=False)
274 for instance in instances:
275 if instance.__class__ == rh.EmployeCommentaire:
276 instance.owner = request.user
277 instance.save()
babf71ec
NC
278
279class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
280 pass
281
54d04eed 282
babf71ec 283class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
284 pass
285
54d04eed 286
6e7c919b 287class EvenementAdmin(admin.ModelAdmin):
babf71ec 288 inlines = (EvenementRemunerationInline,)
6e7c919b 289
54d04eed 290
6e7c919b
NC
291class EvenementRemunerationAdmin(admin.ModelAdmin):
292 pass
293
54d04eed 294
26dacccc 295class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 296 inlines = (TypePosteInline,)
26dacccc
OL
297 fieldsets = AUFMetadataAdminMixin.fieldsets + (
298 (None, {
299 'fields': ('nom', )
300 }),
301 )
6e7c919b 302
54d04eed 303
43f5653a 304class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 305 search_fields = ('nom', )
1c8856ef 306 list_display = ('nom', 'type', 'pays', )
babf71ec 307 inlines = (DossierROInline,)
43f5653a
OL
308 fieldsets = AUFMetadataAdminMixin.fieldsets + (
309 (None, {
310 'fields': ('nom', 'type', 'pays', )
311 }),
312 )
6e7c919b 313
54d04eed 314
d2cf315a 315class PosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387ab827 316 alphabet_filter = 'nom'
70561dc2
OL
317 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
318 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
d2cf315a 319 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b
NC
320 (None, {
321 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
322 'service', 'responsable')
323 }),
324 ('Contrat', {
325 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
326 }),
327 ('Recrutement', {
328 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
329 }),
330 ('Rémunération', {
331 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
332 'valeur_point_max', 'devise_min', 'devise_max',
333 'salaire_min', 'salaire_max', 'indemn_min',
334 'indemn_max', 'autre_min', 'autre_max')
335 }),
336 ('Comparatifs de rémunération', {
337 'fields': ('devise_comparaison', 'comp_locale_min',
338 'comp_locale_max', 'comp_universite_min',
339 'comp_universite_max', 'comp_fonctionpub_min',
340 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
341 'comp_autre_min', 'comp_autre_max')
342 }),
343 ('Justification', {
344 'fields': ('justification',)
345 }),
346 ('Autres Metadata', {
347 'fields': ('date_validation', 'date_debut', 'date_fin')
348 }),
349 )
350
babf71ec
NC
351 inlines = (PosteFinancementInline,
352 PostePieceInline,
70561dc2
OL
353 DossierROInline,
354 PosteCommentaireInline, )
6e7c919b 355
70561dc2
OL
356 def save_formset(self, request, form, formset, change):
357 instances = formset.save(commit=False)
358 for instance in instances:
359 if instance.__class__ == rh.PosteCommentaire:
360 instance.owner = request.user
361 instance.save()
362 formset.save_m2m()
6e7c919b
NC
363
364class PosteCommentaireAdmin(admin.ModelAdmin):
365 pass
366
6e7c919b 367
babf71ec 368class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
369 pass
370
6e7c919b 371
babf71ec 372class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
373 pass
374
6e7c919b 375
babf71ec 376class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
377 pass
378
6e7c919b 379
1eede0db
OL
380class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
381 fieldsets = AUFMetadataAdminMixin.fieldsets + (
382 (None, {
383 'fields': ('employe', 'implantation', ),
384 }),
385 )
386
6e7c919b 387
43f5653a
OL
388class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
389 list_display = ('nom', 'actif', )
390 fieldsets = AUFMetadataAdminMixin.fieldsets + (
391 (None, {
392 'fields': ('nom', ),
393 }),
394 )
6e7c919b 395
43f5653a
OL
396class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
397 fieldsets = AUFMetadataAdminMixin.fieldsets + (
398 (None, {
399 'fields': ('code', 'nom', ),
400 }),
401 )
6e7c919b 402
babf71ec 403class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
404 list_display = ('taux', 'devise', 'annee', )
405 list_filter = ('devise', )
dcbadfad
OL
406 fieldsets = AUFMetadataAdminMixin.fieldsets + (
407 (None, {
408 'fields': ('taux', 'devise', 'annee', ),
409 }),
410 )
6e7c919b 411
6e7c919b 412class TypeContratAdmin(admin.ModelAdmin):
babf71ec 413 inlines = (ContratInline,)
6e7c919b 414
6e7c919b 415
240893cb 416class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 417 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
418 list_display = ('nom', 'famille_emploi', )
419 list_filter = ('famille_emploi', )
240893cb
OL
420 fieldsets = AUFMetadataAdminMixin.fieldsets + (
421 (None, {
422 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
423 }),
424 )
6e7c919b 425
6e7c919b 426
3f486b41 427class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 428 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
429 #inlines = (RemunerationROInline,) utilité?
430 fieldsets = AUFMetadataAdminMixin.fieldsets + (
431 (None, {
432 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
433 }),
434 )
6e7c919b 435
6e7c919b 436
3f486b41
OL
437class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
438 #inlines = (RemunerationROInline,) utilité?
439 fieldsets = AUFMetadataAdminMixin.fieldsets + (
440 (None, {
441 'fields': ('nom', )
442 }),
443 )
6e7c919b 444
6e7c919b 445
84fc088b 446class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 447 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
448 fieldsets = AUFMetadataAdminMixin.fieldsets + (
449 (None, {
450 'fields': ('valeur', 'devise', 'implantation', 'annee', )
451 }),
452 )
701f3bea
OL
453
454 def _devise_code(self, obj):
455 return obj.devise.code
456 _devise_code.short_description = "Code de la devise"
457
458 def _devise_nom(self, obj):
459 return obj.devise.nom
460 _devise_nom.short_description = "Nom de la devise"