--- a/web/views/workflow.py Mon Sep 14 11:25:56 2009 +0200
+++ b/web/views/workflow.py Tue Sep 15 15:01:41 2009 +0200
@@ -15,13 +15,14 @@
from logilab.common.graph import escape, GraphGenerator, DotBackend
from cubicweb import Unauthorized, view
-from cubicweb.selectors import (implements, has_related_entities,
+from cubicweb.selectors import (implements, has_related_entities, one_line_rset,
relation_possible, match_form_params)
from cubicweb.interfaces import IWorkflowable
from cubicweb.view import EntityView
-from cubicweb.web import stdmsgs, action, component, form
+from cubicweb.schema import display_name
+from cubicweb.web import stdmsgs, action, component, form, action
from cubicweb.web import formfields as ff, formwidgets as fwdgs
-from cubicweb.web.views import TmpFileViewMixin, forms
+from cubicweb.web.views import TmpFileViewMixin, forms, primary
# IWorkflowable views #########################################################
@@ -109,7 +110,41 @@
def cell_call(self, row, col, view=None):
self.wview('wfhistory', self.rset, row=row, col=col, view=view)
-# workflow entity types views #################################################
+
+# workflow actions #############################################################
+
+class WorkflowActions(action.Action):
+ """fill 'workflow' sub-menu of the actions box"""
+ id = 'workflow'
+ __select__ = (action.Action.__select__ & one_line_rset() &
+ relation_possible('in_state'))
+
+ submenu = _('workflow')
+ order = 10
+
+ def fill_menu(self, box, menu):
+ entity = self.rset.get_entity(self.row or 0, self.col or 0)
+ menu.label = u'%s: %s' % (self.req._('state'), entity.printable_state)
+ menu.append_anyway = True
+ super(WorkflowActions, self).fill_menu(box, menu)
+
+ def actual_actions(self):
+ entity = self.rset.get_entity(self.row or 0, self.col or 0)
+ hastr = False
+ for tr in entity.possible_transitions():
+ url = entity.absolute_url(vid='statuschange', treid=tr.eid)
+ yield self.build_action(self.req._(tr.name), url)
+ hastr = True
+ # don't propose to see wf if user can't pass any transition
+ if hastr:
+ wfurl = entity.current_workflow.absolute_url()
+ yield self.build_action(self.req._('view workflow'), wfurl)
+ if entity.workflow_history:
+ wfurl = entity.absolute_url(vid='wfhistory')
+ yield self.build_action(self.req._('view history'), wfurl)
+
+
+# workflow entity types views ##################################################
class CellView(view.EntityView):
id = 'cell'
@@ -129,32 +164,17 @@
row=row, col=col)))
-# workflow images #############################################################
-
-class ViewWorkflowAction(action.Action):
- id = 'workflow'
- __select__ = implements('CWEType') & has_related_entities('workflow_of', 'object')
+class WorkflowPrimaryView(primary.PrimaryView):
+ __select__ = implements('Workflow')
- category = 'mainactions'
- title = _('view workflow')
- def url(self):
- entity = self.rset.get_entity(self.row or 0, self.col or 0)
- return entity.absolute_url(vid='workflow')
+ def render_entity_attributes(self, entity):
+ self.w(entity.view('reledit', rtype='description'))
+ self.w(u'<img src="%s" alt="%s"/>' % (
+ xml_escape(entity.absolute_url(vid='wfgraph')),
+ xml_escape(self.req._('graphical workflow for %s') % entity.name)))
-class CWETypeWorkflowView(view.EntityView):
- id = 'workflow'
- __select__ = implements('CWEType')
- cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
-
- def cell_call(self, row, col, **kwargs):
- entity = self.rset.get_entity(row, col)
- self.w(u'<h1>%s</h1>' % (self.req._('workflow for %s')
- % display_name(self.req, entity.name)))
- self.w(u'<img src="%s" alt="%s"/>' % (
- xml_escape(entity.absolute_url(vid='ewfgraph')),
- xml_escape(self.req._('graphical workflow for %s') % entity.name)))
-
+# workflow images ##############################################################
class WorkflowDotPropsHandler(object):
def __init__(self, req):
@@ -178,7 +198,9 @@
self._('groups:'),
','.join(g.name for g in tr.require_group)))
if tr.condition:
- descr.append('%s %s'% (self._('condition:'), tr.condition))
+ descr.append('%s %s'% (
+ self._('condition:'),
+ ' | '.join(e.expression for e in tr.condition)))
if descr:
props['label'] += escape('\n'.join(descr))
return props
@@ -208,10 +230,10 @@
yield transition.eid, transition.destination().eid, transition
-class CWETypeWorkflowImageView(TmpFileViewMixin, view.EntityView):
- id = 'ewfgraph'
+class WorkflowImageView(TmpFileViewMixin, view.EntityView):
+ id = 'wfgraph'
content_type = 'image/png'
- __select__ = implements('CWEType')
+ __select__ = implements('Workflow')
def _generate(self, tmpfile):
"""display schema information for an entity"""