-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored
iso_time_tag
from a filter to an inclusion tag
- Loading branch information
Showing
4 changed files
with
15 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters