#1539, #1540, #1542
[auf_rh_dae.git] / project / rh / lib.py
1 # -*- encoding: utf-8 -*-
2
3 import datetime
4 from django.db import models
5 from django.contrib import admin
6
7 from project.rh import models as rh
8
9 # MetaData
10 METADATA_READONLY_FIELDS = ('supprime',
11 'date_creation',
12 'user_creation',
13 'date_modification',
14 'user_modification',
15 'date_activation',
16 'user_activation',
17 'date_desactivation',
18 'user_desactivation', )
19
20 METADATA_FIELDSET_FIELDS = ('actif', 'date_creation', 'user_creation',
21 'date_modification', 'user_modification',
22 'date_activation', 'user_activation',
23 'date_desactivation', 'user_desactivation',)
24
25 class MetadataAdminMixin(object):
26 """
27 Surcharge l'admin de base, pour setter automatiquement les metadata
28 """
29 def save_model(self, request, obj, form, change):
30 if change is False:
31 obj.user_creation = request.user
32 obj.date_creation = datetime.datetime.now()
33 obj.user_modification = request.user
34 obj.date_modification = datetime.datetime.now()
35 if form.initial['actif'] is True and obj.actif is False:
36 obj.user_desactivation = request.user
37 obj.date_desactivation = datetime.datetime.now()
38 if form.initial['actif'] is False and obj.actif is True:
39 obj.user_activation = request.user
40 obj.date_activation = datetime.datetime.now()
41 obj.save()
42
43 class ReadonlyInlineMixin(object):
44 def get_readonly_fields(self, request, obj=None):
45 return [f.name for f in self.model._meta.fields]
46
47
48 # Inlines
49
50 class AyantDroitInline(admin.TabularInline):
51 model = models.Model # à remplacer dans admin.py
52
53
54 class AyantDroitCommentaireInline(admin.TabularInline):
55 model = models.Model # à remplacer dans admin.py
56
57
58 class ContratInline(admin.TabularInline):
59 model = models.Model # à remplacer dans admin.py
60 exclude = METADATA_READONLY_FIELDS + ('actif', )
61 extra = 1
62
63
64 class DossierROInline(ReadonlyInlineMixin, admin.TabularInline):
65 model = models.Model # à remplacer dans admin.py
66
67
68 class DossierCommentaireInline(admin.TabularInline, MetadataAdminMixin):
69 exclude = METADATA_READONLY_FIELDS + ('actif', )
70 readonly_fields = ('owner', )
71 model = models.Model # à remplacer dans admin.py
72 extra = 1
73
74 class DossierPieceInline(admin.TabularInline):
75 model = models.Model # à remplacer dans admin.py
76
77
78 class EmployeInline(admin.TabularInline):
79 model = models.Model # à remplacer dans admin.py
80
81
82 class EmployeCommentaireInline(admin.TabularInline):
83 model = models.Model # à remplacer dans admin.py
84
85
86 class EmployePieceInline(admin.TabularInline):
87 model = models.Model # à remplacer dans admin.py
88
89
90 class EvenementInline(admin.TabularInline, MetadataAdminMixin):
91 model = models.Model # à remplacer dans admin.py
92 exclude = METADATA_READONLY_FIELDS + ('actif', )
93 extra = 1
94
95
96 class EvenementRemunerationInline(admin.TabularInline, MetadataAdminMixin):
97 model = models.Model # à remplacer dans admin.py
98 exclude = METADATA_READONLY_FIELDS + ('actif', )
99 extra = 1
100
101
102 class PosteInline(admin.TabularInline):
103 model = models.Model # à remplacer dans admin.py
104
105
106 class PosteCommentaireInline(admin.TabularInline):
107 model = models.Model # à remplacer dans admin.py
108
109
110 class PosteFinancementInline(admin.TabularInline):
111 model = models.Model # à remplacer dans admin.py
112
113
114 class PostePieceInline(admin.TabularInline):
115 model = models.Model # à remplacer dans admin.py
116
117
118 class RemunerationInline(admin.TabularInline):
119 model = models.Model # à remplacer dans admin.py
120 exclude = METADATA_READONLY_FIELDS + ('actif', )
121 extra = 1
122
123
124 class RemunerationROInline(ReadonlyInlineMixin, RemunerationInline):
125 pass
126
127
128 class TypePosteInline(admin.TabularInline):
129 model = models.Model # à remplacer dans admin.py
130
131
132 # Admins
133
134 class AyantDroitAdmin(admin.ModelAdmin):
135 inlines = (AyantDroitCommentaireInline,)
136
137
138 class AyantDroitCommentaireAdmin(admin.ModelAdmin):
139 pass
140
141
142 class ClassementAdmin(admin.ModelAdmin):
143 pass
144
145
146 class CommentaireAdmin(admin.ModelAdmin):
147 pass
148
149
150 class ContratAdmin(admin.ModelAdmin):
151 pass
152
153
154 class DeviseAdmin(admin.ModelAdmin):
155 pass
156
157
158 class DossierAdmin(MetadataAdminMixin, admin.ModelAdmin,):
159 search_fields = ('employe__nom', 'employe__prenom', )
160 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
161 inlines = (DossierPieceInline, ContratInline,
162 RemunerationInline, EvenementInline, DossierCommentaireInline,
163 )
164 readonly_fields = METADATA_READONLY_FIELDS
165 fieldsets = (
166 ('Metadata', {
167 'classes': ('collapse',),
168 'fields': METADATA_FIELDSET_FIELDS,
169 }),
170 ('Identification', {
171 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
172 }),
173 ('Recrutement', {
174 'fields': ('remplacement', 'statut_residence', )
175 }),
176 ('Rémunération', {
177 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
178 }),
179 ('Occupation du Poste par cet Employe', {
180 'fields': ('date_debut', 'date_fin', )
181 }),
182 )
183
184 def _poste(self, dossier):
185 return unicode(dossier.poste.nom)
186 _poste.short_description = u'Poste'
187
188 def _employe(self, dossier):
189 return unicode(dossier.employe)
190 _employe.short_description = u'Employé'
191
192 def save_formset(self, 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(admin.ModelAdmin):
209 inlines = (AyantDroitInline,
210 DossierROInline,
211 EmployePieceInline,
212 EmployeCommentaireInline)
213
214
215 class EmployeCommentaireAdmin(admin.ModelAdmin):
216 pass
217
218
219 class EmployePieceAdmin(admin.ModelAdmin):
220 pass
221
222
223 class EvenementAdmin(admin.ModelAdmin):
224 inlines = (EvenementRemunerationInline,)
225
226
227 class EvenementRemunerationAdmin(admin.ModelAdmin):
228 pass
229
230
231 class FamilleEmploiAdmin(admin.ModelAdmin):
232 inlines = (TypePosteInline,)
233
234
235 class OrganismeBstgAdmin(admin.ModelAdmin):
236 inlines = (DossierROInline,)
237
238
239 class PosteAdmin(admin.ModelAdmin):
240 fieldsets = (
241 (None, {
242 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
243 'service', 'responsable')
244 }),
245 ('Contrat', {
246 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
247 }),
248 ('Recrutement', {
249 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
250 }),
251 ('Rémunération', {
252 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
253 'valeur_point_max', 'devise_min', 'devise_max',
254 'salaire_min', 'salaire_max', 'indemn_min',
255 'indemn_max', 'autre_min', 'autre_max')
256 }),
257 ('Comparatifs de rémunération', {
258 'fields': ('devise_comparaison', 'comp_locale_min',
259 'comp_locale_max', 'comp_universite_min',
260 'comp_universite_max', 'comp_fonctionpub_min',
261 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
262 'comp_autre_min', 'comp_autre_max')
263 }),
264 ('Justification', {
265 'fields': ('justification',)
266 }),
267 ('Autres Metadata', {
268 'fields': ('date_validation', 'date_debut', 'date_fin')
269 }),
270 )
271
272 inlines = (PosteFinancementInline,
273 PostePieceInline,
274 PosteCommentaireInline,
275 DossierROInline)
276
277
278 class PosteCommentaireAdmin(admin.ModelAdmin):
279 pass
280
281
282 class PosteFinancementAdmin(admin.ModelAdmin):
283 pass
284
285
286 class PostePieceAdmin(admin.ModelAdmin):
287 pass
288
289
290 class RemunerationAdmin(admin.ModelAdmin):
291 pass
292
293
294 class ResponsableImplantationAdmin(admin.ModelAdmin):
295 pass
296
297
298 class ServiceAdmin(admin.ModelAdmin):
299 inlines = (PosteInline,)
300
301
302 class StatutAdmin(admin.ModelAdmin):
303 inlines = (EmployeInline,)
304
305
306 class TauxChangeAdmin(admin.ModelAdmin):
307 pass
308
309
310 class TypeContratAdmin(admin.ModelAdmin):
311 inlines = (ContratInline,)
312
313
314 class TypePosteAdmin(admin.ModelAdmin):
315 inlines = (PosteInline,)
316
317
318 class TypeRemunerationAdmin(admin.ModelAdmin):
319 inlines = (RemunerationROInline,)
320
321
322 class TypeRevalorisationAdmin(admin.ModelAdmin):
323 inlines = (RemunerationROInline,)
324
325
326 class ValeurPointAdmin(admin.ModelAdmin):
327 pass