[Zope3-checkins] SVN: Zope3/trunk/ Implemented issue 306 as
suggested.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Feb 28 12:47:10 EST 2005
Log message for revision 29346:
Implemented issue 306 as suggested.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/doc/TODO.txt
U Zope3/trunk/src/zope/app/form/browser/metaconfigure.py
U Zope3/trunk/src/zope/app/publisher/browser/menu.py
U Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/menus.zcml
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_menudirectives.py
U Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/doc/CHANGES.txt 2005-02-28 17:47:10 UTC (rev 29346)
@@ -10,6 +10,11 @@
New features
+ - Implemented issue 306: page/view-menu-layer configuration
+
+ Added a layer argument to the menu directives and made sure that all
+ browser directives specify the layer for the menu directives.
+
- Implemented issue 292: Add factory to browser:resource directive
- Implemented issue 309: <schemadisplay> should support <widget>
Modified: Zope3/trunk/doc/TODO.txt
===================================================================
--- Zope3/trunk/doc/TODO.txt 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/doc/TODO.txt 2005-02-28 17:47:10 UTC (rev 29346)
@@ -68,8 +68,6 @@
* 298: Role/permission title and description should be messageids
-* 306: page/view-menu-layer configuration
-
* 307: browser:addMenuItem and broken view references
* 313: importchecker.py ignores assignment to module attributes
Modified: Zope3/trunk/src/zope/app/form/browser/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/metaconfigure.py 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/src/zope/app/form/browser/metaconfigure.py 2005-02-28 17:47:10 UTC (rev 29346)
@@ -197,7 +197,7 @@
# for=self.schema.
menuItemDirective(
self._context, self.menu, self.for_, '@@' + self.name,
- self.title, permission=self.permission,
+ self.title, permission=self.permission, layer=self.layer,
description=self.description)
def _handle_arguments(self, leftover=None):
@@ -288,7 +288,8 @@
if self.menu:
menuItemDirective(
self._context, self.menu, self.for_ or self.schema,
- '@@' + self.name, self.title, permission=self.permission)
+ '@@' + self.name, self.title, permission=self.permission,
+ layer=self.layer)
def __call__(self):
self._processWidgets()
Modified: Zope3/trunk/src/zope/app/publisher/browser/menu.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/menu.py 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/src/zope/app/publisher/browser/menu.py 2005-02-28 17:47:10 UTC (rev 29346)
@@ -248,7 +248,8 @@
def menuItemDirective(_context, menu, for_,
action, title, description=u'', icon=None, filter=None,
- permission=None, extra=None, order=0):
+ permission=None, layer=IBrowserRequest, extra=None,
+ order=0):
"""Register a single menu item."""
return menuItemsDirective(_context, menu, for_).menuItem(
_context, action, title, description, icon, filter,
@@ -257,7 +258,8 @@
def subMenuItemDirective(_context, menu, for_, title, submenu,
action=u'', description=u'', icon=None, filter=None,
- permission=None, extra=None, order=0):
+ permission=None, layer=IBrowserRequest, extra=None,
+ order=0):
"""Register a single sub-menu menu item."""
return menuItemsDirective(_context, menu, for_).subMenuItem(
_context, submenu, title, description, action, icon, filter,
@@ -289,9 +291,10 @@
class menuItemsDirective(object):
"""Register several menu items for a particular menu."""
- def __init__(self, _context, menu, for_):
+ def __init__(self, _context, menu, for_, layer=IBrowserRequest):
self.for_ = for_
self.menuItemType = menu
+ self.layer = layer
def menuItem(self, _context, action, title, description=u'',
icon=None, filter=None, permission=None, extra=None, order=0):
@@ -309,7 +312,7 @@
filter=filter, permission=permission, extra=extra, order=order,
_for=self.for_)
adapter(_context, (factory,), self.menuItemType,
- (self.for_, IBrowserRequest), name=title)
+ (self.for_, self.layer), name=title)
def subMenuItem(self, _context, submenu, title, description=u'',
action=u'', icon=None, filter=None, permission=None,
@@ -328,7 +331,7 @@
filter=filter, permission=permission, extra=extra, order=order,
_for=self.for_, submenuType=submenu)
adapter(_context, (factory,), self.menuItemType,
- (self.for_, IBrowserRequest), name=title)
+ (self.for_, self.layer), name=title)
def __call__(self, _context):
# Nothing to do.
Modified: Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2005-02-28 17:47:10 UTC (rev 29346)
@@ -412,6 +412,12 @@
required=False
)
+ layer = LayerField(
+ title=u"Layer",
+ description=u"The Layer for which the item is declared.",
+ required=False
+ )
+
class IMenuItem(Interface):
"""Common menu item configuration
"""
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/menus.zcml
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/menus.zcml 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/menus.zcml 2005-02-28 17:47:10 UTC (rev 29346)
@@ -9,7 +9,7 @@
<browser:menu
id="test_sub_id"
- title="test sub menu" />
+ title="test sub menu 2" />
<browser:menuItems
menu="test_id"
@@ -52,4 +52,12 @@
<browser:menuItem action="a10" title="t10" />
</browser:menuItems>
+ <browser:menuItems
+ menu="test_id"
+ for=".tests.test_menudirectives.I111"
+ layer=".tests.test_menudirectives.IMyLayer">
+ <browser:menuItem action="a11" title="t11" />
+ <browser:subMenuItem submenu="test_sub_id" title="s2" />
+ </browser:menuItems>
+
</configure>
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_menudirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_menudirectives.py 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_menudirectives.py 2005-02-28 17:47:10 UTC (rev 29346)
@@ -58,6 +58,8 @@
raise Unauthorized, name
return self.f
+class IMyLayer(Interface):
+ pass
class Test(PlacelessSetup, unittest.TestCase):
@@ -65,7 +67,7 @@
super(Test, self).setUp()
XMLConfig('meta.zcml', zope.app.publisher.browser)()
- def test(self):
+ def testMenusAndMenuItems(self):
XMLConfig('tests/menus.zcml', zope.app.publisher.browser)()
from zope.app.menus import test_id
@@ -104,7 +106,19 @@
self.assertEqual(first, d(5))
+ def testMenuItemWithLayer(self):
+ XMLConfig('tests/menus.zcml', zope.app.publisher.browser)()
+ from zope.app.menus import test_id
+
+ menu = zope.app.publisher.browser.menu.getMenu(
+ test_id, TestObject(), TestRequest())
+ self.assertEqual(len(menu), 6)
+ menu = zope.app.publisher.browser.menu.getMenu(
+ test_id, TestObject(), TestRequest(skin=IMyLayer))
+ self.assertEqual(len(menu), 8)
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test),
Modified: Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py 2005-02-28 17:46:05 UTC (rev 29345)
+++ Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py 2005-02-28 17:47:10 UTC (rev 29346)
@@ -372,9 +372,6 @@
"Menus can be specified only for single-view, not for "
"multi-views.")
- # TODO: menuItemDirective does not handle layers.
- # IMO this fix is just a work around and menu should
- # support layers too.
registeredTitles = _registeredMenus.setdefault(menu, {})
registered = registeredTitles.setdefault(title, [])
@@ -382,7 +379,7 @@
registered.append(for_[0])
return menuItemDirective(
_context, menu, for_[0], '@@' + name, title,
- permission=permission)
+ permission=permission, layer=layer)
return []
More information about the Zope3-Checkins
mailing list