Added "view_name" argument in "absolute_url" TALES extension
authorThierry Florac <thierry.florac@onf.fr>
Wed, 20 May 2015 12:41:21 +0200
changeset 34 b70afbacf63b
parent 33 e1aca8c25e61
child 35 ff081a708652
Added "view_name" argument in "absolute_url" TALES extension
src/pyams_utils/url.py
--- a/src/pyams_utils/url.py	Wed May 20 12:40:19 2015 +0200
+++ b/src/pyams_utils/url.py	Wed May 20 12:41:21 2015 +0200
@@ -27,7 +27,9 @@
 
 def absolute_url(context, request, view_name=None):
     """Get resource absolute_url"""
-    result = resource_url(context, request)
+    # if we have several parents without name in the lineage, the resource URL contains a double slash
+    # which generates "NotFound" exceptions; so we replace it with a single slash...
+    result = resource_url(context, request).replace('//', '/').replace(':/', '://')
     if result.endswith('/'):
         result = result[:-1]
     if view_name:
@@ -42,7 +44,7 @@
 class AbsoluteUrlTalesExtension(ContextRequestViewAdapter):
     """extension:absolute_url(context) TALES extension"""
 
-    def render(self, context):
+    def render(self, context=None, view_name=None):
         if context is None:
             context = self.context
-        return absolute_url(context, self.request)
+        return absolute_url(context, self.request, view_name)