Use "visible" version in shared content relative URL adapter; added shared content canonical URL adapter
authorThierry Florac <tflorac@ulthar.net>
Fri, 25 Jan 2019 09:07:15 +0100
changeset 399 e0bd4fb6c9a5
parent 398 1cfc6c4791ee
child 400 3f312a13f01b
Use "visible" version in shared content relative URL adapter; added shared content canonical URL adapter
src/pyams_default_theme/shared/common/url.py
--- a/src/pyams_default_theme/shared/common/url.py	Thu Jan 24 11:39:30 2019 +0100
+++ b/src/pyams_default_theme/shared/common/url.py	Fri Jan 25 09:07:15 2019 +0100
@@ -17,7 +17,7 @@
 from pyams_skin.layer import IPyAMSUserLayer
 from pyams_utils.adapter import ContextRequestAdapter, adapter_config
 from pyams_utils.interfaces.url import ICanonicalURL, IRelativeURL
-from pyams_utils.url import absolute_url, relative_url
+from pyams_utils.url import absolute_url, canonical_url, relative_url
 
 
 @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=ICanonicalURL)
@@ -33,6 +33,16 @@
                                 '?{}'.format(query) if query else ''))
 
 
+@adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=ICanonicalURL)
+class SharedContentCanonicalURLAdapter(ContextRequestAdapter):
+    """Shared content canonical URL adapter"""
+
+    def get_url(self, view_name=None, query=None):
+        version = self.context.visible_version
+        if version is not None:
+            return canonical_url(version, self.request, view_name, query)
+
+
 @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IRelativeURL)
 class WfSharedContentRelativeUrlAdapter(ContextRequestAdapter):
     """Workflow managed shared content relative URL adapter"""
@@ -51,6 +61,6 @@
     """Shared content relative URL adapter"""
 
     def get_url(self, display_context=None, view_name=None, query=None):
-        version = self.context.published_version
+        version = self.context.visible_version
         if version is not None:
             return relative_url(version, self.request, display_context, view_name, query)