# HG changeset patch # User Sylvain Thénault # Date 1253018970 -7200 # Node ID 7b05b2709439ac3e580c5d604ae13027cffc58e6 # Parent f1695b2da6c36078ffe8eed4198762fc7b5bd0f0 [actions] refactor: extract actual_actions from fill_menu to work with table filter form diff -r f1695b2da6c3 -r 7b05b2709439 web/action.py --- 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 diff -r f1695b2da6c3 -r 7b05b2709439 web/views/actions.py --- 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 diff -r f1695b2da6c3 -r 7b05b2709439 web/views/tableview.py --- 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'
') # close
') # close