From 2c1336488059dfc24c34dd11865c713fec252cbc Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 30 Sep 2010 12:47:30 -0500 Subject: Mirror status improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix sorting issues. '', 'unknown', and '∞' should now always sort after anything else in the list. * Add a completion percentage column; this will tell you at a glance if a mirror is sometimes unresponsive. This should probably be incorporated into the mirror score. * Make a few more things dynamic in the template, like the time back the page reflects. * Add some additional template tags for formatting things. Signed-off-by: Dan McGee --- mirrors/templatetags/mirror_status.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'mirrors/templatetags') diff --git a/mirrors/templatetags/mirror_status.py b/mirrors/templatetags/mirror_status.py index 09c5b33..0031d83 100644 --- a/mirrors/templatetags/mirror_status.py +++ b/mirrors/templatetags/mirror_status.py @@ -1,15 +1,36 @@ +from datetime import timedelta from django import template +from django.template.defaultfilters import floatformat register = template.Library() @register.filter def duration(value): - if not value: - return u'\u221e' + if not value and type(value) != timedelta: + return u'' # does not take microseconds into account total_secs = value.seconds + value.days * 24 * 3600 mins, secs = divmod(total_secs, 60) hrs, mins = divmod(mins, 60) return '%d:%02d' % (hrs, mins) +@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, secs = divmod(total_secs, 60) + hrs, mins = divmod(mins, 60) + if hrs == 1: + return '%d hour' % hrs + return '%d hours' % hrs + +@register.filter +def percentage(value, arg=-1): + if not value and type(value) != float: + return u'' + new_val = value * 100.0 + return floatformat(new_val, arg) + '%' + # vim: set ts=4 sw=4 et: -- cgit v1.2.3-24-g4f1b