# HG changeset patch # User Damien Correia # Date 1530098437 -7200 # Node ID e2a747608ef6e0f3ff89f0e14cd253f6c0a0d806 # Parent 770bac310903afdec466e7d84f983c43633ba99f# Parent c164b59809c8b18c9aefe892f4c6a2de024ffec8 merge default diff -r 770bac310903 -r e2a747608ef6 src/pyams_utils/cache.py --- a/src/pyams_utils/cache.py Fri Jun 22 13:06:28 2018 +0200 +++ b/src/pyams_utils/cache.py Wed Jun 27 13:20:37 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) diff -r 770bac310903 -r e2a747608ef6 src/pyams_utils/date.py --- a/src/pyams_utils/date.py Fri Jun 22 13:06:28 2018 +0200 +++ b/src/pyams_utils/date.py Wed Jun 27 13:20:37 2018 +0200 @@ -17,11 +17,15 @@ from datetime import datetime # import interfaces +from pyams_utils.interfaces.tales import ITALESExtension +from zope.dublincore.interfaces import IZopeDublinCore # import packages +from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter from pyams_utils.request import check_request from pyams_utils.timezone import gmtime, tztime from zope.datetime import parseDatetimetz +from zope.interface import Interface from pyams_utils import _ @@ -245,3 +249,20 @@ return translate(_("%d minutes")) % minutes else: return translate(_("%d seconds")) % delta.seconds + + +@adapter_config(name='timestamp', context=(Interface, Interface, Interface), provides=ITALESExtension) +class TimestampTalesAdapter(ContextRequestViewAdapter): + """extension:timestamp(context) TALES adapter + + A PyAMS TALES extension to get timestamp based on last context modification date. + """ + + def render(self, context=None): + if context is None: + context = self.request.context + dc = IZopeDublinCore(context, None) + if dc is None: + return datetime.utcnow().timestamp() + else: + return dc.modified.timestamp()