plug metadata module #1544
[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
d6985a3a 5from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 6from project.rh import models as rh
6e7c919b 7
d6985a3a 8# Inlines
6e7c919b 9
d6985a3a
OL
10class ReadOnlyInlineMixin(object):
11 def get_readonly_fields(self, request, obj=None):
12 return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS]
6e7c919b
NC
13
14
d6985a3a 15class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 16 model = models.Model # à remplacer dans admin.py
cf786fb2 17 extra = 1
54d04eed 18
d6985a3a
OL
19
20class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 21 readonly_fields = ('owner', )
babf71ec 22 model = models.Model # à remplacer dans admin.py
cf786fb2 23 extra = 1
6e7c919b 24
54d04eed 25
d6985a3a 26class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 27 model = models.Model # à remplacer dans admin.py
1f2979b8 28 extra = 1
babf71ec
NC
29
30
d6985a3a
OL
31class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
32 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 33 model = models.Model # à remplacer dans admin.py
babf71ec 34
d6985a3a
OL
35
36class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 37 readonly_fields = ('owner', )
babf71ec 38 model = models.Model # à remplacer dans admin.py
1f2979b8 39 extra = 1
babf71ec 40
d6985a3a 41
babf71ec
NC
42class DossierPieceInline(admin.TabularInline):
43 model = models.Model # à remplacer dans admin.py
44
45
46class EmployeInline(admin.TabularInline):
47 model = models.Model # à remplacer dans admin.py
48
d6985a3a 49class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 50 readonly_fields = ('owner', )
babf71ec 51 model = models.Model # à remplacer dans admin.py
cf786fb2 52 extra = 1
babf71ec
NC
53
54
55class EmployePieceInline(admin.TabularInline):
56 model = models.Model # à remplacer dans admin.py
57
58
d6985a3a 59class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 60 model = models.Model # à remplacer dans admin.py
1f2979b8 61 extra = 1
babf71ec
NC
62
63
d6985a3a 64class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 65 model = models.Model # à remplacer dans admin.py
1f2979b8 66 extra = 1
babf71ec
NC
67
68
69class PosteInline(admin.TabularInline):
70 model = models.Model # à remplacer dans admin.py
71
72
d6985a3a 73class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 74 readonly_fields = ('owner', )
babf71ec 75 model = models.Model # à remplacer dans admin.py
70561dc2 76 extra = 1
babf71ec
NC
77
78
79class PosteFinancementInline(admin.TabularInline):
80 model = models.Model # à remplacer dans admin.py
81
82
83class PostePieceInline(admin.TabularInline):
84 model = models.Model # à remplacer dans admin.py
85
86
d6985a3a 87class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 88 model = models.Model # à remplacer dans admin.py
1f2979b8 89 extra = 1
babf71ec
NC
90
91
d6985a3a 92class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
93 pass
94
54d04eed 95
babf71ec
NC
96class TypePosteInline(admin.TabularInline):
97 model = models.Model # à remplacer dans admin.py
98
99
100# Admins
101
d6985a3a 102class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cf786fb2
OL
103 """
104 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
105 """
106 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
107 list_display = ('_ayantdroit', '_employe', )
babf71ec 108 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
109 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
110 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
111 ("Lien avec l'employé", {
112 'fields': ('employe', 'lien_parente', )
113 }),
114
115 ('Identification', {
116 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
117 }),
118 )
119
120 def save_formset(self, request, form, formset, change):
d6985a3a 121 super(AyantDroitAdmin, self).save_formset(request, form, formset, change)
cf786fb2
OL
122 instances = formset.save(commit=False)
123 for instance in instances:
124 if instance.__class__ == rh.AyantDroitCommentaire:
125 instance.owner = request.user
126 instance.save()
127 formset.save_m2m()
128
129 def _ayantdroit(self, obj):
130 return unicode(obj)
131 _ayantdroit.short_description = u'Ayant droit'
babf71ec 132
cf786fb2
OL
133 def _employe(self, obj):
134 return unicode(obj.employe)
135 _employe.short_description = u'Employé'
136
137 def has_add_permission(self, request):
138 return False
babf71ec
NC
139
140class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
141 pass
142
54d04eed 143
babf71ec 144class ClassementAdmin(admin.ModelAdmin):
6e7c919b
NC
145 pass
146
6e7c919b
NC
147
148class CommentaireAdmin(admin.ModelAdmin):
149 pass
150
151
babf71ec 152class ContratAdmin(admin.ModelAdmin):
6e7c919b
NC
153 pass
154
54d04eed 155
babf71ec 156class DeviseAdmin(admin.ModelAdmin):
6e7c919b
NC
157 pass
158
54d04eed 159
d6985a3a 160class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
1f2979b8
OL
161 search_fields = ('employe__nom', 'employe__prenom', )
162 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
163 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
164 RemunerationInline,
165 #EvenementInline,
166 DossierCommentaireInline,
1f2979b8 167 )
d6985a3a 168 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
169 ('Identification', {
170 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
171 }),
172 ('Recrutement', {
173 'fields': ('remplacement', 'statut_residence', )
174 }),
175 ('Rémunération', {
176 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
177 }),
178 ('Occupation du Poste par cet Employe', {
179 'fields': ('date_debut', 'date_fin', )
180 }),
181 )
54d04eed
NC
182
183 def _poste(self, dossier):
184 return unicode(dossier.poste.nom)
185 _poste.short_description = u'Poste'
186
187 def _employe(self, dossier):
188 return unicode(dossier.employe)
189 _employe.short_description = u'Employé'
1f2979b8
OL
190
191 def save_formset(self, request, form, formset, change):
d6985a3a 192 super(DossierAdmin, self).save_formset(request, form, formset, change)
1f2979b8
OL
193 instances = formset.save(commit=False)
194 for instance in instances:
195 if instance.__class__ == rh.DossierCommentaire:
196 instance.owner = request.user
197 instance.save()
198 formset.save_m2m()
6e7c919b
NC
199
200class DossierPieceAdmin(admin.ModelAdmin):
201 pass
202
54d04eed 203
6e7c919b
NC
204class DossierCommentaireAdmin(admin.ModelAdmin):
205 pass
206
54d04eed 207
d6985a3a
OL
208class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
209 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
babf71ec
NC
210 inlines = (AyantDroitInline,
211 DossierROInline,
212 EmployePieceInline,
213 EmployeCommentaireInline)
d6985a3a 214 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
215 ('Identification', {
216 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
217 }),
218 ('Informations personnelles', {
219 'fields': ('situation_famille', 'date_entree', )
220 }),
221 ('Coordonnées', {
222 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
223 }),
224 )
babf71ec 225
cf786fb2 226 def save_formset(self, request, form, formset, change):
d6985a3a 227 super(EmployeAdmin, self).save_formset(request, form, formset, change)
cf786fb2
OL
228 instances = formset.save(commit=False)
229 for instance in instances:
230 if instance.__class__ == rh.EmployeCommentaire:
231 instance.owner = request.user
232 instance.save()
233 formset.save_m2m()
babf71ec
NC
234
235class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
236 pass
237
54d04eed 238
babf71ec 239class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
240 pass
241
54d04eed 242
6e7c919b 243class EvenementAdmin(admin.ModelAdmin):
babf71ec 244 inlines = (EvenementRemunerationInline,)
6e7c919b 245
54d04eed 246
6e7c919b
NC
247class EvenementRemunerationAdmin(admin.ModelAdmin):
248 pass
249
54d04eed 250
6e7c919b 251class FamilleEmploiAdmin(admin.ModelAdmin):
babf71ec 252 inlines = (TypePosteInline,)
6e7c919b 253
54d04eed 254
babf71ec
NC
255class OrganismeBstgAdmin(admin.ModelAdmin):
256 inlines = (DossierROInline,)
6e7c919b 257
54d04eed 258
6e7c919b 259class PosteAdmin(admin.ModelAdmin):
70561dc2
OL
260 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
261 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
6e7c919b
NC
262 fieldsets = (
263 (None, {
264 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
265 'service', 'responsable')
266 }),
267 ('Contrat', {
268 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
269 }),
270 ('Recrutement', {
271 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
272 }),
273 ('Rémunération', {
274 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
275 'valeur_point_max', 'devise_min', 'devise_max',
276 'salaire_min', 'salaire_max', 'indemn_min',
277 'indemn_max', 'autre_min', 'autre_max')
278 }),
279 ('Comparatifs de rémunération', {
280 'fields': ('devise_comparaison', 'comp_locale_min',
281 'comp_locale_max', 'comp_universite_min',
282 'comp_universite_max', 'comp_fonctionpub_min',
283 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
284 'comp_autre_min', 'comp_autre_max')
285 }),
286 ('Justification', {
287 'fields': ('justification',)
288 }),
289 ('Autres Metadata', {
290 'fields': ('date_validation', 'date_debut', 'date_fin')
291 }),
292 )
293
babf71ec
NC
294 inlines = (PosteFinancementInline,
295 PostePieceInline,
70561dc2
OL
296 DossierROInline,
297 PosteCommentaireInline, )
6e7c919b 298
70561dc2
OL
299 def save_formset(self, request, form, formset, change):
300 instances = formset.save(commit=False)
301 for instance in instances:
302 if instance.__class__ == rh.PosteCommentaire:
303 instance.owner = request.user
304 instance.save()
305 formset.save_m2m()
6e7c919b
NC
306
307class PosteCommentaireAdmin(admin.ModelAdmin):
308 pass
309
6e7c919b 310
babf71ec 311class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
312 pass
313
6e7c919b 314
babf71ec 315class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
316 pass
317
6e7c919b 318
babf71ec 319class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
320 pass
321
6e7c919b 322
babf71ec 323class ResponsableImplantationAdmin(admin.ModelAdmin):
6e7c919b
NC
324 pass
325
6e7c919b 326
babf71ec
NC
327class ServiceAdmin(admin.ModelAdmin):
328 inlines = (PosteInline,)
6e7c919b 329
6e7c919b 330
babf71ec
NC
331class StatutAdmin(admin.ModelAdmin):
332 inlines = (EmployeInline,)
6e7c919b 333
6e7c919b 334
babf71ec 335class TauxChangeAdmin(admin.ModelAdmin):
6e7c919b
NC
336 pass
337
6e7c919b 338
6e7c919b 339class TypeContratAdmin(admin.ModelAdmin):
babf71ec 340 inlines = (ContratInline,)
6e7c919b 341
6e7c919b 342
babf71ec
NC
343class TypePosteAdmin(admin.ModelAdmin):
344 inlines = (PosteInline,)
6e7c919b 345
6e7c919b 346
babf71ec
NC
347class TypeRemunerationAdmin(admin.ModelAdmin):
348 inlines = (RemunerationROInline,)
6e7c919b 349
6e7c919b 350
babf71ec
NC
351class TypeRevalorisationAdmin(admin.ModelAdmin):
352 inlines = (RemunerationROInline,)
6e7c919b 353
6e7c919b 354
babf71ec 355class ValeurPointAdmin(admin.ModelAdmin):
6e7c919b 356 pass