[Zope3-checkins] SVN: Zope3/trunk/ Ok, it's time to bugfix since
the release get much more important ; -)
Roger Ineichen
roger at projekt01.ch
Fri Mar 18 17:48:14 EST 2005
Log message for revision 29569:
Ok, it's time to bugfix since the release get much more important ;-)
Bugfix:
Added missing layer to the continerViews menu items.
Enhance:
Added layer, extra, order, icon, menu and for attributes to the addMenuItem directive.
This makes the addMenuItem useable for not only the AddMenu class in the IDefaultLayer
Moved:
The addMenuItem directive get moved to the menumeta.py where was added from srichters
menu refactoring
Test:
Changed and added more tests
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/container/browser/tests/test_directive.py
U Zope3/trunk/src/zope/app/publisher/browser/menumeta.py
U Zope3/trunk/src/zope/app/publisher/browser/meta.zcml
U Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
U Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-03-18 20:44:41 UTC (rev 29568)
+++ Zope3/trunk/doc/CHANGES.txt 2005-03-18 22:48:09 UTC (rev 29569)
@@ -10,6 +10,11 @@
New features
+ - Change addMenuItem directive. Make use of class and menu attributes.
+ This makes it possible to use the directive for own IAdding menu
+ implementation. The addMenuItem directive supports now also the order
+ layer, extra and icon attributes.
+
- Added the HTTP request recorder, which lets you inspect raw HTTP
requests and responses. It can be used to create functional doctests
without requiring third-party tools such as TCPWatch. See the
@@ -516,6 +521,17 @@
Bug Fixes
+ - Fix: Pagelet directive was inoring the permission. Pagelets which
+ not the right permission are not shwon if calling via the Tales
+ expression "pagelets:". If calling named pagelets directly via the
+ Tales expression "pagelet:" we raise a Unauthorized exception if
+ the permission ins't right.
+
+ - Fix: Register the zmi_actions on the right layer if the layer attribute
+ is used in the containerViews directive
+
+ - Fix: Make use of the layer attribute in the menuItemDirective
+
- Fixed issue #345: Using response.write should not involve unicode
conversion
@@ -623,7 +639,7 @@
Jim Fulton, Fred Drake, Philipp von Weitershausen, Stephan Richter,
Gustavo Niemeyer, Daniel Nouri, Volker Bachschneider, Roger Ineichen,
Shane Hathaway, Bjorn Tillenius, Garrett Smith, Marius Gedminas, Stuart
- Bishop
+ Bishop, Dominik Huber
Note: If you are not listed and contributed, please add yourself. This
note will be deleted before the release.
Modified: Zope3/trunk/src/zope/app/container/browser/tests/test_directive.py
===================================================================
--- Zope3/trunk/src/zope/app/container/browser/tests/test_directive.py 2005-03-18 20:44:41 UTC (rev 29568)
+++ Zope3/trunk/src/zope/app/container/browser/tests/test_directive.py 2005-03-18 22:48:09 UTC (rev 29569)
@@ -182,13 +182,13 @@
>>> context
((('adapter',
(<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
- <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.container.browser.tests.test_directive.ITestLayer>),
<InterfaceClass zope.app.menus.zmi_views>,
u'Contents'),
<function handler>,
('provideAdapter',
(<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
- <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.container.browser.tests.test_directive.ITestLayer>),
<InterfaceClass zope.app.menus.zmi_views>,
u'Contents',
<zope.app.publisher.browser.menumeta.MenuItemFactory object>,
@@ -203,7 +203,7 @@
(None,
<function provideInterface>,
('',
- <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>)),
+ <InterfaceClass zope.app.container.browser.tests.test_directive.ITestLayer>)),
(None,
<function provideInterface>,
('',
@@ -240,13 +240,13 @@
'info')),
(('adapter',
(<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
- <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.container.browser.tests.test_directive.ITestLayer>),
<InterfaceClass zope.app.menus.zmi_actions>,
u'Add'),
<function handler>,
('provideAdapter',
(<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
- <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.container.browser.tests.test_directive.ITestLayer>),
<InterfaceClass zope.app.menus.zmi_actions>,
u'Add',
<zope.app.publisher.browser.menumeta.MenuItemFactory object>,
@@ -261,7 +261,7 @@
(None,
<function provideInterface>,
('',
- <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>)),
+ <InterfaceClass zope.app.container.browser.tests.test_directive.ITestLayer>)),
(None,
<function provideInterface>,
('',
Modified: Zope3/trunk/src/zope/app/publisher/browser/menumeta.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/menumeta.py 2005-03-18 20:44:41 UTC (rev 29568)
+++ Zope3/trunk/src/zope/app/publisher/browser/menumeta.py 2005-03-18 22:48:09 UTC (rev 29569)
@@ -20,6 +20,7 @@
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.security.checker import InterfaceChecker, CheckerPublic
+from zope.app import zapi
from zope.app.component.interface import provideInterface
from zope.app.component.metaconfigure import adapter, proxify
from zope.app.component.metaconfigure import utility
@@ -30,7 +31,12 @@
from zope.app.publisher.interfaces.browser import IBrowserMenuItem
from zope.app.publisher.interfaces.browser import IMenuItemType
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.app.container.interfaces import IAdding
+from zope.app.component.contentdirective import ContentDirective
+from zope.app.publisher.interfaces.browser import AddMenu
+
# Create special modules that contain all menu item types
from types import ModuleType as module
import sys
@@ -100,7 +106,7 @@
permission=None, layer=IDefaultBrowserLayer, extra=None,
order=0):
"""Register a single menu item."""
- return menuItemsDirective(_context, menu, for_).menuItem(
+ return menuItemsDirective(_context, menu, for_, layer).menuItem(
_context, action, title, description, icon, filter,
permission, extra, order)
@@ -110,7 +116,7 @@
permission=None, layer=IDefaultBrowserLayer,
extra=None, order=0):
"""Register a single sub-menu menu item."""
- return menuItemsDirective(_context, menu, for_).subMenuItem(
+ return menuItemsDirective(_context, menu, for_, layer).subMenuItem(
_context, submenu, title, description, action, icon, filter,
permission, extra, order)
@@ -185,3 +191,61 @@
def __call__(self, _context):
# Nothing to do.
pass
+
+
+def addMenuItem(_context, title, description='', menu=None, for_=None,
+ class_=None, factory=None, view=None, icon=None, filter=None,
+ permission=None, layer=IDefaultBrowserLayer, extra=None,
+ order=0):
+ """Create an add menu item for a given class or factory
+
+ As a convenience, a class can be provided, in which case, a
+ factory is automatically defined based on the class. In this
+ case, the factory id is based on the class name.
+
+ """
+
+ if for_ is not None:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = ('', for_)
+ )
+ forname = 'For' + for_.getName()
+ else:
+ for_ = IAdding
+ forname = ''
+
+ if menu is not None:
+ if isinstance(menu, (str, unicode)):
+ menu = zapi.getUtility(IMenuItemType, menu)
+ if menu is None:
+ raise ValueError("Missing menu id '%s'" % menu)
+
+ if class_ is None:
+ if factory is None:
+ raise ValueError("Must specify either class or factory")
+ else:
+ if factory is not None:
+ raise ValueError("Can't specify both class and factory")
+ if permission is None:
+ raise ValueError(
+ "A permission must be specified when a class is used")
+ factory = "BrowserAdd%s__%s.%s" % (
+ forname, class_.__module__, class_.__name__)
+ ContentDirective(_context, class_).factory(
+ _context, id=factory)
+
+ extra = {'factory': factory}
+
+ if view:
+ action = view
+ else:
+ action = factory
+
+ if menu == None:
+ menu = AddMenu
+
+ return menuItemsDirective(_context, menu, for_, layer).menuItem(
+ _context, action, title, description, icon, filter,
+ permission, extra, order)
Modified: Zope3/trunk/src/zope/app/publisher/browser/meta.zcml
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/meta.zcml 2005-03-18 20:44:41 UTC (rev 29568)
+++ Zope3/trunk/src/zope/app/publisher/browser/meta.zcml 2005-03-18 22:48:09 UTC (rev 29569)
@@ -4,6 +4,51 @@
<meta:directives namespace="http://namespaces.zope.org/browser">
+ <!-- browser menus -->
+
+ <meta:directive
+ name="menu"
+ schema=".metadirectives.IMenuDirective"
+ handler=".menumeta.menuDirective"
+ />
+
+ <meta:complexDirective
+ name="menuItems"
+ schema=".metadirectives.IMenuItemsDirective"
+ handler=".menumeta.menuItemsDirective"
+ >
+
+ <meta:subdirective
+ name="menuItem"
+ schema=".metadirectives.IMenuItemSubdirective"
+ />
+
+ <meta:subdirective
+ name="subMenuItem"
+ schema=".metadirectives.ISubMenuItemSubdirective"
+ />
+
+ </meta:complexDirective>
+
+ <meta:directive
+ name="menuItem"
+ schema=".metadirectives.IMenuItemDirective"
+ handler=".menumeta.menuItemDirective"
+ />
+
+ <meta:directive
+ name="subMenuItem"
+ schema=".metadirectives.ISubMenuItemDirective"
+ handler=".menumeta.subMenuItemDirective"
+ />
+
+ <meta:directive
+ name="addMenuItem"
+ schema=".metadirectives.IAddMenuItemDirective"
+ handler=".menumeta.addMenuItem"
+ />
+
+
<!-- browser views -->
<meta:complexDirective
@@ -98,45 +143,6 @@
</meta:complexDirective>
-
- <!-- browser menus -->
-
- <meta:directive
- name="menu"
- schema=".metadirectives.IMenuDirective"
- handler=".menumeta.menuDirective"
- />
-
- <meta:complexDirective
- name="menuItems"
- schema=".metadirectives.IMenuItemsDirective"
- handler=".menumeta.menuItemsDirective"
- >
-
- <meta:subdirective
- name="menuItem"
- schema=".metadirectives.IMenuItemSubdirective"
- />
-
- <meta:subdirective
- name="subMenuItem"
- schema=".metadirectives.ISubMenuItemSubdirective"
- />
-
- </meta:complexDirective>
-
- <meta:directive
- name="menuItem"
- schema=".metadirectives.IMenuItemDirective"
- handler=".menumeta.menuItemDirective"
- />
-
- <meta:directive
- name="subMenuItem"
- schema=".metadirectives.ISubMenuItemDirective"
- handler=".menumeta.subMenuItemDirective"
- />
-
<!-- misc. directives -->
<meta:directive
@@ -163,12 +169,6 @@
handler=".icon.IconDirective"
/>
- <meta:directive
- name="addMenuItem"
- schema=".metadirectives.IAddMenuItemDirective"
- handler=".metaconfigure.addMenuItem"
- />
-
</meta:directives>
</configure>
Modified: Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py 2005-03-18 20:44:41 UTC (rev 29568)
+++ Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py 2005-03-18 22:48:09 UTC (rev 29569)
@@ -17,17 +17,13 @@
"""
from zope.component.interfaces import IDefaultViewName
from zope.configuration.exceptions import ConfigurationError
-from zope.interface import Interface, directlyProvides
+from zope.interface import directlyProvides
from zope.interface.interface import InterfaceClass
from zope.publisher.interfaces.browser import ILayer, ISkin, IDefaultSkin
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app import zapi
from zope.app.component.metaconfigure import handler
-from zope.app.container.interfaces import IAdding
-from zope.app.publisher.browser.menumeta import menuItemDirective
-from zope.app.component.contentdirective import ContentDirective
-from zope.app.publisher.interfaces.browser import AddMenu
# referred to through ZCML
from zope.app.publisher.browser.resourcemeta import resource
@@ -348,40 +344,3 @@
callable = provideInterface,
args = ('', for_)
)
-
-
-def addMenuItem(_context, title, class_=None, factory=None, description='',
- permission=None, filter=None, view=None, layer=IBrowserRequest):
- """Create an add menu item for a given class or factory
-
- As a convenience, a class can be provided, in which case, a
- factory is automatically defined based on the class. In this
- case, the factory id is based on the class name.
-
- """
-
- if class_ is None:
- if factory is None:
- raise ValueError("Must specify either class or factory")
- else:
- if factory is not None:
- raise ValueError("Can't specify both class and factory")
- if permission is None:
- raise ValueError(
- "A permission must be specified when a class is used")
- factory = "BrowserAdd__%s.%s" % (
- class_.__module__, class_.__name__)
- ContentDirective(_context, class_).factory(
- _context,
- id = factory)
-
- extra = {'factory': factory}
-
- if view:
- action = view
- else:
- action = factory
-
- menuItemDirective(_context, AddMenu, IAdding,
- action, title, description, None, filter,
- permission, layer, extra)
Modified: Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2005-03-18 20:44:41 UTC (rev 29568)
+++ Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2005-03-18 22:48:09 UTC (rev 29569)
@@ -524,6 +524,12 @@
class IAddMenuItemDirective(IMenuItem):
"""Define an add-menu item"""
+ for_ = GlobalInterface(
+ title=u"Interface",
+ description=u"The interface the menu items are defined for",
+ required=False
+ )
+
class_ = GlobalObject(
title=u"Class",
description=u"""
@@ -543,6 +549,12 @@
required = False,
)
+ menu = MenuField(
+ title=u"Menu name",
+ description=u"The (name of the) menu the items are defined for",
+ required=False,
+ )
+
#
# misc. directives
#
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py 2005-03-18 20:44:41 UTC (rev 29568)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py 2005-03-18 22:48:09 UTC (rev 29569)
@@ -63,13 +63,24 @@
import re
import pprint
import cStringIO
-from zope.app.publisher.browser.metaconfigure import addMenuItem
+from zope.interface import Interface
+from zope.app.publisher.browser.menumeta import addMenuItem
atre = re.compile(' at [0-9a-fA-Fx]+')
+class IX(Interface):
+ pass
+
class X(object):
pass
+class ILayerStub(Interface):
+ pass
+
+class MenuStub(object):
+ pass
+
+
class Context(object):
actions = ()
info = ''
@@ -200,7 +211,151 @@
<InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>)))
"""
+def test_w_for_factory():
+ """
+ >>> context = Context()
+ >>> addMenuItem(context, for_=IX, factory="x.y.z", title="Add an X",
+ ... permission="zope.ManageContent", description="blah blah",
+ ... filter="context/foo")
+ >>> context
+ ((None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>)),
+ (('adapter',
+ (<InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>,
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>,
+ 'Add an X'),
+ <function handler>,
+ ('provideAdapter',
+ (<InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>,
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>,
+ 'Add an X',
+ <zope.app.publisher.browser.menumeta.MenuItemFactory object>,
+ '')),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>)))
+ """
+def test_w_factory_layer():
+ """
+ >>> context = Context()
+ >>> addMenuItem(context, factory="x.y.z", title="Add an X", layer=ILayerStub,
+ ... permission="zope.ManageContent", description="blah blah",
+ ... filter="context/foo")
+ >>> context
+ ((('adapter',
+ (<InterfaceClass zope.app.container.interfaces.IAdding>,
+ <InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.ILayerStub>),
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>,
+ 'Add an X'),
+ <function handler>,
+ ('provideAdapter',
+ (<InterfaceClass zope.app.container.interfaces.IAdding>,
+ <InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.ILayerStub>),
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>,
+ 'Add an X',
+ <zope.app.publisher.browser.menumeta.MenuItemFactory object>,
+ '')),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.container.interfaces.IAdding>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.ILayerStub>)))
+ """
+
+def test_w_for_menu_factory():
+ """
+ >>> context = Context()
+ >>> addMenuItem(context, for_=IX, menu=MenuStub, factory="x.y.z", title="Add an X",
+ ... permission="zope.ManageContent", description="blah blah",
+ ... filter="context/foo")
+ >>> context
+ ((None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>)),
+ (('adapter',
+ (<InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>,
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <class 'zope.app.publisher.browser.tests.test_addMenuItem.MenuStub'>,
+ 'Add an X'),
+ <function handler>,
+ ('provideAdapter',
+ (<InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>,
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <class 'zope.app.publisher.browser.tests.test_addMenuItem.MenuStub'>,
+ 'Add an X',
+ <zope.app.publisher.browser.menumeta.MenuItemFactory object>,
+ '')),
+ (None,
+ <function provideInterface>,
+ ('',
+ <class 'zope.app.publisher.browser.tests.test_addMenuItem.MenuStub'>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.browser.tests.test_addMenuItem.IX>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>)))
+ """
+
+def test_w_factory_icon_extra_order():
+ """
+ >>> context = Context()
+ >>> addMenuItem(context, factory="x.y.z", title="Add an X",
+ ... permission="zope.ManageContent", description="blah blah",
+ ... filter="context/foo", icon=u'/@@/icon.png', extra='Extra',
+ ... order=99)
+ >>> context
+ ((('adapter',
+ (<InterfaceClass zope.app.container.interfaces.IAdding>,
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>,
+ 'Add an X'),
+ <function handler>,
+ ('provideAdapter',
+ (<InterfaceClass zope.app.container.interfaces.IAdding>,
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>),
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>,
+ 'Add an X',
+ <zope.app.publisher.browser.menumeta.MenuItemFactory object>,
+ '')),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.publisher.interfaces.browser.AddMenu>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.app.container.interfaces.IAdding>)),
+ (None,
+ <function provideInterface>,
+ ('',
+ <InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>)))
+ """
+
def test_suite():
return unittest.TestSuite((
DocTestSuite(),
More information about the Zope3-Checkins
mailing list