--- a/src/pyams_utils/date.py Wed Jun 27 12:23:22 2018 +0200
+++ b/src/pyams_utils/date.py Wed Jun 27 12:23:41 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()