# HG changeset patch # User tflorac@dagon.home # Date 1546456526 -3600 # Node ID 79c1f716107f614bd3dc7a8028233342efa3a946 # Parent 4d5930d8c4ba824686ed9f73cb566caaa750e4fa Updated canonical URL for blog and site topics diff -r 4d5930d8c4ba -r 79c1f716107f src/pyams_default_theme/shared/blog/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/shared/blog/__init__.py Wed Jan 02 20:15:26 2019 +0100 @@ -0,0 +1,36 @@ +# +# Copyright (c) 2008-2019 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + +from pyams_content.shared.blog import IWfBlogPost +from pyams_content.shared.blog.interfaces import IBlogFolder +from pyams_sequence.interfaces import ISequentialIdInfo +from pyams_skin.layer import IPyAMSUserLayer +from pyams_utils.adapter import adapter_config, ContextRequestAdapter +from pyams_utils.interfaces.url import ICanonicalURL +from pyams_utils.traversing import get_parent +from pyams_utils.url import absolute_url + + +@adapter_config(context=(IWfBlogPost, IPyAMSUserLayer), provides=ICanonicalURL) +class BlogPostCanonicalUrlAdapter(ContextRequestAdapter): + """Blog post canonical URL adapter""" + + def get_url(self, view_name=None, query=None): + parent = get_parent(self.context, IBlogFolder) + return absolute_url(parent, self.request, + '++oid++{0}::{1}{2}{3}'.format( + ISequentialIdInfo(self.context).get_base_oid().strip(), + self.context.content_url, + '/{}'.format(view_name) if view_name else '.html', + '?{}'.format(query) if query else '')) diff -r 4d5930d8c4ba -r 79c1f716107f src/pyams_default_theme/shared/common/url.py --- a/src/pyams_default_theme/shared/common/url.py Sun Dec 30 18:15:50 2018 +0100 +++ b/src/pyams_default_theme/shared/common/url.py Wed Jan 02 20:15:26 2019 +0100 @@ -16,10 +16,23 @@ 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.interfaces.url import ICanonicalURL, IRelativeURL from pyams_utils.url import absolute_url, relative_url +@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=ICanonicalURL) +class WfSharedContentCanonicalUrlAdapter(ContextRequestAdapter): + """Workflow managed shared content canonical URL adapter""" + + def get_url(self, view_name=None, query=None): + return absolute_url(self.request.root, self.request, + '++oid++{0}::{1}{2}{3}'.format( + ISequentialIdInfo(self.context).get_base_oid().strip(), + self.context.content_url, + '/{}'.format(view_name) if view_name else '.html', + '?{}'.format(query) if query else '')) + + @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IRelativeURL) class WfSharedContentRelativeUrlAdapter(ContextRequestAdapter): """Workflow managed shared content relative URL adapter""" diff -r 4d5930d8c4ba -r 79c1f716107f src/pyams_default_theme/shared/site/__init__.py --- a/src/pyams_default_theme/shared/site/__init__.py Sun Dec 30 18:15:50 2018 +0100 +++ b/src/pyams_default_theme/shared/site/__init__.py Wed Jan 02 20:15:26 2019 +0100 @@ -14,12 +14,17 @@ from zope.interface import Interface -from pyams_content.shared.site.interfaces import ISiteFolder, ISiteManager +from pyams_content.shared.site import IWfSiteTopic +from pyams_content.shared.site.interfaces import ISiteFolder, ISiteManager, ISiteContainer from pyams_i18n.interfaces import II18n +from pyams_sequence.interfaces import ISequentialIdInfo from pyams_skin.interfaces.metas import IHTMLContentMetas from pyams_skin.layer import IPyAMSUserLayer from pyams_skin.metas import ContentMeta, HTMLTagMeta -from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config +from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config, ContextRequestAdapter +from pyams_utils.interfaces.url import ICanonicalURL +from pyams_utils.traversing import get_parent +from pyams_utils.url import absolute_url @adapter_config(name='title', context=(ISiteManager, IPyAMSUserLayer, Interface), provides=IHTMLContentMetas) @@ -38,3 +43,17 @@ description = i18n.query_attribute('header', request=self.request) if description: yield ContentMeta('description', description) + + +@adapter_config(context=(IWfSiteTopic, IPyAMSUserLayer), provides=ICanonicalURL) +class SiteTopicCanonicalUrlAdapter(ContextRequestAdapter): + """Site topic canonical URL adapter""" + + def get_url(self, view_name=None, query=None): + parent = get_parent(self.context, ISiteContainer) + return absolute_url(parent, self.request, + '++oid++{0}::{1}{2}{3}'.format( + ISequentialIdInfo(self.context).get_base_oid().strip(), + self.context.content_url, + '/{}'.format(view_name) if view_name else '.html', + '?{}'.format(query) if query else ''))