mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
naturalday_partial filter for working with SealedDate
This commit is contained in:
parent
46d80d56a5
commit
777c8b4549
2 changed files with 23 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
{% spaceless %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load humanize %}
|
||||
{% load sealed_dates %}
|
||||
|
||||
{% firstof book.physical_format_detail book.get_physical_format_display as format %}
|
||||
{% firstof book.physical_format book.physical_format_detail as format_property %}
|
||||
|
@ -57,7 +57,7 @@
|
|||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% with date=book.published_date|default:book.first_published_date|naturalday publisher=book.publishers|join:', ' %}
|
||||
{% with date=book.published_date|default:book.first_published_date|naturalday_partial publisher=book.publishers|join:', ' %}
|
||||
{% if book.published_date and publisher %}
|
||||
{% blocktrans %}Published {{ date }} by {{ publisher }}.{% endblocktrans %}
|
||||
{% elif publisher %}
|
||||
|
|
21
bookwyrm/templatetags/sealed_dates.py
Normal file
21
bookwyrm/templatetags/sealed_dates.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
""" formatting of SealedDate instances """
|
||||
from django import template
|
||||
from django.template import defaultfilters
|
||||
from django.contrib.humanize.templatetags.humanize import naturalday
|
||||
|
||||
from bookwyrm.utils.sealed_date import SealedDate
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(expects_localtime=True, is_safe=False)
|
||||
def naturalday_partial(date):
|
||||
if not isinstance(date, SealedDate):
|
||||
return defaultfilters.date(date)
|
||||
if date.has_day:
|
||||
fmt = "DATE_FORMAT"
|
||||
elif date.has_month:
|
||||
fmt = "YEAR_MONTH_FORMAT"
|
||||
else:
|
||||
fmt = "Y"
|
||||
return naturalday(date, fmt)
|
Loading…
Reference in a new issue