Check if request is an instance of PyramidPublisherRequest in "relative_url" function
authorThierry Florac <tflorac@ulthar.net>
Fri, 26 Jul 2019 12:30:53 +0200
changeset 388 e768f0e1e52f
parent 387 604807051f00
child 389 f0a62fab5368
Check if request is an instance of PyramidPublisherRequest in "relative_url" function
src/pyams_utils/url.py
--- a/src/pyams_utils/url.py	Fri Jun 28 15:40:59 2019 +0200
+++ b/src/pyams_utils/url.py	Fri Jul 26 12:30:53 2019 +0200
@@ -10,10 +10,9 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
-
 from pyramid.encode import url_quote, urlencode
 from pyramid.url import QUERY_SAFE, resource_url
+from pyramid_zope_request import PyramidPublisherRequest
 from zope.interface import Interface
 
 from pyams_utils.adapter import ContextRequestAdapter, ContextRequestViewAdapter, adapter_config
@@ -22,6 +21,9 @@
 from pyams_utils.unicode import translate_string
 
 
+__docformat__ = 'restructuredtext'
+
+
 def generate_url(title, min_word_length=2):
     """Generate an SEO-friendly content URL from it's title
 
@@ -143,6 +145,8 @@
 
 def relative_url(context, request, display_context=None, view_name=None, query=None):
     """Get resource URL relative to given context"""
+    if isinstance(request, PyramidPublisherRequest):
+        request = request._request
     if display_context is None:
         display_context = request.annotations.get(DISPLAY_CONTEXT, request.context)
     adapter = request.registry.getMultiAdapter((context, request), IRelativeURL)