From 08c2348a69963355d784d3687a8a0d3a75abea01 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Wed, 4 Dec 2013 20:49:11 +0100 Subject: [PATCH] [publisher] show update interval, next update --- mygpo/publisher/templates/publisher/podcast.html | 9 +++++- mygpo/web/templatetags/utils.py | 5 ++- mygpo/web/utils.py | 41 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/mygpo/publisher/templates/publisher/podcast.html b/mygpo/publisher/templates/publisher/podcast.html index 1006691e..96ed59ea 100644 --- a/mygpo/publisher/templates/publisher/podcast.html +++ b/mygpo/publisher/templates/publisher/podcast.html @@ -6,6 +6,7 @@ {% load pcharts %} {% load static %} {% load menu %} +{% load utils %} {% block mainmenu %}{{ "/publisher/"|main_menu }}{% endblock %} {% block sectionmenu %}{{ "/publisher/podcast/"|section_menu:podcast.title }}{% endblock %} @@ -54,7 +55,13 @@

Podcast Data

{% trans "The podcast information is regularly retrieved from the podcast feed" %}

{{ podcast.url }}
-

{% trans "Last update: " %}{{ podcast.last_update|naturaltime }}

+ +

{% trans "Timing" %}

+
{% csrf_token %} diff --git a/mygpo/web/templatetags/utils.py b/mygpo/web/templatetags/utils.py index fc339870..3c115009 100644 --- a/mygpo/web/templatetags/utils.py +++ b/mygpo/web/templatetags/utils.py @@ -1,7 +1,7 @@ from django import template from django.utils.safestring import mark_safe -from mygpo.web.utils import get_page_list, license_info +from mygpo.web.utils import get_page_list, license_info, hours_to_str register = template.Library() @@ -89,3 +89,6 @@ def urlquote(s): if isinstance(s, unicode): s = s.encode('utf-8') return mark_safe(urllib.quote_plus(s)) + + +hours_to_str = register.filter(hours_to_str) diff --git a/mygpo/web/utils.py b/mygpo/web/utils.py index 17fadc53..5dc9c293 100644 --- a/mygpo/web/utils.py +++ b/mygpo/web/utils.py @@ -3,6 +3,7 @@ import string import collections from datetime import datetime +from django.utils.translation import ungettext from django.views.decorators.cache import never_cache from django.utils.html import strip_tags from django.core.urlresolvers import reverse @@ -287,3 +288,43 @@ def check_restrictions(obj): """ checks for known restrictions of the object """ if "hide" in obj.restrictions: raise Http404 + + +def hours_to_str(hours_total): + """ returns a human-readable string representation of some hours + + >>> hours_to_str(1) + u'1 hour' + + >>> hours_to_str(5) + u'5 hours' + + >>> hours_to_str(100) + u'4 days, 4 hours' + + >>> hours_to_str(960) + u'5 weeks, 5 days' + + >>> hours_to_str(961) + u'5 weeks, 5 days, 1 hour' + """ + + weeks = hours_total / 24 / 7 + days = hours_total / 24 % 7 + hours = hours_total % 24 + + strs = [] + + if weeks: + strs.append(ungettext('%(weeks)d week', '%(weeks)d weeks', weeks) % + { 'weeks': weeks}) + + if days: + strs.append(ungettext('%(days)d day', '%(days)d days', days) % + { 'days': days}) + + if hours: + strs.append(ungettext('%(hours)d hour', '%(hours)d hours', hours) % + { 'hours': hours}) + + return ', '.join(strs) -- 2.11.4.GIT