[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser -
configure.zcml:1.8 globalbrowsermenuservice.py:1.22
icon.py:1.11 metaconfigure.py:1.13 resource.py:1.5
resourcemeta.py:1.12 viewmeta.py:1.31
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Aug 15 21:45:24 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/publisher/browser
In directory cvs.zope.org:/tmp/cvs-serv20171/app/publisher/browser
Modified Files:
configure.zcml globalbrowsermenuservice.py icon.py
metaconfigure.py resource.py resourcemeta.py viewmeta.py
Log Message:
Merging dreamcatcher's TTW Schema branch:
1. Fixed Bug in adding that would cause infinite loops when the menu items
action was not a valif view or factory id.
2. Extended adding to support more complex views. Until now we only
supported constructions like "+/AddView=id". Now you are able to say
"+/AddView/More=id", which means that more information can be carried
in the URL. This can be used in many ways, including multi-page adding
wizards. In my case I needed it to pass in the type of the TTW Schema-
based Content Component.
3. Added Local Menus. This was a pain in the butt, but I think I got a
fairly nice model, where you can create local Menu Services, and Menus
are simply named utilities. When active they are menus in the menu
service. This is very similar to the local interface service and TTW
Schema.
4. Made some modifications to TTW Schema, cleaned up the code and moved
the browser code and interfaces to the places they belong.
5. Added a Content Component Definition utility component, which takes a
Schema and creates a content component for it, including permission
settings and a menu entry. Currently the menu entry is always made to
a local 'add_content' menu. I will change this and make it actually a
screen, where the menu and title of the menu item can be chosen by the
developer. Mmmh, should I add a factory for the definition as well, so
that the content component is also available via python?
6. Added a Content Component Instance component that represents an
instance od a Content Component Definition. You will never directly
encounter this component, since it is automatically used by the adding
code of the Content Component Definition.
7. Cleanups by both dreamcatcher and myself.
That's it. For more details see the branch checkin messages. I now consider
the dreamcatcher-ttwschema-branch closed.
=== Zope3/src/zope/app/publisher/browser/configure.zcml 1.7 => 1.8 ===
--- Zope3/src/zope/app/publisher/browser/configure.zcml:1.7 Fri Aug 15 14:19:09 2003
+++ Zope3/src/zope/app/publisher/browser/configure.zcml Fri Aug 15 20:43:46 2003
@@ -1,12 +1,10 @@
<zopeConfigure
- xmlns='http://namespaces.zope.org/zope'
- xmlns:browser='http://namespaces.zope.org/browser'
->
-
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser">
<serviceType
id="BrowserMenu"
- interface="zope.app.interfaces.publisher.browser.IBrowserMenuService"
+ interface="zope.app.interfaces.publisher.browser.IBrowserMenuService"
/>
<service
@@ -14,7 +12,6 @@
permission="zope.Public"
component=".globalbrowsermenuservice.globalBrowserMenuService"
/>
-
<content class="zope.publisher.browser.BrowserRequest">
<allow
=== Zope3/src/zope/app/publisher/browser/globalbrowsermenuservice.py 1.21 => 1.22 ===
--- Zope3/src/zope/app/publisher/browser/globalbrowsermenuservice.py:1.21 Sat Aug 2 22:13:17 2003
+++ Zope3/src/zope/app/publisher/browser/globalbrowsermenuservice.py Fri Aug 15 20:43:46 2003
@@ -11,7 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+"""Global Browser Menu Service
+$Id$
+"""
from zope.interface import classProvides
from zope.exceptions import DuplicationError, Unauthorized, Forbidden
@@ -26,13 +29,15 @@
from zope.app.security.permission import checkPermission
from zope.app.component.metaconfigure import handler
-from zope.app.interfaces.publisher.browser import IBrowserMenuService
+from zope.app.interfaces.publisher.browser import \
+ IBrowserMenuService, IGlobalBrowserMenuService, IBrowserMenu
from zope.app.pagetemplate.engine import Engine
from zope.app.publication.browser import PublicationTraverser
class Menu(object):
- '''Browser menu
- '''
+ """Browser menu"""
+
+ implements(IBrowserMenu)
def __init__(self, title, description=u'', usage=u''):
self.title = title
@@ -40,16 +45,130 @@
self.usage = usage
self.registry = TypeRegistry()
+ def getMenuItems(self, object=None):
+ """See zope.app.interfaces.publisher.browser.IMenuItem"""
+ results = []
+ if object is None:
+ for items in self.registry._reg.values():
+ results += items
+ else:
+ for items in self.registry.getAllForObject(object):
+ results += items
+ return results
+
-class GlobalBrowserMenuService(object):
- """Global Browser Menu Service
- """
+class BaseBrowserMenuService(object):
+ """Global Browser Menu Service"""
implements(IBrowserMenuService)
def __init__(self):
self._registry = {}
+ def getAllMenuItems(self, menu_id, object):
+ return self._registry[menu_id].getMenuItems(object)
+
+ def getMenu(self, menu_id, object, request, max=999999):
+ traverser = PublicationTraverser()
+
+ result = []
+ seen = {}
+ sm = getSecurityManager()
+
+ # stuff for figuring out the selected view
+ request_url = request.getURL()
+
+ for items in self.getAllMenuItems(menu_id, object):
+ action, title, description, filter, permission = items
+
+ # Make sure we don't repeat a specification for a given title
+ if title in seen:
+ continue
+ seen[title] = 1
+
+ if filter is not None:
+
+ try:
+ include = filter(Engine.getContext(
+ context = object,
+ nothing = None,
+ request = request,
+ ))
+ except Unauthorized:
+ include = 0
+
+ if not include:
+ continue
+
+ if permission:
+ # If we have an explicit permission, check that we
+ # can access it.
+ if not sm.checkPermission(permission, object) and \
+ permission is not CheckerPublic:
+ continue
+
+ elif action:
+ # Otherwise, test access by attempting access
+ path = action
+ l = action.find('?')
+ if l >= 0:
+ path = action[:l]
+ try:
+ v = traverser.traverseRelativeURL(
+ request, object, path)
+ # XXX
+ # tickle the security proxy's checker
+ # we're assuming that view pages are callable
+ # this is a pretty sound assumption
+ v.__call__
+ except (Unauthorized, Forbidden):
+ continue # Skip unauthorized or forbidden
+
+ normalized_action = action
+ if action.startswith('@@'):
+ normalized_action = action[2:]
+
+ if request_url.endswith(action):
+ selected='selected'
+ elif request_url.endswith('/'+normalized_action):
+ selected='selected'
+ elif request_url.endswith('++view++'+normalized_action):
+ selected='selected'
+ else:
+ selected=''
+
+ result.append({
+ 'title': title,
+ 'description': description,
+ 'action': "%s" % action,
+ 'selected': selected
+ })
+
+ if len(result) >= max:
+ return result
+
+ return result
+
+ def getMenuUsage(self, menu_id):
+ return self._registry[menu_id].usage
+
+
+ def getFirstMenuItem(self, menu_id, object, request):
+ r = self.getMenu(menu_id, object, request, max=1)
+ if r:
+ return r[0]
+ return None
+
+
+class GlobalBrowserMenuService(BaseBrowserMenuService):
+ """Global Browser Menu Service that can be manipulated by adding new menus
+ and menu entries."""
+
+ implements(IGlobalBrowserMenuService)
+
+ def __init__(self):
+ self._registry = {}
+
_clear = __init__
def menu(self, menu_id, title, description=u'', usage=u''):
@@ -81,96 +200,6 @@
data.append((action, title, description, filter, permission))
registry.register(interface, data)
- def getMenu(self, menu_id, object, request, max=999999):
- registry = self._registry[menu_id].registry
- traverser = PublicationTraverser()
-
- result = []
- seen = {}
- sm = getSecurityManager()
-
- # stuff for figuring out the selected view
- request_url = request.getURL()
-
- for items in registry.getAllForObject(object):
- for action, title, description, filter, permission in items:
-
- # Make sure we don't repeat a specification for a given title
- if title in seen:
- continue
- seen[title] = 1
-
- if filter is not None:
-
- try:
- include = filter(Engine.getContext(
- context = object,
- nothing = None,
- request = request,
- ))
- except Unauthorized:
- include = 0
-
- if not include:
- continue
-
- if permission:
- # If we have an explicit permission, check that we
- # can access it.
- if not sm.checkPermission(permission, object):
- continue
-
- elif action:
- # Otherwise, test access by attempting access
- path = action
- l = action.find('?')
- if l >= 0:
- path = action[:l]
- try:
- v = traverser.traverseRelativeURL(
- request, object, path)
- # XXX
- # tickle the security proxy's checker
- # we're assuming that view pages are callable
- # this is a pretty sound assumption
- v.__call__
- except (Unauthorized, Forbidden):
- continue # Skip unauthorized or forbidden
-
- normalized_action = action
- if action.startswith('@@'):
- normalized_action = action[2:]
-
- if request_url.endswith(action):
- selected='selected'
- elif request_url.endswith('/'+normalized_action):
- selected='selected'
- elif request_url.endswith('++view++'+normalized_action):
- selected='selected'
- else:
- selected=''
-
- result.append({
- 'title': title,
- 'description': description,
- 'action': "%s" % action,
- 'selected': selected
- })
-
- if len(result) >= max:
- return result
-
- return result
-
- def getMenuUsage(self, menu_id):
- return self._registry[menu_id].usage
-
-
- def getFirstMenuItem(self, menu_id, object, request):
- r = self.getMenu(menu_id, object, request, max=1)
- if r:
- return r[0]
- return None
def menuDirective(_context, id, title, description='', usage=u''):
_context.action(
@@ -207,7 +236,7 @@
discriminator = None,
callable = handler,
args = (Interfaces, 'provideInterface',
- self.interface.__module__+'.'+self.interface.__name__,
+ self.interface.__module__+'.'+self.interface.getName(),
self.interface)
)
@@ -219,8 +248,3 @@
from zope.testing.cleanup import addCleanUp
addCleanUp(_clear)
del addCleanUp
-
-__doc__ = GlobalBrowserMenuService.__doc__ + """
-
-$Id$
-"""
=== Zope3/src/zope/app/publisher/browser/icon.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/publisher/browser/icon.py:1.10 Sat Aug 2 22:13:17 2003
+++ Zope3/src/zope/app/publisher/browser/icon.py Fri Aug 15 20:43:46 2003
@@ -63,7 +63,7 @@
def IconDirective(_context, name, for_, file=None, resource=None,
layer='default', alt=None):
- iname = for_.__name__
+ iname = for_.getName()
if alt is None:
alt = iname
@@ -102,6 +102,6 @@
discriminator = None,
callable = handler,
args = (Interfaces, 'provideInterface',
- for_.__module__+'.'+for_.__name__,
+ for_.__module__+'.'+for_.getName(),
for_)
)
=== Zope3/src/zope/app/publisher/browser/metaconfigure.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/publisher/browser/metaconfigure.py:1.12 Mon Aug 11 10:58:07 2003
+++ Zope3/src/zope/app/publisher/browser/metaconfigure.py Fri Aug 15 20:43:46 2003
@@ -50,6 +50,6 @@
discriminator = None,
callable = handler,
args = (Interfaces, 'provideInterface',
- for_.__module__+'.'+for_.__name__,
+ for_.__module__+'.'+for_.getName(),
for_)
)
=== Zope3/src/zope/app/publisher/browser/resource.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/publisher/browser/resource.py:1.4 Tue May 27 10:18:22 2003
+++ Zope3/src/zope/app/publisher/browser/resource.py Fri Aug 15 20:43:46 2003
@@ -21,6 +21,7 @@
from zope.context import getWrapperContainer, getInnerWrapperData
from zope.context import ContextMethod
from zope.app.traversing import joinPath
+from zope.component.interfaces import IResourceService
class Resource:
@@ -33,6 +34,11 @@
name = name[12:]
service = getWrapperContainer(wrapped_self)
+ while not IResourceService.isImplementedBy(service):
+ name = "%s/%s" % (getInnerWrapperData(service)['name'],
+ name)
+ service = getWrapperContainer(service)
+
site = getWrapperContainer(service)
skin = wrapped_self.request.getPresentationSkin()
=== Zope3/src/zope/app/publisher/browser/resourcemeta.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/publisher/browser/resourcemeta.py:1.11 Mon Aug 11 10:58:07 2003
+++ Zope3/src/zope/app/publisher/browser/resourcemeta.py Fri Aug 15 20:43:46 2003
@@ -65,7 +65,8 @@
if permission == 'zope.Public':
permission = CheckerPublic
- checker = NamesChecker(allowed_names, permission)
+ checker = NamesChecker(allowed_names + ('__getitem__', 'get'),
+ permission)
if not os.path.isdir(directory):
raise ConfigurationError(
=== Zope3/src/zope/app/publisher/browser/viewmeta.py 1.30 => 1.31 ===
--- Zope3/src/zope/app/publisher/browser/viewmeta.py:1.30 Sat Aug 2 22:13:17 2003
+++ Zope3/src/zope/app/publisher/browser/viewmeta.py Fri Aug 15 20:43:46 2003
@@ -391,7 +391,7 @@
discriminator = None,
callable = handler,
args = (Interfaces, 'provideInterface',
- for_.__module__+'.'+for_.__name__, for_)
+ for_.__module__+'.'+for_.getName(), for_)
)
def _handle_menu(_context, menu, title, for_, name, permission):
More information about the Zope3-Checkins
mailing list