debug ajout resp implantation
[auf_rh_dae.git] / project / dae / admin.py
CommitLineData
17353922
OL
1# -*- encoding: utf-8 -*-
2
460771c1 3from django import forms
47d7067b 4from django.contrib import admin
75f0e87b 5
17353922 6from reversion.admin import VersionAdmin
5a1f75cb 7
75f0e87b
DB
8from auf.django.workflow.models import WorkflowCommentaire
9
de151a1e 10from project.dae.models import Poste, Dossier
5a1f75cb 11
746d94af 12
08a9b6fc
EMS
13class BaseAdmin(admin.ModelAdmin):
14
15 class Media:
16 css = {'screen': ('css/admin_custom.css',)}
17
18
19class PosteAdmin(BaseAdmin, VersionAdmin):
b473fbb6 20 list_display = ('nom', 'implantation', 'etat', )
515124ec 21
a6245d0f 22
08a9b6fc 23class DossierAdmin(BaseAdmin, VersionAdmin):
4be5ead0 24 list_display = ('_poste', '_implantation', 'employe', 'etat', )
317ce433 25 list_filter = ('etat', )
460771c1 26 exclude = ('etat', )
4be5ead0
OL
27
28 def _poste(self, obj):
29 return obj.poste.nom
30
31 def _implantation(self, obj):
32 return obj.poste.implantation
17353922 33
a6245d0f 34
460771c1
OL
35class ProxyDossierStatut(Dossier):
36 class Meta:
37 proxy = True
38 verbose_name = "Statut du dossier"
39 verbose_name_plural = "Statut des dossiers"
40
41
a6245d0f
OL
42class ProxyPosteStatut(Poste):
43 class Meta:
44 proxy = True
45 verbose_name = "Statut du poste"
46 verbose_name_plural = "Statut des postes"
47
48
49class StatutForm(forms.ModelForm):
460771c1
OL
50 commentaire = forms.CharField(label="Commentaire",
51 widget=forms.widgets.Textarea())
52
460771c1 53 def __init__(self, *args, **kwargs):
a6245d0f 54 super(StatutForm, self).__init__(*args, **kwargs)
460771c1
OL
55 # On retire le controle check des états pour faire ce qu'on veut
56 self._meta.model.__setattr__ = object.__setattr__
57
58 # on prépare le commentaire
59 self.wf = WorkflowCommentaire()
60 self.wf.etat_initial = self.instance.etat
61 self.wf.owner_id = self.user.id
746d94af 62
460771c1
OL
63 def save(self, *args, **kwargs):
64 # Le dossier se voit attribuée un commentaire WF verbeux
a6245d0f 65 obj = super(StatutForm, self).save(*args, **kwargs)
460771c1
OL
66 self.wf.content_object = obj
67 self.wf.etat_final = obj.etat
df625f22
OL
68 commentaire = u"%s => %s : %s" % (
69 self.wf.get_etat_label(self.wf.etat_initial),
70 self.wf.get_etat_label(self.wf.etat_final),
460771c1
OL
71 self.data['commentaire'])
72 self.wf.texte = commentaire
73 self.wf.save()
74 return obj
460771c1 75
460771c1 76
a6245d0f 77class StatutDossierForm(StatutForm):
460771c1 78
a6245d0f
OL
79 class Meta:
80 model = ProxyDossierStatut
81 fields = ('etat', )
460771c1 82
460771c1 83
a6245d0f 84class StatutPosteForm(StatutForm):
04a96961 85
a6245d0f
OL
86 class Meta:
87 model = ProxyPosteStatut
88 fields = ('etat', )
460771c1 89
a6245d0f 90
08a9b6fc 91class StatutAdmin(BaseAdmin, VersionAdmin):
a6245d0f 92 action = None
460771c1
OL
93
94 def has_delete_permission(self, request, obj=None):
95 return False
96
97 def has_add_permission(self, request):
98 return False
99
100 def has_change_permission(self, request, obj=None):
101 return request.user.is_superuser
102
103 def get_form(self, request, obj=None, **kwargs):
a6245d0f 104 form = super(StatutAdmin, self).get_form(request,
460771c1
OL
105 obj, **kwargs)
106 form.user = request.user
107 return form
108
a6245d0f
OL
109 def _etat(self, obj):
110 return obj.get_etat_display()
df625f22
OL
111 _etat.short_description = "État"
112 _etat.admin_order_field = "etat"
a6245d0f 113
5a1f75cb 114
a6245d0f
OL
115class DossierStatutAdmin(StatutAdmin):
116 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', )
117 list_display = ('_poste', '_implantation', 'employe', '_etat', )
df625f22 118 list_filter = ('poste__implantation', )
a6245d0f
OL
119 form = StatutDossierForm
120
121 def _poste(self, obj):
122 return obj.poste.nom
123
124 def _implantation(self, obj):
125 return obj.poste.implantation
df625f22
OL
126 _implantation.short_description = u"Implantation"
127 _implantation.admin_order_field = "poste__implantation"
a6245d0f 128
5a1f75cb 129
a6245d0f
OL
130class PosteStatutAdmin(StatutAdmin):
131 search_fields = ('nom', )
df625f22
OL
132 list_display = ('nom', 'implantation', )
133 list_filter = ('implantation', 'etat', )
a6245d0f
OL
134 form = StatutPosteForm
135
136
b318efda
OL
137admin.site.register(Poste, PosteAdmin)
138admin.site.register(Dossier, DossierAdmin)
460771c1 139admin.site.register(ProxyDossierStatut, DossierStatutAdmin)
a6245d0f 140admin.site.register(ProxyPosteStatut, PosteStatutAdmin)