--- 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)
--- 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()