def datestampformat(value, arg=None): logger.debug("value=%s, arg=%s" % (value, arg)) t = datetime.fromtimestamp(int(value)) logger.debug("Timestamp translated to: %s" % str(t)) f = filter_time(t, arg) logger.debug("Timestamp rendered as %s" % f) return f
def last_seen(value, autoescape=None): """Formats a datetime as an HTML string representing a short digest of the time since that date, contained by a <span>, with a title (tooltip) of the full date.""" # if autoescaping is on, then we will # need to pass outgoing strings through # cond_esc, or django will escape the HTML if autoescape: esc = conditional_escape else: esc = lambda x: x try: if value: # looks like we have a valid date - return # a span containing the long and short version ts = timesince(value) mag = magnitude_ago(value) long = "on %s at %s" % (filter_date(value), filter_time(value)) out = '<span class="last-seen %s" title="%s">%s ago</span>' % (esc(mag), esc(long), esc(ts)) # abort if there is no date (it's # probably just a null model field) else: out = '<span class="last-seen n/a">Never</span>' # something went wrong! don't blow up # the entire template, just flag it except (ValueError, TypeError): out = '<span class="last-seen error">Error</span>' return mark_safe(out)
def datestampformat(value, arg=None): logger.debug("value=%s, arg=%s" % (value,arg)) t = datetime.fromtimestamp(int(value)) logger.debug("Timestamp translated to: %s" % str(t)) f = filter_time(t, arg) logger.debug("Timestamp rendered as %s" % f) return f