diff options
author | Dan McGee <dan@archlinux.org> | 2014-11-08 14:00:06 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2014-11-08 14:00:09 -0600 |
commit | 713ab837ba59c4a7c0b60cb8e8be4b27f4520e52 (patch) | |
tree | 926af09762f87d14d14f118774240a34a8080430 /mirrors | |
parent | eb7172cd4d9d7af690b2be06e3f925d3023be71c (diff) |
Convert mirror status tables to Jinja2
Yay for way improved performance. Local testing showed render times
going from 265 ms to 135 ms.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors')
-rw-r--r-- | mirrors/templatetags/jinja2.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/mirrors/templatetags/jinja2.py b/mirrors/templatetags/jinja2.py index 5d47fe9b..04e50238 100644 --- a/mirrors/templatetags/jinja2.py +++ b/mirrors/templatetags/jinja2.py @@ -1,3 +1,4 @@ +from datetime import timedelta from django_jinja import library from markupsafe import Markup @@ -23,9 +24,30 @@ def duration(value): @library.filter +def hours(value): + if not value and type(value) != timedelta: + return u'' + # does not take microseconds into account + total_secs = value.seconds + value.days * 24 * 3600 + mins = total_secs // 60 + hrs, mins = divmod(mins, 60) + if hrs == 1: + return '%d hour' % hrs + return '%d hours' % hrs + + +@library.filter def floatvalue(value, arg=2): if value is None: return u'' return '%.*f' % (arg, value) + +@library.filter +def percentage(value, arg=1): + if not value and type(value) != float: + return u'' + new_val = value * 100.0 + return '%.*f%%' % (arg, new_val) + # vim: set ts=4 sw=4 et: |