# HG changeset patch # User Thierry Florac # Date 1530095021 -7200 # Node ID c164b59809c8b18c9aefe892f4c6a2de024ffec8 # Parent 5ac9be953a8f5866c6e65cfb37389f5d24e1b119 Added "timestamp" TALES extension diff -r 5ac9be953a8f -r c164b59809c8 src/pyams_utils/date.py --- 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()