# HG changeset patch # User Sylvain Thénault # Date 1253023397 -7200 # Node ID e454590f1b80eec81133a5f291a815f166114703 # Parent 7ac07c3a965990f2b0fd740e42615e5ba4c3fc08# Parent eccb7380dc3b28422d0329d19985c7636fc1ae54 remerge diff -r eccb7380dc3b -r e454590f1b80 devtools/apptest.py --- a/devtools/apptest.py Tue Sep 15 16:02:17 2009 +0200 +++ b/devtools/apptest.py Tue Sep 15 16:03:17 2009 +0200 @@ -230,6 +230,23 @@ return [(a.id, a.__class__) for a in self.vreg['actions'].possible_vobjects(req, rset=rset) if a.category not in skipcategories] + def action_submenu(self, req, rset, id): + return self._test_action(self.vreg['actions'].select(id, req, rset=rset)) + + def _test_action(self, action): + class fake_menu(list): + @property + def items(self): + return self + class fake_box(object): + def mk_action(self, label, url, **kwargs): + return (label, url) + def box_action(self, action, **kwargs): + return (action.title, action.url()) + submenu = fake_menu() + action.fill_menu(fake_box(), submenu) + return submenu + def pactions_by_cats(self, req, rset, categories=('addrelated',)): return [(a.id, a.__class__) for a in self.vreg['actions'].possible_vobjects(req, rset=rset) if a.category in categories] diff -r eccb7380dc3b -r e454590f1b80 devtools/testlib.py --- a/devtools/testlib.py Tue Sep 15 16:02:17 2009 +0200 +++ b/devtools/testlib.py Tue Sep 15 16:03:17 2009 +0200 @@ -333,7 +333,7 @@ # resultset's syntax tree rset = backup_rset for action in self.list_actions_for(rset): - yield InnerTest(self._testname(rset, action.id, 'action'), action.url) + yield InnerTest(self._testname(rset, action.id, 'action'), self._test_action, action) for box in self.list_boxes_for(rset): yield InnerTest(self._testname(rset, box.id, 'box'), box.render) diff -r eccb7380dc3b -r e454590f1b80 web/action.py --- a/web/action.py Tue Sep 15 16:02:17 2009 +0200 +++ b/web/action.py Tue Sep 15 16:03:17 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 eccb7380dc3b -r e454590f1b80 web/test/unittest_breadcrumbs.py --- a/web/test/unittest_breadcrumbs.py Tue Sep 15 16:02:17 2009 +0200 +++ b/web/test/unittest_breadcrumbs.py Tue Sep 15 16:03:17 2009 +0200 @@ -8,10 +8,10 @@ self.execute('SET F2 filed_under F1 WHERE F1 eid %(f1)s, F2 eid %(f2)s', {'f1' : f1.eid, 'f2' : f2.eid}) self.commit() - childrset = self.execute('Folder F WHERE F eid %s' % f2.eid) - self.assertEquals(childrset.get_entity(0,0).view('breadcrumbs'), - 'chi&ld' % f1.eid) + self.assertEquals(f2.view('breadcrumbs'), + 'chi&ld' % f2.eid) + childrset = f2.as_rset() ibc = self.vreg['components'].select('breadcrumbs', self.request(), rset=childrset) self.assertEquals(ibc.render(), """ > folder_plural > par&ent >  -chi&ld""" % f2.eid) +chi&ld""" % f1.eid) diff -r eccb7380dc3b -r e454590f1b80 web/test/unittest_views_navigation.py --- a/web/test/unittest_views_navigation.py Tue Sep 15 16:02:17 2009 +0200 +++ b/web/test/unittest_views_navigation.py Tue Sep 15 16:03:17 2009 +0200 @@ -95,37 +95,37 @@ html = navcomp.render() - -class ContentNavigationTC(EnvBasedTC): +# XXX deactivate, contextual component has been removed +# class ContentNavigationTC(EnvBasedTC): - def test_component_context(self): - view = mock_object(is_primary=lambda x: True) - rset = self.execute('CWUser X LIMIT 1') - req = self.request() - objs = self.vreg['contentnavigation'].possible_vobjects( - req, rset=rset, view=view, context='navtop') - # breadcrumbs should be in headers by default - clsids = set(obj.id for obj in objs) - self.failUnless('breadcrumbs' in clsids) - objs = self.vreg['contentnavigation'].possible_vobjects( - req, rset=rset, view=view, context='navbottom') - # breadcrumbs should _NOT_ be in footers by default - clsids = set(obj.id for obj in objs) - self.failIf('breadcrumbs' in clsids) - self.execute('INSERT CWProperty P: P pkey "contentnavigation.breadcrumbs.context", ' - 'P value "navbottom"') - # breadcrumbs should now be in footers - req.cnx.commit() - objs = self.vreg['contentnavigation'].possible_vobjects( - req, rset=rset, view=view, context='navbottom') +# def test_component_context(self): +# view = mock_object(is_primary=lambda x: True) +# rset = self.execute('CWUser X LIMIT 1') +# req = self.request() +# objs = self.vreg['contentnavigation'].possible_vobjects( +# req, rset=rset, view=view, context='navtop') +# # breadcrumbs should be in headers by default +# clsids = set(obj.id for obj in objs) +# self.failUnless('breadcrumbs' in clsids) +# objs = self.vreg['contentnavigation'].possible_vobjects( +# req, rset=rset, view=view, context='navbottom') +# # breadcrumbs should _NOT_ be in footers by default +# clsids = set(obj.id for obj in objs) +# self.failIf('breadcrumbs' in clsids) +# self.execute('INSERT CWProperty P: P pkey "contentnavigation.breadcrumbs.context", ' +# 'P value "navbottom"') +# # breadcrumbs should now be in footers +# req.cnx.commit() +# objs = self.vreg['contentnavigation'].possible_vobjects( +# req, rset=rset, view=view, context='navbottom') - clsids = [obj.id for obj in objs] - self.failUnless('breadcrumbs' in clsids) - objs = self.vreg['contentnavigation'].possible_vobjects( - req, rset=rset, view=view, context='navtop') +# clsids = [obj.id for obj in objs] +# self.failUnless('breadcrumbs' in clsids) +# objs = self.vreg['contentnavigation'].possible_vobjects( +# req, rset=rset, view=view, context='navtop') - clsids = [obj.id for obj in objs] - self.failIf('breadcrumbs' in clsids) +# clsids = [obj.id for obj in objs] +# self.failIf('breadcrumbs' in clsids) if __name__ == '__main__': diff -r eccb7380dc3b -r e454590f1b80 web/test/unittest_viewselector.py --- a/web/test/unittest_viewselector.py Tue Sep 15 16:02:17 2009 +0200 +++ b/web/test/unittest_viewselector.py Tue Sep 15 16:03:17 2009 +0200 @@ -17,6 +17,8 @@ treeview, idownloadable, wdoc, debug, cwproperties, workflow, xmlrss, csvexport) +from cubes.folder import views as folderviews + USERACTIONS = [('myprefs', actions.UserPreferencesAction), ('myinfos', actions.UserInfoAction), ('logout', actions.LogoutAction)] @@ -76,7 +78,9 @@ ('propertiesform', cwproperties.CWPropertiesForm), ('registry', startup.RegistryView), ('schema', schema.SchemaView), - ('systempropertiesform', cwproperties.SystemCWPropertiesForm)]) + ('systempropertiesform', cwproperties.SystemCWPropertiesForm), + ('tree', folderviews.FolderTreeView), + ]) def test_possible_views_noresult(self): rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999') @@ -254,9 +258,9 @@ self.assertDictEqual(self.pactions(req, rset), {'useractions': USERACTIONS, 'siteactions': SITEACTIONS, - 'mainactions': [('edit', actions.ModifyAction), - ('workflow', workflow.ViewWorkflowAction),], + 'mainactions': [('edit', actions.ModifyAction)], 'moreactions': [('managepermission', actions.ManagePermissionsAction), + ('addrelated', actions.AddRelatedActions), ('delete', actions.DeleteAction), ('copy', actions.CopyAction), ], @@ -445,6 +449,7 @@ 'siteactions': SITEACTIONS, 'mainactions': [('edit', actions.ModifyAction)], 'moreactions': [('managepermission', actions.ManagePermissionsAction), + ('addrelated', actions.AddRelatedActions), ('delete', actions.DeleteAction), ('copy', actions.CopyAction), ('testaction', CWETypeRQLAction), @@ -456,6 +461,7 @@ 'siteactions': SITEACTIONS, 'mainactions': [('edit', actions.ModifyAction)], 'moreactions': [('managepermission', actions.ManagePermissionsAction), + ('addrelated', actions.AddRelatedActions), ('delete', actions.DeleteAction), ('copy', actions.CopyAction), ], diff -r eccb7380dc3b -r e454590f1b80 web/views/actions.py --- a/web/views/actions.py Tue Sep 15 16:02:17 2009 +0200 +++ b/web/views/actions.py Tue Sep 15 16:03:17 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 eccb7380dc3b -r e454590f1b80 web/views/tableview.py --- a/web/views/tableview.py Tue Sep 15 16:02:17 2009 +0200 +++ b/web/views/tableview.py Tue Sep 15 16:03:17 2009 +0200 @@ -144,8 +144,11 @@ actions += self.show_hide_actions(divid, True) self.w(u'
') # close
') # close