From 03b50a0aa0454babaa151431d9326dcae11350ba Mon Sep 17 00:00:00 2001 From: Flavio Curella Date: Thu, 27 Feb 2014 14:59:30 +0100 Subject: [PATCH] refactored `iso_time_tag` from a filter to an inclusion tag --- cms/templatetags/cms.py | 19 +++++++------------ templates/cms/iso_time_tag.html | 6 ++++++ templates/components/blog-posts.html | 2 +- templates/components/event-posts.html | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 templates/cms/iso_time_tag.html diff --git a/cms/templatetags/cms.py b/cms/templatetags/cms.py index dda85f14d..99b616399 100644 --- a/cms/templatetags/cms.py +++ b/cms/templatetags/cms.py @@ -1,19 +1,14 @@ from django import template from django.utils.dateformat import format -from django.utils.safestring import mark_safe register = template.Library() -@register.filter(is_safe=True) +@register.inclusion_tag('cms/iso_time_tag.html') def iso_time_tag(date): - """ Returns an ISO date, with the year tagged in a say-no-more span. - - This allows the date representation to shrink to just MM-DD. """ - date_templ = '' - return mark_safe(date_templ.format( - timestamp=format(date, 'c'), - month=format(date, 'm'), - day=format(date, 'd'), - year=format(date, 'Y'), - )) + return { + 'timestamp': format(date, 'c'), + 'month': format(date, 'm'), + 'day': format(date, 'd'), + 'year': format(date, 'Y'), + } diff --git a/templates/cms/iso_time_tag.html b/templates/cms/iso_time_tag.html new file mode 100644 index 000000000..4b4958ac8 --- /dev/null +++ b/templates/cms/iso_time_tag.html @@ -0,0 +1,6 @@ +{% comment %} + Returns an ISO date, with the year tagged in a say-no-more span. + + This allows the date representation to shrink to just MM-DD. +{% endcomment %} + diff --git a/templates/components/blog-posts.html b/templates/components/blog-posts.html index 3a48bb8cd..1855c8a2e 100644 --- a/templates/components/blog-posts.html +++ b/templates/components/blog-posts.html @@ -7,7 +7,7 @@

Lates diff --git a/templates/components/event-posts.html b/templates/components/event-posts.html index ccc121665..9b3ef8706 100644 --- a/templates/components/event-posts.html +++ b/templates/components/event-posts.html @@ -8,7 +8,7 @@

U {% get_events_upcoming limit=5 as events %} {% for event in events %} {% with event.next_time as next_time %} -
  • {{ next_time.dt_start|iso_time_tag }} {{ event.title|striptags }}
  • +
  • {% iso_time_tag next_time.dt_start %} {{ event.title|striptags }}
  • {% endwith %} {% endfor %}