summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorJelle van der Waa <jelle@vdwaa.nl>2016-10-21 22:19:46 +0200
committerJelle van der Waa <jelle@vdwaa.nl>2017-05-02 21:13:56 +0200
commit6489bd1a2e6faeff624efa93fa6f1b6f6535ca97 (patch)
tree9653704b927dc53e9453d6a510229db0f99ea5c5 /main
parent7ce890eb18a8d7e17c4eacc760e2cc1ce4608a70 (diff)
downloadarchweb-6489bd1a2e6faeff624efa93fa6f1b6f6535ca97.tar.gz
archweb-6489bd1a2e6faeff624efa93fa6f1b6f6535ca97.zip
Port mirrors to pure django template
Diffstat (limited to 'main')
-rw-r--r--main/templatetags/flags.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/main/templatetags/flags.py b/main/templatetags/flags.py
index 5b356561..d50ee51d 100644
--- a/main/templatetags/flags.py
+++ b/main/templatetags/flags.py
@@ -1,3 +1,4 @@
+from datetime import timedelta
from django import template
register = template.Library()
@@ -10,4 +11,40 @@ def country_flag(country):
return '<span class="fam-flag fam-flag-%s" title="%s"></span> ' % (
unicode(country.code).lower(), unicode(country.name))
+@register.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)
+
+@register.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)
+
+@register.filter
+def floatvalue(value, arg=2):
+ if value is None:
+ return u''
+ return '%.*f' % (arg, value)
+
+
+@register.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
+
# vim: set ts=4 sw=4 et: