Add verbose flag for util.raw_datetime() rendering

just seems like could be useful somewhere...though not used yet
This commit is contained in:
Lance Edgar 2019-05-14 15:58:43 -05:00
parent 13db4861e1
commit f61cf318ae

View file

@ -80,7 +80,7 @@ def pretty_datetime(config, value):
c=humanize.naturaltime(time_ago)) c=humanize.naturaltime(time_ago))
def raw_datetime(config, value): def raw_datetime(config, value, verbose=False):
""" """
Formats a datetime as a "raw" human-readable string, with a tooltip Formats a datetime as a "raw" human-readable string, with a tooltip
showing the more human-friendly "time since" equivalent. showing the more human-friendly "time since" equivalent.
@ -113,9 +113,18 @@ def raw_datetime(config, value):
else: else:
kwargs['c'] = six.text_type(value) kwargs['c'] = six.text_type(value)
# Avoid humanize error when calculating huge time diff. # avoid humanize error when calculating huge time diff
time_diff = None
if abs(time_ago.days) < 100000: if abs(time_ago.days) < 100000:
kwargs['title'] = humanize.naturaltime(time_ago) time_diff = humanize.naturaltime(time_ago)
# by "verbose" we mean the result text to look like "YYYY-MM-DD (X days ago)"
if verbose:
kwargs['c'] = "{} ({})".format(kwargs['c'], time_diff)
# vs. if *not* verbose, text is "YYYY-MM-DD" but we add "X days ago" as title
else:
kwargs['title'] = time_diff
return HTML.tag('span', **kwargs) return HTML.tag('span', **kwargs)