fix workflow graph views and tabs for the new wf system, remove useless view and action (actually useless since introduction of tabbed entity type view
--- a/web/views/schema.py Mon Sep 14 18:25:43 2009 +0200
+++ b/web/views/schema.py Mon Sep 14 18:28:01 2009 +0200
@@ -12,7 +12,8 @@
from logilab.mtconverter import xml_escape
from yams import BASE_TYPES, schema2dot as s2d
-from cubicweb.selectors import implements, yes, match_user_groups
+from cubicweb.selectors import (implements, yes, match_user_groups,
+ has_related_entities)
from cubicweb.schema import META_RTYPES, SCHEMA_TYPES
from cubicweb.schemaviewer import SchemaViewer
from cubicweb.view import EntityView, StartupView
@@ -269,6 +270,7 @@
xml_escape(url),
xml_escape(self.req._('graphical schema for %s') % entity.name)))
+
class CWETypeSPermView(EntityView):
id = 'cwetype-schema-permissions'
__select__ = EntityView.__select__ & implements('CWEType')
@@ -296,18 +298,28 @@
{'x': entity.eid})
self.wview('outofcontext', rset, 'null')
+
class CWETypeSWorkflowView(EntityView):
id = 'cwetype-workflow'
- __select__ = EntityView.__select__ & implements('CWEType')
+ __select__ = (EntityView.__select__ & implements('CWEType') &
+ has_related_entities('workflow_of', 'object'))
def cell_call(self, row, col):
entity = self.entity(row, col)
- if entity.reverse_state_of:
- 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)))
- else:
- self.w(u'<p>%s</p>' % _('There is no workflow defined for this entity.'))
+ if entity.default_workflow:
+ wf = entity.default_workflow[0]
+ self.w(u'<h1>%s (%s)</h1>' % (wf.name, self.req._('default')))
+ self.wf_image(wf)
+ for altwf in entity.reverse_workflow_of:
+ if altwf.eid == wf.eid:
+ continue
+ self.w(u'<h1>%s</h1>' % altwf.name)
+ self.wf_image(altwf)
+
+ def wf_image(self, wf):
+ self.w(u'<img src="%s" alt="%s"/>' % (
+ xml_escape(wf.absolute_url(vid='wfgraph')),
+ xml_escape(self.req._('graphical representation of %s') % wf.name)))
# CWRType ######################################################################
--- a/web/views/workflow.py Mon Sep 14 18:25:43 2009 +0200
+++ b/web/views/workflow.py Mon Sep 14 18:28:01 2009 +0200
@@ -19,9 +19,10 @@
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 #########################################################
@@ -129,32 +130,18 @@
row=row, col=col)))
-# workflow images #############################################################
-
-class ViewWorkflowAction(action.Action):
+class WorkflowPrimaryView(primary.PrimaryView):
id = 'workflow'
- __select__ = implements('CWEType') & has_related_entities('workflow_of', 'object')
+ __select__ = implements('Workflow')
+ cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
- 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(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.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):
@@ -208,10 +195,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"""