plug metadata module #1544
[auf_rh_dae.git] / project / rh / lib.py
1 # -*- encoding: utf-8 -*-
2
3 from django.db import models
4 from django.contrib import admin
5 from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
6 from project.rh import models as rh
7
8 # Inlines
9
10 class 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]
13
14
15 class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
16 model = models.Model # à remplacer dans admin.py
17 extra = 1
18
19
20 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
21 readonly_fields = ('owner', )
22 model = models.Model # à remplacer dans admin.py
23 extra = 1
24
25
26 class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
27 model = models.Model # à remplacer dans admin.py
28 extra = 1
29
30
31 class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
32 exclude = AUF_METADATA_READONLY_FIELDS
33 model = models.Model # à remplacer dans admin.py
34
35
36 class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
37 readonly_fields = ('owner', )
38 model = models.Model # à remplacer dans admin.py
39 extra = 1
40
41
42 class DossierPieceInline(admin.TabularInline):
43 model = models.Model # à remplacer dans admin.py
44
45
46 class EmployeInline(admin.TabularInline):
47 model = models.Model # à remplacer dans admin.py
48
49 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
50 readonly_fields = ('owner', )
51 model = models.Model # à remplacer dans admin.py
52 extra = 1
53
54
55 class EmployePieceInline(admin.TabularInline):
56 model = models.Model # à remplacer dans admin.py
57
58
59 class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
60 model = models.Model # à remplacer dans admin.py
61 extra = 1
62
63
64 class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
65 model = models.Model # à remplacer dans admin.py
66 extra = 1
67
68
69 class PosteInline(admin.TabularInline):
70 model = models.Model # à remplacer dans admin.py
71
72
73 class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
74 readonly_fields = ('owner', )
75 model = models.Model # à remplacer dans admin.py
76 extra = 1
77
78
79 class PosteFinancementInline(admin.TabularInline):
80 model = models.Model # à remplacer dans admin.py
81
82
83 class PostePieceInline(admin.TabularInline):
84 model = models.Model # à remplacer dans admin.py
85
86
87 class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
88 model = models.Model # à remplacer dans admin.py
89 extra = 1
90
91
92 class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
93 pass
94
95
96 class TypePosteInline(admin.TabularInline):
97 model = models.Model # à remplacer dans admin.py
98
99
100 # Admins
101
102 class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
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', )
108 inlines = (AyantDroitCommentaireInline,)
109 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
110 fieldsets = AUFMetadataAdminMixin.fieldsets + (
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):
121 super(AyantDroitAdmin, self).save_formset(request, form, formset, change)
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'
132
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
139
140 class AyantDroitCommentaireAdmin(admin.ModelAdmin):
141 pass
142
143
144 class ClassementAdmin(admin.ModelAdmin):
145 pass
146
147
148 class CommentaireAdmin(admin.ModelAdmin):
149 pass
150
151
152 class ContratAdmin(admin.ModelAdmin):
153 pass
154
155
156 class DeviseAdmin(admin.ModelAdmin):
157 pass
158
159
160 class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
161 search_fields = ('employe__nom', 'employe__prenom', )
162 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
163 inlines = (DossierPieceInline, ContratInline,
164 RemunerationInline,
165 #EvenementInline,
166 DossierCommentaireInline,
167 )
168 fieldsets = AUFMetadataAdminMixin.fieldsets + (
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 )
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é'
190
191 def save_formset(self, request, form, formset, change):
192 super(DossierAdmin, self).save_formset(request, form, formset, change)
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()
199
200 class DossierPieceAdmin(admin.ModelAdmin):
201 pass
202
203
204 class DossierCommentaireAdmin(admin.ModelAdmin):
205 pass
206
207
208 class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
209 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
210 inlines = (AyantDroitInline,
211 DossierROInline,
212 EmployePieceInline,
213 EmployeCommentaireInline)
214 fieldsets = AUFMetadataAdminMixin.fieldsets + (
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 )
225
226 def save_formset(self, request, form, formset, change):
227 super(EmployeAdmin, self).save_formset(request, form, formset, change)
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()
234
235 class EmployeCommentaireAdmin(admin.ModelAdmin):
236 pass
237
238
239 class EmployePieceAdmin(admin.ModelAdmin):
240 pass
241
242
243 class EvenementAdmin(admin.ModelAdmin):
244 inlines = (EvenementRemunerationInline,)
245
246
247 class EvenementRemunerationAdmin(admin.ModelAdmin):
248 pass
249
250
251 class FamilleEmploiAdmin(admin.ModelAdmin):
252 inlines = (TypePosteInline,)
253
254
255 class OrganismeBstgAdmin(admin.ModelAdmin):
256 inlines = (DossierROInline,)
257
258
259 class PosteAdmin(admin.ModelAdmin):
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', )
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
294 inlines = (PosteFinancementInline,
295 PostePieceInline,
296 DossierROInline,
297 PosteCommentaireInline, )
298
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()
306
307 class PosteCommentaireAdmin(admin.ModelAdmin):
308 pass
309
310
311 class PosteFinancementAdmin(admin.ModelAdmin):
312 pass
313
314
315 class PostePieceAdmin(admin.ModelAdmin):
316 pass
317
318
319 class RemunerationAdmin(admin.ModelAdmin):
320 pass
321
322
323 class ResponsableImplantationAdmin(admin.ModelAdmin):
324 pass
325
326
327 class ServiceAdmin(admin.ModelAdmin):
328 inlines = (PosteInline,)
329
330
331 class StatutAdmin(admin.ModelAdmin):
332 inlines = (EmployeInline,)
333
334
335 class TauxChangeAdmin(admin.ModelAdmin):
336 pass
337
338
339 class TypeContratAdmin(admin.ModelAdmin):
340 inlines = (ContratInline,)
341
342
343 class TypePosteAdmin(admin.ModelAdmin):
344 inlines = (PosteInline,)
345
346
347 class TypeRemunerationAdmin(admin.ModelAdmin):
348 inlines = (RemunerationROInline,)
349
350
351 class TypeRevalorisationAdmin(admin.ModelAdmin):
352 inlines = (RemunerationROInline,)
353
354
355 class ValeurPointAdmin(admin.ModelAdmin):
356 pass