Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
Add a time filter to output time tags
Browse files Browse the repository at this point in the history
We usually have the same kind of formatting in our <time>
tags across reporter, so let's standardize it.

See tofumatt@3c80c58#commitcomment-412158
  • Loading branch information
tofumatt committed Jun 3, 2011
1 parent 1dc21fc commit 6ac0a39
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
3 changes: 1 addition & 2 deletions apps/dashboard/templates/dashboard/message_list.html
Expand Up @@ -9,8 +9,7 @@ <h3 class="type {{ opinion.type_name|lower }}" title="{{ opinion.type_name }}"><
<ul class="meta">
<li>
<a href="{{ opinion.get_url_path() }}">
<time datetime="{{ opinion.created|isotime }}" title="{{ opinion.created|babel_datetime }}">{{
opinion.created|timesince }}</time>
{{ opinion.created|time }}
</a>
</li>
<li><a href="{{ search_url(platform=opinion.platform, defaults=defaults) }}">{{ platform_name(opinion.platform) }}{% if opinion.device %} ({{ opinion.device }}){% endif %}</a></li>
Expand Down
3 changes: 1 addition & 2 deletions apps/dashboard/templates/dashboard/mobile/message_list.html
Expand Up @@ -9,8 +9,7 @@ <h3 class="type {{ opinion.type_name|lower }}" title="{{ opinion.type_name }}"><

<ul class="meta">
<li>
<time datetime="{{ opinion.created|isotime }}" title="{{ opinion.created|babel_datetime }}">{{
opinion.created|timesince }}</time>
{{ opinion.created|time }}
</li>
<li>{{ platform_name(opinion.platform) }}{% if opinion.device %} ({{ opinion.device }}){% endif %}</li>
<li>{{ locale_name(opinion.locale) }}</li>
Expand Down
3 changes: 1 addition & 2 deletions apps/feedback/templates/feedback/mobile/opinion.html
Expand Up @@ -22,8 +22,7 @@ <h3 class="type {{ opinion.type_name|lower }}" title="{{ opinion.type_name }}"><
<ul class="meta">
<li>
<a href="{{ opinion.get_url_path() }}">
<time datetime="{{ opinion.created|isotime }}" title="{{ opinion.created|babel_datetime }}">{{
opinion.created|timesince }}</time>
{{ opinion.created|time }}
</a>
</li>
<li><a href="{{ search_url(platform=opinion.platform, defaults=defaults) }}">{{ platform_name(opinion.platform) }}{% if opinion.device %} ({{ opinion.device }}){% endif %}</a></li>
Expand Down
16 changes: 16 additions & 0 deletions apps/input/helpers.py
Expand Up @@ -6,6 +6,7 @@
from django.utils import translation
from django.utils.encoding import smart_str
from django.utils.http import urlencode
from django.utils.safestring import mark_safe

from babel import Locale, UnknownLocaleError
from babel.support import Format
Expand Down Expand Up @@ -60,6 +61,21 @@ def babel_date(t, format='medium'):
def babel_datetime(t, format='medium'):
return _get_format().datetime(t, format=format)

@register.filter
def time(time):
"""
Return a <time> tag with a locale-formatted time inside the title
attribute and an HTML5 datetime attribute formatted time inside the
datetime attribute.
The content of the time tag itself will be the result of timesince(time).
"""
return mark_safe(
u'<time datetime="{isotime}" title="{time}">{ago}</time>'.format(
ago=timesince(time),
isotime=isotime(time),
time=babel_datetime(time)))


@register.filter
def timesince(t):
Expand Down

0 comments on commit 6ac0a39

Please sign in to comment.