# HG changeset patch # User Damien Correia # Date 1528726417 -7200 # Node ID a70ef9a05ea1254cbb04205cb87c0320caaeab7e # Parent 4abd201debc662ed6fa97338a0f84fb2eefd2b97# Parent 81c21f719cc698c8fece7c89e60a64f0c581ac26 merge default diff -r 4abd201debc6 -r a70ef9a05ea1 .hgtags --- a/.hgtags Mon Jun 11 09:59:25 2018 +0200 +++ b/.hgtags Mon Jun 11 16:13:37 2018 +0200 @@ -15,3 +15,4 @@ 417296f4bfab831c918720a17737e30cda2bd933 0.1.12 aedd98145b972474f1d68a6fa87653faaf4f7ea3 0.1.13 f7e43a680f4221fc00ca3c8ed779e772a46961d1 0.1.14 +0b5f84d9eff4d94ae88078b157148fbda6aa7a58 0.1.15 diff -r 4abd201debc6 -r a70ef9a05ea1 docs/HISTORY.txt --- a/docs/HISTORY.txt Mon Jun 11 09:59:25 2018 +0200 +++ b/docs/HISTORY.txt Mon Jun 11 16:13:37 2018 +0200 @@ -1,6 +1,13 @@ Changelog ========= +0.1.15 +------ + - added "inherit_from" attribute to IInheritInfo interface + - added helper to get a persistent adapter through context's annotations + - added "canonical_url" function, interface and TALES extension + - updated custom PyAMS traverser to notify BeforeTraverseEvent on last traversed object + 0.1.14 ------ - updated request_property decorator cache key diff -r 4abd201debc6 -r a70ef9a05ea1 src/pyams_utils.egg-info/PKG-INFO --- a/src/pyams_utils.egg-info/PKG-INFO Mon Jun 11 09:59:25 2018 +0200 +++ b/src/pyams_utils.egg-info/PKG-INFO Mon Jun 11 16:13:37 2018 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pyams-utils -Version: 0.1.14 +Version: 0.1.15 Summary: Utility functions and classes for PyAMS Home-page: http://www.ztfy.org Author: Thierry Florac @@ -48,6 +48,13 @@ Changelog ========= + 0.1.15 + ------ + - added "inherit_from" attribute to IInheritInfo interface + - added helper to get a persistent adapter through context's annotations + - added "canonical_url" function, interface and TALES extension + - updated custom PyAMS traverser to notify BeforeTraverseEvent on last traversed object + 0.1.14 ------ - updated request_property decorator cache key diff -r 4abd201debc6 -r a70ef9a05ea1 src/pyams_utils.egg-info/SOURCES.txt --- a/src/pyams_utils.egg-info/SOURCES.txt Mon Jun 11 09:59:25 2018 +0200 +++ b/src/pyams_utils.egg-info/SOURCES.txt Mon Jun 11 16:13:37 2018 +0200 @@ -14,6 +14,7 @@ src/pyams_utils/decorator.py src/pyams_utils/dict.py src/pyams_utils/encoding.py +src/pyams_utils/factory.py src/pyams_utils/fanstatic.py src/pyams_utils/html.py src/pyams_utils/i18n.py @@ -61,6 +62,7 @@ src/pyams_utils/interfaces/timezone.py src/pyams_utils/interfaces/traversing.py src/pyams_utils/interfaces/tree.py +src/pyams_utils/interfaces/url.py src/pyams_utils/interfaces/zeo.py src/pyams_utils/locales/pyams_utils.pot src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.mo @@ -77,9 +79,4 @@ src/pyams_utils/timezone/utility.py src/pyams_utils/timezone/vocabulary.py src/pyams_utils/widget/__init__.py -src/pyams_utils/widget/decimal.py -src/pyams_utils/zmi/__init__.py -src/pyams_utils/zmi/intids.py -src/pyams_utils/zmi/timezone.py -src/pyams_utils/zmi/zeo.py -src/pyams_utils/zmi/templates/connection-test.pt \ No newline at end of file +src/pyams_utils/widget/decimal.py \ No newline at end of file diff -r 4abd201debc6 -r a70ef9a05ea1 src/pyams_utils/interfaces/url.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_utils/interfaces/url.py Mon Jun 11 16:13:37 2018 +0200 @@ -0,0 +1,28 @@ +# +# Copyright (c) 2008-2018 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' + + +# import standard library + +# import interfaces + +# import packages +from zope.interface import Interface, Attribute + + +class ICanonicalURL(Interface): + """Interface used to get content's canonical URL""" + + def get_url(self, view_name=None, query=None): + """Get content's canonical URL""" diff -r 4abd201debc6 -r a70ef9a05ea1 src/pyams_utils/url.py --- a/src/pyams_utils/url.py Mon Jun 11 09:59:25 2018 +0200 +++ b/src/pyams_utils/url.py Mon Jun 11 16:13:37 2018 +0200 @@ -17,6 +17,7 @@ # import interfaces from pyams_utils.interfaces.tales import ITALESExtension +from pyams_utils.interfaces.url import ICanonicalURL # import packages from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config @@ -85,3 +86,33 @@ if context is None: context = self.context return absolute_url(context, self.request, view_name) + + +def canonical_url(context, request, view_name=None, query=None): + """Get resource canonical URL""" + + # if we pass a string to canonical_url(), argument is returned as-is! + if isinstance(context, str): + return context + + url_adapter = request.registry.queryMultiAdapter((context, request), ICanonicalURL) + if url_adapter is None: + url_adapter = request.registry.queryAdapter(context, ICanonicalURL) + + if url_adapter is not None: + return url_adapter.get_url(view_name, query) + else: + return absolute_url(context, request, view_name, query) + + +@adapter_config(name='canonical_url', context=(Interface, Interface, Interface), provides=ITALESExtension) +class CanonicalUrlTalesExtension(ContextRequestViewAdapter): + """extension:canonical_url(context, view_name) TALES extension + + A PyAMS TALES extension used to get access to an object's canonical URL from a page template. + """ + + def render(self, context=None, view_name=None): + if context is None: + context = self.context + return canonical_url(context, self.request, view_name)