Skip to content

Commit

Permalink
refactored iso_time_tag from a filter to an inclusion tag
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Feb 27, 2014
1 parent 18cb0f8 commit 03b50a0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
19 changes: 7 additions & 12 deletions cms/templatetags/cms.py
Original file line number Diff line number Diff line change
@@ -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 = '<time datetime="{timestamp}"><span class="say-no-more">{year}-</span>{month}-{day}</time>'
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'),
}
6 changes: 6 additions & 0 deletions templates/cms/iso_time_tag.html
Original file line number Diff line number Diff line change
@@ -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 %}
<time datetime="{{ timestamp }}"><span class="say-no-more">{{ year }}-</span>{{ month }}-{{ day }}</time>
2 changes: 1 addition & 1 deletion templates/components/blog-posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2 class="widget-title"><span aria-hidden="true" class="icon-news"></span>Lates
<ul class="menu">
{% get_latest_blog_entries limit=5 as entries %}
{% for entry in entries %}
<li>{{ entry.pub_date|iso_time_tag }} <a href="{{ entry.url }}">{{ entry.summary|striptags|truncatewords:10|safe }}</a></li>
<li>{% iso_time_tag entry.pub_date %} <a href="{{ entry.url }}">{{ entry.summary|striptags|truncatewords:10|safe }}</a></li>
{% endfor %}
</ul>
</div><!-- end .shrubbery -->
2 changes: 1 addition & 1 deletion templates/components/event-posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2 class="widget-title"><span aria-hidden="true" class="icon-calendar"></span>U
{% get_events_upcoming limit=5 as events %}
{% for event in events %}
{% with event.next_time as next_time %}
<li>{{ next_time.dt_start|iso_time_tag }} <a href="{{ event.get_absolute_url }}">{{ event.title|striptags }}</a></li>
<li>{% iso_time_tag next_time.dt_start %} <a href="{{ event.get_absolute_url }}">{{ event.title|striptags }}</a></li>
{% endwith %}
{% endfor %}
</ul>
Expand Down

0 comments on commit 03b50a0

Please sign in to comment.