[Checkins] SVN: zope.app.publisher/branches/3.4/ -
<browser:menuItem> can now be registered for classes
(backport from 3.5)
Christian Zagrodnick
cz at gocept.com
Tue Aug 21 07:43:28 EDT 2007
Log message for revision 79072:
- <browser:menuItem> can now be registered for classes (backport from 3.5)
Changed:
U zope.app.publisher/branches/3.4/CHANGES.txt
U zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.py
U zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.txt
U zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/metadirectives.py
U zope.app.publisher/branches/3.4/src/zope/app/publisher/xmlrpc/metaconfigure.py
-=-
Modified: zope.app.publisher/branches/3.4/CHANGES.txt
===================================================================
--- zope.app.publisher/branches/3.4/CHANGES.txt 2007-08-21 11:42:57 UTC (rev 79071)
+++ zope.app.publisher/branches/3.4/CHANGES.txt 2007-08-21 11:43:27 UTC (rev 79072)
@@ -2,9 +2,12 @@
Changes
=======
-After 3.4.0a1
+
+3.4.0b1
=============
+ - <browser:menuItem> can now be registered for classes (backport from 3.5)
+
- Fixed a bug about xmlrpc:view: Omitting a permission was (widely)
documented to be allowed when a name is given and should incorporate the
original security settings of the view class. This did not work at all and
Modified: zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.py
===================================================================
--- zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.py 2007-08-21 11:42:57 UTC (rev 79071)
+++ zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.py 2007-08-21 11:43:27 UTC (rev 79072)
@@ -19,6 +19,7 @@
import sys
import zope.component
+import zope.interface.interfaces
from zope.interface import Interface, implements, providedBy
from zope.security import checkPermission, canAccess
from zope.security.interfaces import Unauthorized, Forbidden
@@ -47,6 +48,7 @@
def getMenuItems(self, object, request):
"""Return menu item entries in a TAL-friendly form."""
+
result = []
for name, item in zope.component.getAdapters((object, request),
self.getMenuItemType()):
@@ -56,15 +58,27 @@
# Now order the result. This is not as easy as it seems.
#
# (1) Look at the interfaces and put the more specific menu entries
- # to the front.
+ # to the front.
# (2) Sort unambigious entries by order and then by title.
ifaces = list(providedBy(removeSecurityProxy(object)).__iro__)
- result = [(ifaces.index(item._for or Interface),
- item.order, item.title, item) for item in result]
+ max_key = len(ifaces)
+ def iface_index(item):
+ iface = item._for
+ if not iface:
+ iface = Interface
+ if zope.interface.interfaces.IInterface.providedBy(iface):
+ return ifaces.index(iface)
+ if isinstance(removeSecurityProxy(object), item._for):
+ # directly specified for class, this goes first.
+ return -1
+ # no idea. This goes last.
+ return max_key
+ result = [(iface_index(item), item.order, item.title, item)
+ for item in result]
result.sort()
result = [
- {'title': item.title,
+ {'title': title,
'description': item.description,
'action': item.action,
'selected': (item.selected() and u'selected') or u'',
Modified: zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.txt
===================================================================
--- zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.txt 2007-08-21 11:42:57 UTC (rev 79071)
+++ zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/menu.txt 2007-08-21 11:43:27 UTC (rev 79072)
@@ -281,6 +281,14 @@
>>> ztapi.provideAdapter((IContent, IBrowserRequest),
... SaveOptions, saveall, 'saveall')
+Note that we can also register menu items for classes:
+
+
+ >>> new = menumeta.MenuItemFactory(menu.BrowserMenuItem, title="New",
+ ... action="new.html", _for=Content)
+ >>> ztapi.provideAdapter((Content, IBrowserRequest), EditMenu, new, 'new')
+
+
The utility that is used to generate the menu into a TAL-friendly
data-structure is ``getMenu()``::
@@ -290,9 +298,16 @@
menu now:
>>> pprint(menu.getMenu('edit', Content(), TestRequest()))
- [{'action': 'redo.html',
+ [{'action': 'new.html',
'description': u'',
'extra': None,
+ 'icon': None,
+ 'selected': u'',
+ 'submenu': None,
+ 'title': 'New'},
+ {'action': 'redo.html',
+ 'description': u'',
+ 'extra': None,
'icon': '/@@/redo.png',
'selected': u'',
'submenu': None,
Modified: zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/metadirectives.py 2007-08-21 11:42:57 UTC (rev 79071)
+++ zope.app.publisher/branches/3.4/src/zope/app/publisher/browser/metadirectives.py 2007-08-21 11:43:27 UTC (rev 79072)
@@ -412,7 +412,7 @@
required=True,
)
- for_ = GlobalInterface(
+ for_ = GlobalObject(
title=u"Interface",
description=u"The interface the menu items are defined for",
required=True
Modified: zope.app.publisher/branches/3.4/src/zope/app/publisher/xmlrpc/metaconfigure.py
===================================================================
--- zope.app.publisher/branches/3.4/src/zope/app/publisher/xmlrpc/metaconfigure.py 2007-08-21 11:42:57 UTC (rev 79071)
+++ zope.app.publisher/branches/3.4/src/zope/app/publisher/xmlrpc/metaconfigure.py 2007-08-21 11:43:27 UTC (rev 79072)
@@ -77,7 +77,8 @@
# of the original class
def proxyView(context, request, class_=class_):
view = class_(context, request)
- view.__Security_checker__ = getCheckerForInstancesOf(original_class)
+ view.__Security_checker__ = getCheckerForInstancesOf(
+ original_class)
return view
class_ = proxyView
class_.factory = original_class
@@ -104,10 +105,10 @@
'__call__': getattr(class_, name)}
new_class = type(class_.__name__, (class_,), cdict)
_context.action(
- discriminator = ('view', for_, name, IXMLRPCRequest),
+ discriminator = ('view', for_, name, layer),
callable = handler,
args = ('registerAdapter',
- new_class, (for_, IXMLRPCRequest), Interface, name,
+ new_class, (for_, layer), Interface, name,
_context.info)
)
More information about the Checkins
mailing list