[actions] refactor: extract actual_actions from fill_menu to work with table filter form
--- a/web/action.py Tue Sep 15 14:48:13 2009 +0200
+++ b/web/action.py Tue Sep 15 14:49:30 2009 +0200
@@ -37,9 +37,13 @@
# actions in category 'moreactions' can specify a sub-menu in which they should be filed
submenu = None
+ def actual_actions(self):
+ yield self
+
def fill_menu(self, box, menu):
"""add action(s) to the given submenu of the given box"""
- menu.append(box.box_action(self))
+ for action in self.actual_actions():
+ menu.append(box.box_action(action))
def url(self):
"""return the url associated with this action"""
@@ -51,6 +55,9 @@
if self.category:
return 'box' + self.category.capitalize()
+ def build_action(self, title, path, **kwargs):
+ return UnregisteredAction(self.req, self.rset, title, path, **kwargs)
+
class UnregisteredAction(Action):
"""non registered action used to build boxes. Unless you set them
--- a/web/views/actions.py Tue Sep 15 14:48:13 2009 +0200
+++ b/web/views/actions.py Tue Sep 15 14:49:30 2009 +0200
@@ -238,10 +238,10 @@
# when there is only one item in the sub-menu, replace the sub-menu by
# item's title prefixed by 'add'
menu.label_prefix = self.req._('add')
+ super(AddRelatedActions, self).fill_menu(box, menu)
+
+ def actual_actions(self):
entity = self.rset.get_entity(self.row or 0, self.col or 0)
- user = self.req.user
- actions = []
- _ = self.req._
eschema = entity.e_schema
for rschema, teschema, x in self.add_related_schemas(entity):
if x == 'subject':
@@ -250,7 +250,7 @@
else:
label = 'add %s %s %s %s' % (teschema, rschema, eschema, x)
url = self.linkto_url(entity, rschema, teschema, 'subject')
- menu.append(box.mk_action(_(label), url))
+ yield self.build_action(self.req._(label), url)
def add_related_schemas(self, entity):
"""this is actually used ui method to generate 'addrelated' actions from
--- a/web/views/tableview.py Tue Sep 15 14:48:13 2009 +0200
+++ b/web/views/tableview.py Tue Sep 15 14:49:30 2009 +0200
@@ -144,8 +144,11 @@
actions += self.show_hide_actions(divid, True)
self.w(u'<div id="%s"' % divid)
if displayactions:
- for action in self.vreg['actions'].possible_actions(req, self.rset).get('mainactions', ()):
- actions.append( (action.url(), req._(action.title), action.html_class(), None) )
+ actionsbycat = self.vreg['actions'].possible_actions(req, self.rset)
+ for action in actionsbycat.get('mainactions', ()):
+ for action in action.actual_actions():
+ actions.append( (action.url(), req._(action.title),
+ action.html_class(), None) )
self.w(u' cubicweb:displayactions="1">') # close <div tag
else:
self.w(u'>') # close <div tag
--- a/web/views/workflow.py Tue Sep 15 14:48:13 2009 +0200
+++ b/web/views/workflow.py Tue Sep 15 14:49:30 2009 +0200
@@ -123,20 +123,25 @@
order = 10
def fill_menu(self, box, menu):
- req = self.req
entity = self.rset.get_entity(self.row or 0, self.col or 0)
- menu.label = u'%s: %s' % (req._('state'), entity.printable_state)
+ 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)
- menu.append(box.mk_action(req._(tr.name), url))
+ 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 menu.items:
+ if hastr:
wfurl = entity.current_workflow.absolute_url()
- menu.append(box.mk_action(req._('view workflow'), wfurl))
+ yield self.build_action(self.req._('view workflow'), wfurl)
if entity.workflow_history:
wfurl = entity.absolute_url(vid='wfhistory')
- menu.append(box.mk_action(req._('view history'), wfurl))
+ yield self.build_action(self.req._('view history'), wfurl)
# workflow entity types views ##################################################