17 from cubicweb import Unauthorized, view |
17 from cubicweb import Unauthorized, view |
18 from cubicweb.selectors import (implements, has_related_entities, |
18 from cubicweb.selectors import (implements, has_related_entities, |
19 relation_possible, match_form_params) |
19 relation_possible, match_form_params) |
20 from cubicweb.interfaces import IWorkflowable |
20 from cubicweb.interfaces import IWorkflowable |
21 from cubicweb.view import EntityView |
21 from cubicweb.view import EntityView |
22 from cubicweb.web import stdmsgs, action, component, form |
22 from cubicweb.schema import display_name |
|
23 from cubicweb.web import stdmsgs, action, component, form, action |
23 from cubicweb.web import formfields as ff, formwidgets as fwdgs |
24 from cubicweb.web import formfields as ff, formwidgets as fwdgs |
24 from cubicweb.web.views import TmpFileViewMixin, forms |
25 from cubicweb.web.views import TmpFileViewMixin, forms, primary |
25 |
26 |
26 |
27 |
27 # IWorkflowable views ######################################################### |
28 # IWorkflowable views ######################################################### |
28 |
29 |
29 class ChangeStateForm(forms.CompositeEntityForm): |
30 class ChangeStateForm(forms.CompositeEntityForm): |
127 def cell_call(self, row, col): |
128 def cell_call(self, row, col): |
128 self.w(xml_escape(self.view('textincontext', self.rset, |
129 self.w(xml_escape(self.view('textincontext', self.rset, |
129 row=row, col=col))) |
130 row=row, col=col))) |
130 |
131 |
131 |
132 |
132 # workflow images ############################################################# |
133 class WorkflowPrimaryView(primary.PrimaryView): |
133 |
|
134 class ViewWorkflowAction(action.Action): |
|
135 id = 'workflow' |
134 id = 'workflow' |
136 __select__ = implements('CWEType') & has_related_entities('workflow_of', 'object') |
135 __select__ = implements('Workflow') |
137 |
|
138 category = 'mainactions' |
|
139 title = _('view workflow') |
|
140 def url(self): |
|
141 entity = self.rset.get_entity(self.row or 0, self.col or 0) |
|
142 return entity.absolute_url(vid='workflow') |
|
143 |
|
144 |
|
145 class CWETypeWorkflowView(view.EntityView): |
|
146 id = 'workflow' |
|
147 __select__ = implements('CWEType') |
|
148 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
136 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
149 |
137 |
150 def cell_call(self, row, col, **kwargs): |
138 def render_entity_attributes(self, entity): |
151 entity = self.entity(row, col) |
|
152 self.w(u'<h1>%s</h1>' % (self.req._('workflow for %s') |
|
153 % display_name(self.req, entity.name))) |
|
154 self.w(u'<img src="%s" alt="%s"/>' % ( |
139 self.w(u'<img src="%s" alt="%s"/>' % ( |
155 xml_escape(entity.absolute_url(vid='ewfgraph')), |
140 xml_escape(entity.absolute_url(vid='wfgraph')), |
156 xml_escape(self.req._('graphical workflow for %s') % entity.name))) |
141 xml_escape(self.req._('graphical workflow for %s') % entity.name))) |
157 |
142 |
|
143 |
|
144 # workflow images ############################################################## |
158 |
145 |
159 class WorkflowDotPropsHandler(object): |
146 class WorkflowDotPropsHandler(object): |
160 def __init__(self, req): |
147 def __init__(self, req): |
161 self._ = req._ |
148 self._ = req._ |
162 |
149 |
206 for incomingstate in transition.reverse_allowed_transition: |
193 for incomingstate in transition.reverse_allowed_transition: |
207 yield incomingstate.eid, transition.eid, transition |
194 yield incomingstate.eid, transition.eid, transition |
208 yield transition.eid, transition.destination().eid, transition |
195 yield transition.eid, transition.destination().eid, transition |
209 |
196 |
210 |
197 |
211 class CWETypeWorkflowImageView(TmpFileViewMixin, view.EntityView): |
198 class WorkflowImageView(TmpFileViewMixin, view.EntityView): |
212 id = 'ewfgraph' |
199 id = 'wfgraph' |
213 content_type = 'image/png' |
200 content_type = 'image/png' |
214 __select__ = implements('CWEType') |
201 __select__ = implements('Workflow') |
215 |
202 |
216 def _generate(self, tmpfile): |
203 def _generate(self, tmpfile): |
217 """display schema information for an entity""" |
204 """display schema information for an entity""" |
218 entity = self.entity(self.row, self.col) |
205 entity = self.entity(self.row, self.col) |
219 visitor = WorkflowVisitor(entity) |
206 visitor = WorkflowVisitor(entity) |