Don't escape slashes when generating content's URL
authorThierry Florac <tflorac@ulthar.net>
Tue, 17 Sep 2019 11:34:31 +0200
changeset 392 1af0ba410187
parent 391 49d63e4bf171
child 393 225e6576d28d
Don't escape slashes when generating content's URL
src/pyams_utils/url.py
--- a/src/pyams_utils/url.py	Tue Sep 17 11:28:42 2019 +0200
+++ b/src/pyams_utils/url.py	Tue Sep 17 11:34:31 2019 +0200
@@ -31,8 +31,9 @@
     shorter than three characters are removed; terms are joined by hyphens.
     """
     return '-'.join(filter(lambda x: len(x) >= min_word_length,
-                           translate_string(title, escape_slashes=True, force_lower=True, spaces='-',
-                                            remove_punctuation=True, keep_chars='-').split('-')))
+                           translate_string(title, escape_slashes=False, force_lower=True,
+                                            spaces='-', remove_punctuation=True,
+                                            keep_chars='-').split('-')))
 
 
 #
@@ -64,8 +65,8 @@
     if isinstance(context, str):
         return context
 
-    # 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...
+    # 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]
@@ -84,7 +85,8 @@
     return result
 
 
-@adapter_config(name='absolute_url', context=(Interface, Interface, Interface), provides=ITALESExtension)
+@adapter_config(name='absolute_url', context=(Interface, Interface, Interface),
+                provides=ITALESExtension)
 class AbsoluteUrlTalesExtension(ContextRequestViewAdapter):
     """extension:absolute_url(context, view_name) TALES extension
 
@@ -118,7 +120,8 @@
         return absolute_url(context, request, view_name, query)
 
 
-@adapter_config(name='canonical_url', context=(Interface, Interface, Interface), provides=ITALESExtension)
+@adapter_config(name='canonical_url', context=(Interface, Interface, Interface),
+                provides=ITALESExtension)
 class CanonicalUrlTalesExtension(ContextRequestViewAdapter):
     """extension:canonical_url(context, view_name) TALES extension
 
@@ -153,11 +156,13 @@
     return adapter.get_url(display_context, view_name, query)
 
 
-@adapter_config(name='relative_url', context=(Interface, Interface, Interface), provides=ITALESExtension)
+@adapter_config(name='relative_url', context=(Interface, Interface, Interface),
+                provides=ITALESExtension)
 class RelativeUrlTalesExtension(ContextRequestViewAdapter):
     """extension:relative_url(context, view_name, query) TALES extension
 
-    A PyAMS TALES extension used to get an object's relative URL based on current request display context.
+    A PyAMS TALES extension used to get an object's relative URL based on current request display
+    context.
     """
 
     def render(self, context=None, view_name=None, query=None):