Updated relative URLs adapters
authorThierry Florac <thierry.florac@onf.fr>
Mon, 05 Nov 2018 13:20:10 +0100
changeset 1058 1fe028e17f70
parent 1057 1359212b0034
child 1059 34e6d07ea2e9
Updated relative URLs adapters
src/pyams_content/shared/common/skin/url.py
--- a/src/pyams_content/shared/common/skin/url.py	Mon Nov 05 11:18:34 2018 +0100
+++ b/src/pyams_content/shared/common/skin/url.py	Mon Nov 05 13:20:10 2018 +0100
@@ -12,26 +12,32 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
-from pyams_content.shared.common import IWfSharedContent
+from pyams_content.shared.common import ISharedContent, IWfSharedContent
 from pyams_sequence.interfaces import ISequentialIdInfo
 from pyams_skin.layer import IPyAMSUserLayer
+from pyams_utils.adapter import ContextRequestAdapter, adapter_config
 from pyams_utils.interfaces.url import IRelativeURL
+from pyams_utils.url import absolute_url, relative_url
+
 
-# import packages
-from pyams_utils.adapter import adapter_config, ContextRequestAdapter
-from pyams_utils.url import absolute_url
+@adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=IRelativeURL)
+class SharedContentRelativeURLAdapter(ContextRequestAdapter):
+    """Shared content relative URL adapter"""
+
+    def get_url(self, display_context=None, view_name=None, query=None):
+        version = self.context.published_version
+        if version is not None:
+            return relative_url(version, self.request, display_context, view_name, query)
 
 
 @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IRelativeURL)
-class SharedContentRelativeUrlAdapter(ContextRequestAdapter):
-    """Shared content relative URL adapter"""
+class WfSharedContentRelativeUrlAdapter(ContextRequestAdapter):
+    """Workflow managed shared content relative URL adapter"""
 
     def get_url(self, display_context=None, view_name=None, query=None):
         return absolute_url(display_context, self.request,
-                            '++oid++{0}::{1}.html'.format(
+                            '++oid++{0}::{1}{2}{3}'.format(
                                 ISequentialIdInfo(self.context).get_base_oid().strip(),
-                                self.context.content_url))
+                                self.context.content_url,
+                                '/{}'.format(view_name) if view_name else '.html',
+                                '?{}'.format(query) if query else ''))