Commits

Matthew Schinckel committed f94b182

Added new template filters for number of seconds.

  • Participants
  • Parent commits 5e5a3f2

Comments (0)

Files changed (3)

 
 Changelog
 ----------
+0.6.6: Add in a couple of new template filters: total_seconds, and total_seconds_sort.
+       The latter zero-pads the value to 10 places, ideal for lexical sorting.
+       This correctly sorts timedeltas of up to around 10 years, if you need more
+       you can pass an argument to the filter.
+
 0.6.5: Empty string values in database now are returned as None for the field value.
        Note that you must have field.null=True to store a NULL in the db.
        I'm still not 100% happy with this: postgres may choke on empty string values when doing INTERVAL comparisons.

File timedelta/templatetags/decimal_hours.py

 
 @register.filter(name='decimal_hours')
 def decimal_hours(value, decimal_places=None):
-    return dh(value, decimal_places)
+    return dh(value, decimal_places)

File timedelta/templatetags/timedelta.py

 register = template.Library()
 
 # Don't really like using relative imports, but no choice here!
-from ..helpers import nice_repr, iso8601_repr
+from ..helpers import nice_repr, iso8601_repr, total_seconds as _total_seconds
 
 @register.filter(name='timedelta')
 def timedelta(value, display="long"):
 @register.filter(name='iso8601')
 def iso8601(value):
     return iso8601_repr(value)
+
+@register.filter(name='total_seconds')
+def total_seconds(value):
+    return _total_seconds(value)
+
+@register.filter(name='total_seconds_sort')
+def total_seconds(value, places=10):
+    return ("%0" + str(places) + "i") % _total_seconds(value)
+