# HG changeset patch # User Thierry Florac # Date 1548403635 -3600 # Node ID e0bd4fb6c9a59c6d9bccc394e0f040dbe8fff4e4 # Parent 1cfc6c4791ee99175e8de3bd47979e5f5266c240 Use "visible" version in shared content relative URL adapter; added shared content canonical URL adapter diff -r 1cfc6c4791ee -r e0bd4fb6c9a5 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)