[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/configuration - __init__.py:1.11
Guido van Rossum
guido@python.org
Thu, 12 Jun 2003 13:04:14 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/services/configuration
In directory cvs.zope.org:/tmp/cvs-serv25618/browser/services/configuration
Modified Files:
__init__.py
Log Message:
Use/allow relative paths in ComponentConfiguration subclasses.
Existing absolute paths will continue to work, but all newly created
ComponentConfiguration subclass instances will use a path relative to
the site management folder containing the configured object -- i.e.,
this is just the object's name. Fixed all places where I've seen
absolute paths used. (Still to do: use relative paths for references
*to* the configuration object as well; these occur in registries, and
are also used by the IUseConfigurable machinery and by dependencies.)
=== Zope3/src/zope/app/browser/services/configuration/__init__.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/browser/services/configuration/__init__.py:1.10 Fri Jun 6 16:44:28 2003
+++ Zope3/src/zope/app/browser/services/configuration/__init__.py Thu Jun 12 13:03:43 2003
@@ -25,7 +25,7 @@
from zope.app.interfaces.services.configuration import Unregistered
from zope.app.interfaces.services.configuration import IUseConfiguration
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-from zope.app.traversing import getPath, traverse
+from zope.app.traversing import getPath, objectName, traverse
from zope.component import getView, getServiceManager, getAdapter
from zope.context import getWrapperContainer
from zope.app.context import ContextWrapper
@@ -191,7 +191,7 @@
The widget doesn't actually allow editing. Rather it gets the
value by inspecting its field's context. If the context is an
- IComponentConfiguration, then it just gets it's value from the
+ IComponentConfiguration, then it just gets its value from the
component using the field's name. Otherwise, it uses the path to
the context.
"""
@@ -204,13 +204,17 @@
field = self.context
context = field.context
if IComponentConfiguration.isImplementedBy(context):
- # It's a configuration object. Just get the corresponsing attr
+ # It's a configuration object. Just get the corresponding attr
path = getattr(context, field.__name__)
+ # The path may be relative; then interpret relative to ../..
+ if not path.startswith("/"):
+ context = traverse(context, "../..")
component = traverse(context, path)
else:
# It must be a component that is about to be configured.
component = context
- path = getPath(context)
+ # Always use a relative path (just the component name)
+ path = objectName(context)
url = getView(component, 'absolute_url', self.request)
@@ -226,12 +230,13 @@
field = self.context
context = field.context
if IComponentConfiguration.isImplementedBy(context):
- # It's a configuration object. Just get the corresponsing attr
+ # It's a configuration object. Just get the corresponding attr
# XXX this code has no unittests !!!
path = getattr(context, field.__name__)
else:
# It must be a component that is about to be configured.
- path = getPath(context)
+ # Always return a relative path (just the component name)
+ path = objectName(context)
return path