Filter for concise status timestamps

This commit is contained in:
Mouse Reeve 2021-05-11 18:59:31 -07:00
parent 1ea07448c3
commit 3b9fed1b31
2 changed files with 18 additions and 2 deletions

View file

@ -92,7 +92,7 @@
</h3>
<p class="is-size-7 is-flex is-align-items-center">
<a href="{{ status.remote_id }}">{{ status.published_date|timesince }}</a>
<a href="{{ status.remote_id }}">{{ status.published_date|published_date }}</a>
{% if status.progress %}
<span class="ml-1">
{% if status.progress_mode == 'PG' %}

View file

@ -1,6 +1,8 @@
""" template filters """
from dateutil.relativedelta import relativedelta
from django import template
from django.contrib.humanize.templatetags.humanize import naturaltime, naturalday
from django.utils import timezone
from bookwyrm import models
from bookwyrm.templatetags.utilities import get_user_identifier
@ -41,3 +43,17 @@ def get_parent(status):
def get_boosted(boost):
"""load a boosted status. have to do this or it won't get foreign keys"""
return models.Status.objects.select_subclasses().get(id=boost.boosted_status.id)
@register.filter(name="published_date")
def get_published_date(date):
"""less verbose combo of humanize filters"""
if not date:
return ""
now = timezone.now()
delta = relativedelta(now, date)
if delta.years:
return naturalday(date)
if delta.days:
return naturalday(date, "M j")
return naturaltime(date)