1 # -*- encoding: utf-8 -*-
3 from django
import forms
4 from django
.contrib
import admin
6 from reversion
.admin
import VersionAdmin
8 from auf
.django
.workflow
.models
import WorkflowCommentaire
10 from project
.dae
.models
import Poste
, Dossier
13 class BaseAdmin(admin
.ModelAdmin
):
16 css
= {'screen': ('css/admin_custom.css',)}
19 class PosteAdmin(BaseAdmin
, VersionAdmin
):
20 list_display
= ('nom', 'implantation', 'etat', )
23 class DossierAdmin(BaseAdmin
, VersionAdmin
):
24 list_display
= ('_poste', '_implantation', 'employe', 'etat', )
25 list_filter
= ('etat', )
28 def _poste(self
, obj
):
31 def _implantation(self
, obj
):
32 return obj
.poste
.implantation
35 class ProxyDossierStatut(Dossier
):
38 verbose_name
= "Statut du dossier"
39 verbose_name_plural
= "Statut des dossiers"
42 class ProxyPosteStatut(Poste
):
45 verbose_name
= "Statut du poste"
46 verbose_name_plural
= "Statut des postes"
49 class StatutForm(forms
.ModelForm
):
50 commentaire
= forms
.CharField(label
="Commentaire",
51 widget
=forms
.widgets
.Textarea())
53 def __init__(self
, *args
, **kwargs
):
54 super(StatutForm
, self
).__init__(*args
, **kwargs
)
55 # On retire le controle check des états pour faire ce qu'on veut
56 self
._meta
.model
.__setattr__
= object.__setattr__
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
63 def save(self
, *args
, **kwargs
):
64 # Le dossier se voit attribuée un commentaire WF verbeux
65 obj
= super(StatutForm
, self
).save(*args
, **kwargs
)
66 self
.wf
.content_object
= obj
67 self
.wf
.etat_final
= obj
.etat
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
),
71 self
.data
['commentaire'])
72 self
.wf
.texte
= commentaire
77 class StatutDossierForm(StatutForm
):
80 model
= ProxyDossierStatut
84 class StatutPosteForm(StatutForm
):
87 model
= ProxyPosteStatut
91 class StatutAdmin(BaseAdmin
, VersionAdmin
):
94 def has_delete_permission(self
, request
, obj
=None):
97 def has_add_permission(self
, request
):
100 def has_change_permission(self
, request
, obj
=None):
101 return request
.user
.is_superuser
103 def get_form(self
, request
, obj
=None, **kwargs
):
104 form
= super(StatutAdmin
, self
).get_form(request
,
106 form
.user
= request
.user
109 def _etat(self
, obj
):
110 return obj
.get_etat_display()
111 _etat
.short_description
= "État"
112 _etat
.admin_order_field
= "etat"
115 class DossierStatutAdmin(StatutAdmin
):
116 search_fields
= ('employe__nom', 'employe__prenom', 'poste__nom', )
117 list_display
= ('_poste', '_implantation', 'employe', '_etat', )
118 list_filter
= ('poste__implantation', )
119 form
= StatutDossierForm
121 def _poste(self
, obj
):
124 def _implantation(self
, obj
):
125 return obj
.poste
.implantation
126 _implantation
.short_description
= u
"Implantation"
127 _implantation
.admin_order_field
= "poste__implantation"
130 class PosteStatutAdmin(StatutAdmin
):
131 search_fields
= ('nom', )
132 list_display
= ('nom', 'implantation', )
133 list_filter
= ('implantation', 'etat', )
134 form
= StatutPosteForm
137 admin
.site
.register(Poste
, PosteAdmin
)
138 admin
.site
.register(Dossier
, DossierAdmin
)
139 admin
.site
.register(ProxyDossierStatut
, DossierStatutAdmin
)
140 admin
.site
.register(ProxyPosteStatut
, PosteStatutAdmin
)