mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Filter for concise status timestamps
This commit is contained in:
parent
1ea07448c3
commit
3b9fed1b31
2 changed files with 18 additions and 2 deletions
|
@ -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' %}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue