author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 18 Aug 2009 09:25:26 +0200 | |
changeset 2901 | 8f4d495c94c2 |
parent 2789 | 39712da6f397 |
child 2968 | 0e3460341023 |
permissions | -rw-r--r-- |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
1 |
"""workflow views: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
2 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
3 |
* IWorkflowable views and forms |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
4 |
* workflow entities views (State, Transition, TrInfo) |
0 | 5 |
|
6 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
7 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 8 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
9 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 10 |
""" |
11 |
__docformat__ = "restructuredtext en" |
|
1739 | 12 |
_ = unicode |
0 | 13 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
14 |
from logilab.mtconverter import xml_escape |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
15 |
from logilab.common.graph import escape, GraphGenerator, DotBackend |
822 | 16 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
17 |
from cubicweb import Unauthorized, view |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
18 |
from cubicweb.selectors import (implements, has_related_entities, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
19 |
relation_possible, match_form_params) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
20 |
from cubicweb.interfaces import IWorkflowable |
2438
576f4d51f826
[cleanup] fix deprecation warnings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2381
diff
changeset
|
21 |
from cubicweb.view import EntityView |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
22 |
from cubicweb.web import stdmsgs, action, component, form |
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1305
diff
changeset
|
23 |
from cubicweb.web.form import FormViewMixIn |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
24 |
from cubicweb.web.formfields import StringField, RichTextField |
1304 | 25 |
from cubicweb.web.formwidgets import HiddenInput, SubmitButton, Button |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1995
diff
changeset
|
26 |
from cubicweb.web.views import TmpFileViewMixin, forms |
1151
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
27 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
28 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
29 |
# IWorkflowable views ######################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
30 |
|
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1995
diff
changeset
|
31 |
class ChangeStateForm(forms.EntityFieldsForm): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
32 |
id = 'changestate' |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
33 |
|
1995
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
34 |
form_renderer_id = 'base' # don't want EntityFormRenderer |
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
35 |
form_buttons = [SubmitButton(stdmsgs.YES), |
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
36 |
Button(stdmsgs.NO, cwaction='cancel')] |
ec95eaa2b711
turn renderers into appobjects
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
37 |
|
1305
395ef7f2b95b
cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
38 |
__method = StringField(name='__method', initial='set_state', |
395ef7f2b95b
cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
39 |
widget=HiddenInput) |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1504
diff
changeset
|
40 |
state = StringField(eidparam=True, widget=HiddenInput) |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1504
diff
changeset
|
41 |
trcomment = RichTextField(label=_('comment:'), eidparam=True) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
42 |
|
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
43 |
|
1318
50e1a778c5ee
new FormViewMixIn class, cleanup FormMixIn (to remove once cubes doesn't use it anymore)
sylvain.thenault@logilab.fr
parents:
1305
diff
changeset
|
44 |
class ChangeStateFormView(FormViewMixIn, view.EntityView): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
45 |
id = 'statuschange' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
46 |
title = _('status change') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
47 |
__select__ = implements(IWorkflowable) & match_form_params('treid') |
0 | 48 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
49 |
def cell_call(self, row, col): |
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2726
diff
changeset
|
50 |
entity = self.rset.get_entity(row, col) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
51 |
state = entity.in_state[0] |
2680
66472d85d548
[R] use req.entity_from_eid
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2506
diff
changeset
|
52 |
transition = self.req.entity_from_eid(self.req.form['treid']) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
53 |
dest = transition.destination() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
54 |
_ = self.req._ |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
55 |
form = self.vreg.select('forms', 'changestate', self.req, rset=self.rset, |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
56 |
row=row, col=col, entity=entity, |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
57 |
redirect_path=self.redirectpath(entity)) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
58 |
self.w(form.error_message()) |
1305
395ef7f2b95b
cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
59 |
self.w(u'<h4>%s %s</h4>\n' % (_(transition.name), |
395ef7f2b95b
cleanup, remove some unnecessary (sometime buggy) stuff
sylvain.thenault@logilab.fr
parents:
1304
diff
changeset
|
60 |
entity.view('oneline'))) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
61 |
msg = _('status will change from %(st1)s to %(st2)s') % { |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
62 |
'st1': _(state.name), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
63 |
'st2': _(dest.name)} |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
64 |
self.w(u'<p>%s</p>\n' % msg) |
2725
6d0acd812d98
need to set default value for trcomment_format since it's not an actual field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
65 |
self.w(form.form_render(state=dest.eid, trcomment=u'', |
6d0acd812d98
need to set default value for trcomment_format since it's not an actual field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
66 |
trcomment_format=self.req.property_value('ui.default-text-format'))) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
67 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
68 |
def redirectpath(self, entity): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
69 |
return entity.rest_path() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
70 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
71 |
|
2440
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
72 |
class WFHistoryView(EntityView): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
73 |
id = 'wfhistory' |
2440
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
74 |
__select__ = relation_possible('wf_info_for', role='object') |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
75 |
title = _('Workflow history') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
76 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
77 |
def cell_call(self, row, col, view=None): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
78 |
_ = self.req._ |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
79 |
eid = self.rset[row][col] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
80 |
sel = 'Any FS,TS,WF,D' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
81 |
rql = ' ORDERBY D DESC WHERE WF wf_info_for X,'\ |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
82 |
'WF from_state FS, WF to_state TS, WF comment C,'\ |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
83 |
'WF creation_date D' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1318
diff
changeset
|
84 |
if self.vreg.schema.eschema('CWUser').has_perm(self.req, 'read'): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
85 |
sel += ',U,C' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
86 |
rql += ', WF owned_by U?' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
87 |
displaycols = range(5) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
88 |
headers = (_('from_state'), _('to_state'), _('comment'), _('date'), |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
89 |
_('CWUser')) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
90 |
else: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
91 |
sel += ',C' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
92 |
displaycols = range(4) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
93 |
headers = (_('from_state'), _('to_state'), _('comment'), _('date')) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
94 |
rql = '%s %s, X eid %%(x)s' % (sel, rql) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
95 |
try: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
96 |
rset = self.req.execute(rql, {'x': eid}, 'x') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
97 |
except Unauthorized: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
98 |
return |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
99 |
if rset: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
100 |
self.wview('table', rset, title=_(self.title), displayactions=False, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
101 |
displaycols=displaycols, headers=headers) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
102 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
103 |
|
2440
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
104 |
class WFHistoryVComponent(component.EntityVComponent): |
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
105 |
"""display the workflow history for entities supporting it""" |
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
106 |
id = 'wfhistory' |
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
107 |
__select__ = WFHistoryView.__select__ & component.EntityVComponent.__select__ |
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
108 |
context = 'navcontentbottom' |
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
109 |
title = _('Workflow history') |
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
110 |
|
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
111 |
def cell_call(self, row, col, view=None): |
8e6b83e3b6b5
#343227: display the workflow history of any entity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2438
diff
changeset
|
112 |
self.wview('wfhistory', self.rset, row=row, col=col, view=view) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
113 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
114 |
# workflow entity types views ################################################# |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
115 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
116 |
class CellView(view.EntityView): |
0 | 117 |
id = 'cell' |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
118 |
__select__ = implements('TrInfo') |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
119 |
|
0 | 120 |
def cell_call(self, row, col, cellvid=None): |
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2726
diff
changeset
|
121 |
self.w(self.rset.get_entity(row, col).view('reledit', rtype='comment')) |
795
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
122 |
|
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
123 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
124 |
class StateInContextView(view.EntityView): |
795
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
125 |
"""convenience trick, State's incontext view should not be clickable""" |
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
126 |
id = 'incontext' |
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
127 |
__select__ = implements('State') |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
128 |
|
795
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
129 |
def cell_call(self, row, col): |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
130 |
self.w(xml_escape(self.view('textincontext', self.rset, |
795
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
131 |
row=row, col=col))) |
63f4f81e19f1
restore appropriate in State's incontext view, moved it into wfentities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
132 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
133 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
134 |
# workflow images ############################################################# |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
135 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
136 |
class ViewWorkflowAction(action.Action): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
137 |
id = 'workflow' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1318
diff
changeset
|
138 |
__select__ = implements('CWEType') & has_related_entities('state_of', 'object') |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
139 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
140 |
category = 'mainactions' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
141 |
title = _('view workflow') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
142 |
def url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
143 |
entity = self.rset.get_entity(self.row or 0, self.col or 0) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
144 |
return entity.absolute_url(vid='workflow') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
145 |
|
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
146 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1318
diff
changeset
|
147 |
class CWETypeWorkflowView(view.EntityView): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
148 |
id = 'workflow' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1318
diff
changeset
|
149 |
__select__ = implements('CWEType') |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
150 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
151 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
152 |
def cell_call(self, row, col, **kwargs): |
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2726
diff
changeset
|
153 |
entity = self.rset.get_entity(row, col) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
154 |
self.w(u'<h1>%s</h1>' % (self.req._('workflow for %s') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
155 |
% display_name(self.req, entity.name))) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
156 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
157 |
xml_escape(entity.absolute_url(vid='ewfgraph')), |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
158 |
xml_escape(self.req._('graphical workflow for %s') % entity.name))) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
159 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
160 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
161 |
class WorkflowDotPropsHandler(object): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
162 |
def __init__(self, req): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
163 |
self._ = req._ |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
164 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
165 |
def node_properties(self, stateortransition): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
166 |
"""return default DOT drawing options for a state or transition""" |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
167 |
props = {'label': stateortransition.name, |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
168 |
'fontname': 'Courier'} |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
169 |
if hasattr(stateortransition, 'state_of'): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
170 |
props['shape'] = 'box' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
171 |
props['style'] = 'filled' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
172 |
if stateortransition.reverse_initial_state: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
173 |
props['color'] = '#88CC88' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
174 |
else: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
175 |
props['shape'] = 'ellipse' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
176 |
descr = [] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
177 |
tr = stateortransition |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
178 |
if tr.require_group: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
179 |
descr.append('%s %s'% ( |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
180 |
self._('groups:'), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
181 |
','.join(g.name for g in tr.require_group))) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
182 |
if tr.condition: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
183 |
descr.append('%s %s'% (self._('condition:'), tr.condition)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
184 |
if descr: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
185 |
props['label'] += escape('\n'.join(descr)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
186 |
return props |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
187 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
188 |
def edge_properties(self, transition, fromstate, tostate): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
189 |
return {'label': '', 'dir': 'forward', |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
190 |
'color': 'black', 'style': 'filled'} |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
191 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
192 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
193 |
class WorkflowVisitor: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
194 |
def __init__(self, entity): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
195 |
self.entity = entity |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
196 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
197 |
def nodes(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
198 |
for state in self.entity.reverse_state_of: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
199 |
state.complete() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
200 |
yield state.eid, state |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
201 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
202 |
for transition in self.entity.reverse_transition_of: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
203 |
transition.complete() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
204 |
yield transition.eid, transition |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
205 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
206 |
def edges(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
207 |
for transition in self.entity.reverse_transition_of: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
208 |
for incomingstate in transition.reverse_allowed_transition: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
209 |
yield incomingstate.eid, transition.eid, transition |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
210 |
yield transition.eid, transition.destination().eid, transition |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
211 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
212 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1318
diff
changeset
|
213 |
class CWETypeWorkflowImageView(TmpFileViewMixin, view.EntityView): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
214 |
id = 'ewfgraph' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
215 |
content_type = 'image/png' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1318
diff
changeset
|
216 |
__select__ = implements('CWEType') |
1504
c6051f141807
register to catalog, delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
217 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
218 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
219 |
"""display schema information for an entity""" |
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2726
diff
changeset
|
220 |
entity = self.rset.get_entity(self.row, self.col) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
221 |
visitor = WorkflowVisitor(entity) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
222 |
prophdlr = WorkflowDotPropsHandler(self.req) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
223 |
generator = GraphGenerator(DotBackend('workflow', 'LR', |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
224 |
ratio='compress', size='30,12')) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
225 |
return generator.generate(visitor, prophdlr, tmpfile) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
984
diff
changeset
|
226 |