Merge pull request #1080 from bookwyrm-social/concise-dates

Filter for concise status timestamps
This commit is contained in:
Mouse Reeve 2021-05-12 09:41:38 -07:00 committed by GitHub
commit e011fe6f88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

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

View file

@ -1,6 +1,8 @@
""" template filters """ """ template filters """
from dateutil.relativedelta import relativedelta
from django import template from django import template
from django.contrib.humanize.templatetags.humanize import naturaltime, naturalday
from django.utils import timezone
from bookwyrm import models from bookwyrm import models
from bookwyrm.templatetags.utilities import get_user_identifier from bookwyrm.templatetags.utilities import get_user_identifier
@ -41,3 +43,17 @@ def get_parent(status):
def get_boosted(boost): def get_boosted(boost):
"""load a boosted status. have to do this or it won't get foreign keys""" """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) 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)