skip info
[auf_rh_dae.git] / project / dae / admin.py
CommitLineData
17353922
OL
1# -*- encoding: utf-8 -*-
2
3from django.contrib import admin
460771c1 4from django import forms
17353922 5from reversion.admin import VersionAdmin
460771c1 6from auf.django.workflow.models import WorkflowCommentaire
4be5ead0 7from models import Poste, Dossier
17353922
OL
8
9class PosteAdmin(VersionAdmin):
b473fbb6 10 list_display = ('nom', 'implantation', 'etat', )
515124ec 11
4be5ead0
OL
12class DossierAdmin(VersionAdmin):
13 list_display = ('_poste', '_implantation', 'employe', 'etat', )
317ce433 14 list_filter = ('etat', )
460771c1 15 exclude = ('etat', )
4be5ead0
OL
16
17 def _poste(self, obj):
18 return obj.poste.nom
19
20 def _implantation(self, obj):
21 return obj.poste.implantation
17353922 22
460771c1
OL
23class ProxyDossierStatut(Dossier):
24 class Meta:
25 proxy = True
26 verbose_name = "Statut du dossier"
27 verbose_name_plural = "Statut des dossiers"
28
29
30class StatutDossierForm(forms.ModelForm):
31
32 commentaire = forms.CharField(label="Commentaire",
33 widget=forms.widgets.Textarea())
34
35 class Meta:
36 model = ProxyDossierStatut
37 fields = ('etat', )
38
39 def __init__(self, *args, **kwargs):
40 super(StatutDossierForm, self).__init__(*args, **kwargs)
41
42 # On retire le controle check des états pour faire ce qu'on veut
43 self._meta.model.__setattr__ = object.__setattr__
44
45 # on prépare le commentaire
46 self.wf = WorkflowCommentaire()
47 self.wf.etat_initial = self.instance.etat
48 self.wf.owner_id = self.user.id
49
50 def save(self, *args, **kwargs):
51 # Le dossier se voit attribuée un commentaire WF verbeux
52 obj = super(StatutDossierForm, self).save(*args, **kwargs)
53 self.wf.content_object = obj
54 self.wf.etat_final = obj.etat
55 commentaire = u"%s => %s : %s" % (self.wf.etat_initial, self.wf.etat_final,
56 self.data['commentaire'])
57 self.wf.texte = commentaire
58 self.wf.save()
59 return obj
60
61
62class DossierStatutAdmin(VersionAdmin):
63 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', )
64 list_display = ('_poste', '_implantation', 'employe', '_etat', )
65 form = StatutDossierForm
66 action = None
67
68 def _poste(self, obj):
69 return obj.poste.nom
70
71 def _implantation(self, obj):
72 return obj.poste.implantation
73
74 def _etat(self, obj):
75 return obj.get_etat_display()
76
77 def has_delete_permission(self, request, obj=None):
78 return False
79
80 def has_add_permission(self, request):
81 return False
82
83 def has_change_permission(self, request, obj=None):
84 return request.user.is_superuser
85
86 def get_form(self, request, obj=None, **kwargs):
87 form = super(DossierStatutAdmin, self).get_form(request,
88 obj, **kwargs)
89 form.user = request.user
90 return form
91
b318efda
OL
92admin.site.register(Poste, PosteAdmin)
93admin.site.register(Dossier, DossierAdmin)
460771c1 94admin.site.register(ProxyDossierStatut, DossierStatutAdmin)