# HG changeset patch # User Thierry Florac # Date 1530095002 -7200 # Node ID 5ac9be953a8f5866c6e65cfb37389f5d24e1b119 # Parent 4eff8c9109eb3f965592b85630a694a5c687bfb9 Added "cache_key" TALES extension diff -r 4eff8c9109eb -r 5ac9be953a8f src/pyams_utils/cache.py --- a/src/pyams_utils/cache.py Fri Jun 22 12:50:19 2018 +0200 +++ b/src/pyams_utils/cache.py Wed Jun 27 12:23:22 2018 +0200 @@ -18,9 +18,11 @@ # import interfaces from persistent.interfaces import IPersistent from pyams_utils.interfaces import ICacheKeyValue +from pyams_utils.interfaces.tales import ITALESExtension # import packages -from pyams_utils.adapter import adapter_config +from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter +from zope.interface import Interface @adapter_config(context=object, provides=ICacheKeyValue) @@ -39,3 +41,16 @@ return str(int.from_bytes(obj._p_oid, byteorder='big')) else: # unsaved object return str(id(obj)) + + +@adapter_config(name='cache_key', context=(Interface, Interface, Interface), provides=ITALESExtension) +class CacheKeyTalesExtension(ContextRequestViewAdapter): + """extension:cache_key(context) TALES extension + + A PyAMS TALES extension which allows to render cache key value for a given context. + """ + + def render(self, context=None): + if context is None: + context = self.request.context + return ICacheKeyValue(context)