[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Don't make the
query/getResource function depend on the context. This is
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Jul 10 10:30:53 EDT 2004
Log message for revision 26400:
Don't make the query/getResource function depend on the context. This is
done via the global site now. However, we still need to pass in the site
to which the resource belongs, so that we can set the parent of it,
which is important for the absolute URL to work.
-=-
Modified: Zope3/trunk/src/zope/app/publisher/browser/icon.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/icon.py 2004-07-10 13:30:57 UTC (rev 26399)
+++ Zope3/trunk/src/zope/app/publisher/browser/icon.py 2004-07-10 14:30:52 UTC (rev 26400)
@@ -13,17 +13,15 @@
##############################################################################
"""Icon support
-
$Id$
"""
-
import os
import re
from zope.app import zapi
from zope.app.component.metaconfigure import handler
from zope.app.publisher.browser import metaconfigure
-from zope.app.traversing.namespace import getResourceInContext
+from zope.app.traversing.namespace import getResource
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.configuration.exceptions import ConfigurationError
from zope.app.component.interface import provideInterface
@@ -41,14 +39,16 @@
self.alt = alt
def __call__(self):
- resource = getResourceInContext(self.context, self.rname, self.request)
+ # The context is important here, since it becomes the parent of the
+ # icon, which is needed to generate the absolute URL.
+ resource = getResource(self.context, self.rname, self.request)
src = resource()
return ('<img src="%s" alt="%s" width="16" height="16" border="0" />'
% (src, self.alt))
def url(self):
- resource = getResourceInContext(self.context, self.rname, self.request)
+ resource = getResource(self.context, self.rname, self.request)
src = resource()
return src
Modified: Zope3/trunk/src/zope/app/traversing/namespace.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/namespace.py 2004-07-10 13:30:57 UTC (rev 26399)
+++ Zope3/trunk/src/zope/app/traversing/namespace.py 2004-07-10 14:30:52 UTC (rev 26400)
@@ -20,6 +20,7 @@
from zope import component
from zope.component.servicenames import Presentation
from zope.exceptions import NotFoundError
+
from zope.app.traversing.interfaces import ITraversable, IPathAdapter
from zope.proxy import removeAllProxies
@@ -151,15 +152,14 @@
return ns, name
-def getResourceInContext(ob, name, request):
- resource = queryResourceInContext(ob, name, request)
+def getResource(site, name, request):
+ resource = queryResource(site, name, request)
if resource is None:
- raise NotFoundError(ob, name)
+ raise NotFoundError(site, name)
return resource
-def queryResourceInContext(ob, name, request, default=None):
- resource_service = component.getService(Presentation, ob)
- resource = resource_service.queryResource(name, request)
+def queryResource(site, name, request, default=None):
+ resource = component.queryResource(name, request)
if resource is None:
return default
@@ -167,12 +167,11 @@
# resource to do this. we will still return the proxied resource.
r = removeAllProxies(resource)
- r.__parent__ = ob
+ r.__parent__ = site
r.__name__ = name
return resource
-
# ---- namespace processors below ----
class SimpleHandler(object):
@@ -341,12 +340,10 @@
class resource(view):
def traverse(self, name, ignored):
- resource = queryResourceInContext(self.context, name, self.request)
- if resource is None:
- raise NotFoundError(self.context, name)
+ # The context is important here, since it becomes the parent of the
+ # resource, which is needed to generate the absolute URL.
+ return getResource(self.context, name, self.request)
- return resource
-
class skin(view):
def traverse(self, name, ignored):
More information about the Zope3-Checkins
mailing list