[Zope3-checkins] CVS: Zope3/src/zope/app/services - menu.py:1.1.2.3
menu.pyc:1.1.2.3 menu.zcml:1.1.2.2 servicenames.py:1.9.12.1
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Aug 15 09:44:19 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv31241/services
Modified Files:
Tag: dreamcatcher-ttwschema-branch
menu.py menu.pyc menu.zcml servicenames.py
Log Message:
Finished Local Browser Menus:
- Interfaces are complete and documented.
- Implementation complete.
- Tests for testing the implementation of the local browser menu service.
(I am almost amozed about the type of bugs found during these tests.)
=== Zope3/src/zope/app/services/menu.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/app/services/menu.py:1.1.2.2 Thu Aug 14 18:46:35 2003
+++ Zope3/src/zope/app/services/menu.py Fri Aug 15 08:43:42 2003
@@ -17,15 +17,18 @@
"""
from persistence import Persistent
from zope.app import zapi
-from zope.app.component.nextservice import queryNextService
+from zope.app.component.nextservice import getNextService
from zope.app.container.ordered import OrderedContainer
-from zope.app.interfaces.services.menu import ILocalBrowserMenu
-from zope.app.interfaces.publisher.browser import IBrowserMenuItem
+from zope.app.interfaces.services.menu import \
+ ILocalBrowserMenu, ILocalBrowserMenuService
+from zope.app.interfaces.publisher.browser import \
+ IBrowserMenuItem, IGlobalBrowserMenuService
from zope.app.interfaces.services.service import ISimpleService
from zope.app.publisher.browser.globalbrowsermenuservice import \
Menu, BaseBrowserMenuService
-from zope.app.services.servicenames import Utilities
+from zope.app.services.servicenames import Utilities, BrowserMenu
from zope.interface import implements
+from zope.component.exceptions import ComponentLookupError
from zope.context import ContextMethod
from zope.interface import providedBy
from zope.security.proxy import trustedRemoveSecurityProxy
@@ -36,22 +39,22 @@
implements(IBrowserMenuItem)
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenuItem
interface = None
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenuItem
action = u''
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenuItem
title = u''
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenuItem
description = u''
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenuItem
permission = None
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenuItem
filter_string = u''
@@ -60,16 +63,16 @@
implements(ILocalBrowserMenu)
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenu
title = u''
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenu
description = u''
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenu
usage = u''
- # See zope.app.interfaces.publisher.browser.IMenuItem
+ # See zope.app.interfaces.publisher.browser.IBrowserMenu
inherit = True
def __init__(self):
@@ -77,9 +80,9 @@
self._next = 0
def getMenuItems(self, object=None):
- """See zope.app.interfaces.publisher.browser.IMenuItem"""
+ """See zope.app.interfaces.publisher.browser.IBrowserMenu"""
result = []
- interfaces = providedBy(object).flattened()
+ interfaces = list(providedBy(object).flattened())
for menuitem in self.values():
if menuitem.interface in interfaces or object is None:
result.append(
@@ -91,8 +94,8 @@
return result
-
def setObject(self, key, object):
+ """See zope.app.interfaces.container.Container"""
self._next += 1
key = str(self._next)
while key in self:
@@ -102,28 +105,35 @@
return key
-class BrowserMenuService(BaseBrowserMenuService, Persistent):
+class LocalBrowserMenuService(BaseBrowserMenuService, Persistent):
"""This implementation strongly depends on the semantics of
GlobalBrowserMenuService."""
- implements(ISimpleService)
+ implements(ILocalBrowserMenuService, ISimpleService)
def __init__(self):
- super(BrowserMenuService, self).__init__()
+ super(LocalBrowserMenuService, self).__init__()
+
def getAllLocalMenus(self):
+ """See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
utilities = zapi.getService(self, Utilities)
matching = utilities.getRegisteredMatching(ILocalBrowserMenu)
- return matching
+ return map(lambda m: m[2].active().getComponent(), matching)
+ getAllLocalMenus = ContextMethod(getAllLocalMenus)
+
def getLocalMenu(self, menu_id):
+ """See zope.app.interfaces.services.menu.ILocalBrowserMenuService"""
menu = self.queryLocalMenu(menu_id)
if menu is None:
raise ComponentLookupError(menu_id)
return menu
getLocalMenu = ContextMethod(getLocalMenu)
+
def queryLocalMenu(self, menu_id, default=None):
+ """See zope.app.interfaces.services.menu.ILocalBrowserMenuService"""
utilities = zapi.getService(self, Utilities)
matching = utilities.getRegisteredMatching(ILocalBrowserMenu, menu_id)
if matching and matching[0][2].active():
@@ -131,35 +141,68 @@
return default
queryLocalMenu = ContextMethod(queryLocalMenu)
+
+ def getInheritedMenu(self, menu_id, canBeLocal=False):
+ """See zope.app.interfaces.services.menu.ILocalBrowserMenuService"""
+ menu = self.queryInheritedMenu(menu_id, canBeLocal)
+ if menu is None:
+ raise ComponentLookupError(menu_id)
+ return menu
+ getInheritedMenu = ContextMethod(getInheritedMenu)
+
+
+ def queryInheritedMenu(self, menu_id, canBeLocal=False, default=None):
+ """See zope.app.interfaces.services.menu.ILocalBrowserMenuService"""
+ if canBeLocal and self.queryLocalMenu(menu_id):
+ return self.queryLocalMenu(menu_id)
+ # Another service (global) should always be available
+ next = getNextService(self, BrowserMenu)
+
+ # Check whether we deal with a Global Menu Service
+ if IGlobalBrowserMenuService.isImplementedBy(next):
+ return next._registry.get(menu_id, default)
+
+ return next.queryInheritedMenu(menu_id, True, default)
+ queryInheritedMenu = ContextMethod(queryInheritedMenu)
+
+
def getAllMenuItems(self, menu_id, object):
- """Get the menu entries of the local menu and all the ones higher up
- the tree."""
+ """See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
result = []
# Find the local items, if available
menu = self.queryLocalMenu(menu_id)
if menu is not None:
- result += menu.getMenuItems()
+ result += menu.getMenuItems(object)
# We might not want to inherit menu entries from higher up
if not menu.inherit:
return result
# Try to find the next service and get its items. The next service is
# also responsible for finding items higher up.
- next = queryNextService(self, "BrowserMenu")
- if next is not None:
- result += next.getAllMenuItems(menu_id, object)
+ next = getNextService(self, BrowserMenu)
+ result += next.getAllMenuItems(menu_id, object)
return tuple(result)
getAllMenuItems = ContextMethod(getAllMenuItems)
def getMenu(self, menu_id, object, request, max=999999):
- return super(BrowserMenuService,
+ """See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
+ return super(LocalBrowserMenuService,
self).getMenu(menu_id, object, request, max)
getMenu = ContextMethod(getMenu)
+
def getFirstMenuItem(self, menu_id, object, request):
- return super(BrowserMenuService,
+ """See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
+ return super(LocalBrowserMenuService,
self).getFirstMenuItem(menu_id, object, request)
getFirstMenuItem = ContextMethod(getFirstMenuItem)
+
+
+ def getMenuUsage(self, menu_id):
+ """See zope.app.interfaces.publisher.browser.IBrowserMenuService"""
+ return self.getInheritedMenu(menu_id, True).usage
+ getMenuUsage = ContextMethod(getMenuUsage)
+
=== Zope3/src/zope/app/services/menu.pyc 1.1.2.2 => 1.1.2.3 ===
=== Zope3/src/zope/app/services/menu.zcml 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/services/menu.zcml:1.1.2.1 Thu Aug 14 13:58:08 2003
+++ Zope3/src/zope/app/services/menu.zcml Fri Aug 15 08:43:42 2003
@@ -2,18 +2,17 @@
xmlns="http://namespaces.zope.org/zope">
<!-- Browser Menu Service -->
- <content class="zope.app.services.menu.BrowserMenuService">
+ <content class="zope.app.services.menu.LocalBrowserMenuService">
<factory
- id="zope.app.services.MenuService"
+ id="LocalBrowserMenuService"
permission="zope.ManageServices"
title="Browser Menu Service"
description="A Persistent Browser Menu Service" />
- />
+
<require
permission="zope.ManageServices"
interface="zope.app.interfaces.services.registration.IRegistry"
- attributes="menu menuItem"
- />
+ attributes="menu menuItem" />
</content>
<!-- Browser Menu -->
=== Zope3/src/zope/app/services/servicenames.py 1.9 => 1.9.12.1 ===
--- Zope3/src/zope/app/services/servicenames.py:1.9 Tue Jul 8 15:57:56 2003
+++ Zope3/src/zope/app/services/servicenames.py Fri Aug 15 08:43:42 2003
@@ -19,15 +19,16 @@
from zope.component.servicenames import *
-HubIds = 'HubIds'
+Authentication = 'Authentication'
+BrowserMenu = 'BrowserMenu'
+DAVSchema = 'DAVSchema'
EventPublication = 'EventPublication'
EventSubscription = 'Subscription'
ErrorLogging = 'ErrorLogging'
-Roles = 'Roles'
+HubIds = 'HubIds'
Permissions = 'Permissions'
-Authentication = 'Authentication'
-Workflows = 'Workflows'
-Translation = 'Translation'
-DAVSchema = 'DAVSchema'
PrincipalAnnotation = 'PrincipalAnnotation'
+Roles = 'Roles'
SQLDatabaseConnections = 'SQLDatabaseConnections'
+Translation = 'Translation'
+Workflows = 'Workflows'
More information about the Zope3-Checkins
mailing list