# HG changeset patch # User Damien Correia # Date 1524823158 -7200 # Node ID 1adc0ffda3665fc1867729760813244de6809a7a # Parent 146a0deffad83100722acb83020eebcaefa18079# Parent 2db6735d541662202ef7861196f7603c75fcf9bb merge default diff -r 146a0deffad8 -r 1adc0ffda366 .hgtags --- a/.hgtags Thu Apr 12 11:43:16 2018 +0200 +++ b/.hgtags Fri Apr 27 11:59:18 2018 +0200 @@ -14,3 +14,4 @@ d702d2bf095a840135620dbd8ec877b0f3c34a2d 0.1.11 417296f4bfab831c918720a17737e30cda2bd933 0.1.12 aedd98145b972474f1d68a6fa87653faaf4f7ea3 0.1.13 +f7e43a680f4221fc00ca3c8ed779e772a46961d1 0.1.14 diff -r 146a0deffad8 -r 1adc0ffda366 docs/HISTORY.txt --- a/docs/HISTORY.txt Thu Apr 12 11:43:16 2018 +0200 +++ b/docs/HISTORY.txt Fri Apr 27 11:59:18 2018 +0200 @@ -1,6 +1,13 @@ Changelog ========= +0.1.14 +------ + - updated request_property decorator cache key + - updated base site root ACL to grant 'public' permission to everyone + - use object ID in default cache key adapter + - add cache key adapters for string and persistent objects + 0.1.13 ------ - added site root factory interface diff -r 146a0deffad8 -r 1adc0ffda366 src/pyams_utils.egg-info/PKG-INFO --- a/src/pyams_utils.egg-info/PKG-INFO Thu Apr 12 11:43:16 2018 +0200 +++ b/src/pyams_utils.egg-info/PKG-INFO Fri Apr 27 11:59:18 2018 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pyams-utils -Version: 0.1.13 +Version: 0.1.14 Summary: Utility functions and classes for PyAMS Home-page: http://www.ztfy.org Author: Thierry Florac @@ -48,6 +48,13 @@ Changelog ========= + 0.1.14 + ------ + - updated request_property decorator cache key + - updated base site root ACL to grant 'public' permission to everyone + - use object ID in default cache key adapter + - add cache key adapters for string and persistent objects + 0.1.13 ------ - added site root factory interface diff -r 146a0deffad8 -r 1adc0ffda366 src/pyams_utils.egg-info/SOURCES.txt --- a/src/pyams_utils.egg-info/SOURCES.txt Thu Apr 12 11:43:16 2018 +0200 +++ b/src/pyams_utils.egg-info/SOURCES.txt Fri Apr 27 11:59:18 2018 +0200 @@ -5,6 +5,7 @@ src/pyams_utils/__init__.py src/pyams_utils/adapter.py src/pyams_utils/attr.py +src/pyams_utils/cache.py src/pyams_utils/configure.zcml src/pyams_utils/container.py src/pyams_utils/context.py diff -r 146a0deffad8 -r 1adc0ffda366 src/pyams_utils/cache.py --- a/src/pyams_utils/cache.py Thu Apr 12 11:43:16 2018 +0200 +++ b/src/pyams_utils/cache.py Fri Apr 27 11:59:18 2018 +0200 @@ -35,4 +35,7 @@ @adapter_config(context=IPersistent, provides=ICacheKeyValue) def persistent_cache_key_adapter(obj): - return str(int.from_bytes(obj._p_oid, byteorder='big')) + if obj._p_oid: + return str(int.from_bytes(obj._p_oid, byteorder='big')) + else: # unsaved object + return str(id(obj)) diff -r 146a0deffad8 -r 1adc0ffda366 src/pyams_utils/url.py --- a/src/pyams_utils/url.py Thu Apr 12 11:43:16 2018 +0200 +++ b/src/pyams_utils/url.py Fri Apr 27 11:59:18 2018 +0200 @@ -16,16 +16,27 @@ # import standard library # import interfaces -from persistent.interfaces import IPersistent from pyams_utils.interfaces.tales import ITALESExtension # import packages from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config +from pyams_utils.unicode import translate_string from pyramid.encode import url_quote, urlencode from pyramid.url import resource_url, QUERY_SAFE from zope.interface import Interface +def generate_url(title): + """Generate an SEO-friendly content URL from it's title + + The original title is translated to remove accents, converted to lowercase, and words + shorter than three characters are removed; terms are joined by hyphens. + """ + return '-'.join(filter(lambda x: len(x) > 2, + translate_string(title, escape_slashes=True, force_lower=True, spaces='-', + remove_punctuation=True, keep_chars='-').split('-'))) + + def absolute_url(context, request, view_name=None, query=None): """Get resource absolute_url