diff --git a/bookwyrm/templates/book/publisher_info.html b/bookwyrm/templates/book/publisher_info.html index e3ffedca8..26d8e43fd 100644 --- a/bookwyrm/templates/book/publisher_info.html +++ b/bookwyrm/templates/book/publisher_info.html @@ -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 %} diff --git a/bookwyrm/templatetags/sealed_dates.py b/bookwyrm/templatetags/sealed_dates.py new file mode 100644 index 000000000..fb64734fa --- /dev/null +++ b/bookwyrm/templatetags/sealed_dates.py @@ -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)