diff options
author | Dan McGee <dan@archlinux.org> | 2014-11-08 13:43:59 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2014-11-08 13:43:59 -0600 |
commit | eb7172cd4d9d7af690b2be06e3f925d3023be71c (patch) | |
tree | 5ba9d30d7dc1e985e37d58ea0c04548b034ec75c /mirrors | |
parent | cd22bfd73b184888df13b194ecdf6e482b36c3fc (diff) |
Convert some of URL details to Jinja2
Anytime we have a loop with >100 items, the Django template engine
begins to be the bottleneck. This one is relatively straightforward to
convert, and sets the stage for converting the mirror status page as
well.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors')
-rw-r--r-- | mirrors/templatetags/jinja2.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/mirrors/templatetags/jinja2.py b/mirrors/templatetags/jinja2.py new file mode 100644 index 00000000..5d47fe9b --- /dev/null +++ b/mirrors/templatetags/jinja2.py @@ -0,0 +1,31 @@ +from django_jinja import library +from markupsafe import Markup + + +@library.global_function +def country_flag(country): + if not country: + return '' + html = '<span class="fam-flag fam-flag-%s" title="%s"></span> ' % ( + unicode(country.code).lower(), unicode(country.name)) + return Markup(html) + + +@library.filter +def duration(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) + return '%d:%02d' % (hrs, mins) + + +@library.filter +def floatvalue(value, arg=2): + if value is None: + return u'' + return '%.*f' % (arg, value) + +# vim: set ts=4 sw=4 et: |