merge 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 15 Sep 2009 16:02:07 +0200
branch3.5
changeset 3233 7ac07c3a9659
parent 3223 480b003cd31b (current diff)
parent 3229 948e0cb59b1a (diff)
child 3234 e454590f1b80
merge
--- a/devtools/apptest.py	Tue Sep 15 14:13:59 2009 +0200
+++ b/devtools/apptest.py	Tue Sep 15 16:02:07 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]
--- a/devtools/testlib.py	Tue Sep 15 14:13:59 2009 +0200
+++ b/devtools/testlib.py	Tue Sep 15 16:02:07 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)
 
--- a/web/action.py	Tue Sep 15 14:13:59 2009 +0200
+++ b/web/action.py	Tue Sep 15 16:02:07 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/test/unittest_breadcrumbs.py	Tue Sep 15 14:13:59 2009 +0200
+++ b/web/test/unittest_breadcrumbs.py	Tue Sep 15 16:02:07 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'),
-                          '<a href="http://testing.fr/cubicweb/folder/%s" title="">chi&amp;ld</a>' % f1.eid)
+        self.assertEquals(f2.view('breadcrumbs'),
+                          '<a href="http://testing.fr/cubicweb/folder/%s" title="">chi&amp;ld</a>' % f2.eid)
+        childrset = f2.as_rset()
         ibc = self.vreg['components'].select('breadcrumbs', self.request(), rset=childrset)
         self.assertEquals(ibc.render(),
                           """<span id="breadcrumbs" class="pathbar">&#160;&gt;&#160;<a href="http://testing.fr/cubicweb/Folder">folder_plural</a>&#160;&gt;&#160;<a href="http://testing.fr/cubicweb/folder/%s" title="">par&amp;ent</a>&#160;&gt;&#160;
-chi&amp;ld</span>""" % f2.eid)
+chi&amp;ld</span>""" % f1.eid)
--- a/web/test/unittest_views_navigation.py	Tue Sep 15 14:13:59 2009 +0200
+++ b/web/test/unittest_views_navigation.py	Tue Sep 15 16:02:07 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__':
--- a/web/test/unittest_viewselector.py	Tue Sep 15 14:13:59 2009 +0200
+++ b/web/test/unittest_viewselector.py	Tue Sep 15 16:02:07 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),
                                               ],
--- a/web/views/actions.py	Tue Sep 15 14:13:59 2009 +0200
+++ b/web/views/actions.py	Tue Sep 15 16:02:07 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:13:59 2009 +0200
+++ b/web/views/tableview.py	Tue Sep 15 16:02:07 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:13:59 2009 +0200
+++ b/web/views/workflow.py	Tue Sep 15 16:02:07 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 ##################################################