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