summaryrefslogtreecommitdiff
path: root/mirrors
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-04-15 22:00:57 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-04-15 22:00:57 -0400
commit05430050147c87818c08373e9930756da4d6b5ac (patch)
tree24db1d6ca431ff64f91e3f41547b91687c4aedd7 /mirrors
parent86bd3d5e4920fd6d57ac51ed3abf02d2f368f2a7 (diff)
parent1a35cbe842212d674d83196ecfa70569ffe2e2da (diff)
Merge tag 'release_2014-11-08' into archweb-generic
Mirror status and details switch to Jinja2
Diffstat (limited to 'mirrors')
-rw-r--r--mirrors/models.py1
-rw-r--r--mirrors/templatetags/jinja2.py53
-rw-r--r--mirrors/templatetags/mirror_status.py7
3 files changed, 54 insertions, 7 deletions
diff --git a/mirrors/models.py b/mirrors/models.py
index 820f3328..9743d177 100644
--- a/mirrors/models.py
+++ b/mirrors/models.py
@@ -165,6 +165,7 @@ class MirrorLog(models.Model):
is_success = models.BooleanField(default=True)
error = models.TextField(blank=True, default='')
+ @property
def delay(self):
if self.last_sync is None:
return None
diff --git a/mirrors/templatetags/jinja2.py b/mirrors/templatetags/jinja2.py
new file mode 100644
index 00000000..04e50238
--- /dev/null
+++ b/mirrors/templatetags/jinja2.py
@@ -0,0 +1,53 @@
+from datetime import timedelta
+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 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:
diff --git a/mirrors/templatetags/mirror_status.py b/mirrors/templatetags/mirror_status.py
index b3810d9a..c8004e4b 100644
--- a/mirrors/templatetags/mirror_status.py
+++ b/mirrors/templatetags/mirror_status.py
@@ -31,11 +31,4 @@ def floatvalue(value, arg=2):
return u''
return '%.*f' % (arg, value)
-@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)
-
# vim: set ts=4 sw=4 et: