[Checkins] SVN: hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py Adjust to changes in hurry.resource. If there is a resource publisher configured, generate the base url accordingly

Jan-Jaap Driessen jdriessen at thehealthagency.com
Sun Nov 14 09:40:49 EST 2010


Log message for revision 118403:
  Adjust to changes in hurry.resource. If there is a resource publisher configured, generate the base url accordingly

Changed:
  U   hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py

-=-
Modified: hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py
===================================================================
--- hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py	2010-11-14 14:39:38 UTC (rev 118402)
+++ hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py	2010-11-14 14:40:48 UTC (rev 118403)
@@ -1,14 +1,12 @@
 # zope integration for hurry.resource
-from zope import component
-from zope.component.hooks import getSite
 import zope.security.management
 from zope.publisher.interfaces import IRequest
-from zope.traversing.browser.interfaces import IAbsoluteURL
+from zope.traversing.browser.absoluteurl import absoluteURL
 from grokcore.component import subscribe
 from zope.publisher.interfaces import IEndRequestEvent
 
 from hurry.resource import NeededInclusions
-from hurry.resource.wsgi import KEY
+from hurry.resource.wsgi import NEEDED, PUBLISHER_PREFIX
 
 class NoRequestError(Exception):
     pass
@@ -41,14 +39,22 @@
         # environment.
         # Unfortunately we don't have easy access to the WSGI environment,
         # so we have to use request._orig_env.
-        return request._orig_env.setdefault(KEY, NeededInclusions())
+        return request._orig_env.setdefault(NEEDED, NeededInclusions())
 
 @subscribe(IEndRequestEvent)
 def set_base_url_on_needed_inclusions(event):
     request = event.request
-    needed = request._orig_env.get(KEY)
-    # We only set the base_url if resources have been needed during this
-    # request and the base_url has not been set yet.
+    # Unfortunately we don't have easy access to the WSGI environment,
+    # so we have to use request._orig_env.
+    needed = request._orig_env.get(NEEDED)
+    # Only set the base_url if resources have been needed during this request.
     if needed is not None and needed.base_url is None:
-        needed.base_url = str(component.getMultiAdapter(
-            (getSite(), request), IAbsoluteURL)) + '/@@/'
+        publisher_prefix = request._orig_env.get(PUBLISHER_PREFIX)
+        # Compute URLs to the resource publisher,
+        # Taking into account skins and virtual host specifications
+        # XXX Do we need to skip ++skin++ information?
+        absolute_url = absoluteURL(None, request)
+        if publisher_prefix is not None:
+            needed.base_url = absolute_url + publisher_prefix
+        else:
+            needed.base_url = absolute_url + '/@@/'



More information about the checkins mailing list