aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--development.ini1
-rw-r--r--fietsboek/jinja2.py19
-rw-r--r--fietsboek/templates/details.jinja28
3 files changed, 24 insertions, 4 deletions
diff --git a/development.ini b/development.ini
index fb46605..153e684 100644
--- a/development.ini
+++ b/development.ini
@@ -18,6 +18,7 @@ pyramid.includes =
pyramid_debugtoolbar
jinja2.filters =
format_decimal = fietsboek.jinja2.filter_format_decimal
+ format_datetime = fietsboek.jinja2.filter_format_datetime
sqlalchemy.url = sqlite:///%(here)s/fietsboek.sqlite
diff --git a/fietsboek/jinja2.py b/fietsboek/jinja2.py
index b940d74..def61a6 100644
--- a/fietsboek/jinja2.py
+++ b/fietsboek/jinja2.py
@@ -2,6 +2,7 @@
import jinja2
from babel.numbers import format_decimal
+from babel.dates import format_datetime
@jinja2.pass_context
@@ -14,7 +15,25 @@ def filter_format_decimal(ctx, value):
:type ctx: jinja2.runtime.Context
:param value: The value to format.
:type value: float
+ :return: The formatted decimal.
+ :rtype: str
"""
request = ctx.get('request')
locale = request.localizer.locale_name
return format_decimal(value, locale=locale)
+
+
+@jinja2.pass_context
+def filter_format_datetime(ctx, value):
+ """Format a datetime according to the locale.
+
+ :param ctx: The jinja context, passed automatically.
+ :type ctx: jinja2.runtime.Context
+ :param value: The value to format.
+ :type value: datetime.datetime
+ :return: The formatted date.
+ :rtype: str
+ """
+ request = ctx.get('request')
+ locale = request.localizer.locale_name
+ return format_datetime(value, locale=locale)
diff --git a/fietsboek/templates/details.jinja2 b/fietsboek/templates/details.jinja2
index bf87b9f..f626730 100644
--- a/fietsboek/templates/details.jinja2
+++ b/fietsboek/templates/details.jinja2
@@ -61,15 +61,15 @@
<tbody>
<tr>
<th scope="row">{{ _("page.details.date") }}</th>
- <td>{{ track.date }}</td>
+ <td>{{ track.date | format_datetime }}</td>
</tr>
<tr>
<th scope="row">{{ _("page.details.start_time") }}</th>
- <td>{{ track.start_time }}</td>
+ <td>{{ track.start_time | format_datetime }}</td>
</tr>
<tr>
<th scope="row">{{ _("page.details.end_time") }}</th>
- <td>{{ track.end_time }}</td>
+ <td>{{ track.end_time | format_datetime }}</td>
</tr>
<tr>
<th scope="row">{{ _("page.details.length") }}</th>
@@ -125,7 +125,7 @@
{{ comment_md_to_html(comment.text) }}
</div>
<div class="card-footer text-muted">
- {{ comment.date }}
+ {{ comment.date | format_datetime }}
</div>
</div>
{% endfor %}