Replace humanize with hack around django built-in
This commit is contained in:
parent
385fae7fe1
commit
019e0cf431
5 changed files with 11 additions and 12 deletions
|
@ -14,7 +14,6 @@ psycopg2==2.9.6
|
||||||
djangorestframework
|
djangorestframework
|
||||||
django-htmx==1.14.0
|
django-htmx==1.14.0
|
||||||
wagtail-metadata==4.0.3
|
wagtail-metadata==4.0.3
|
||||||
humanize==4.6.0
|
|
||||||
django-plausible==0.5.0
|
django-plausible==0.5.0
|
||||||
sentry-sdk==1.25.0
|
sentry-sdk==1.25.0
|
||||||
django-sri==0.6.0
|
django-sri==0.6.0
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, Optional, Type
|
from typing import Any, Optional, Type
|
||||||
|
|
||||||
|
from django.contrib.humanize.templatetags.humanize import NaturalTimeFormatter
|
||||||
from django.contrib.syndication.views import Feed
|
from django.contrib.syndication.views import Feed
|
||||||
from django.core.paginator import EmptyPage
|
from django.core.paginator import EmptyPage
|
||||||
from django.core.paginator import Page as PaginatorPage
|
from django.core.paginator import Page as PaginatorPage
|
||||||
|
@ -8,6 +9,7 @@ from django.core.paginator import Paginator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.http.response import Http404, HttpResponse, HttpResponseBadRequest
|
from django.http.response import Http404, HttpResponse, HttpResponseBadRequest
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.functional import cached_property, classproperty
|
from django.utils.functional import cached_property, classproperty
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
|
@ -113,6 +115,12 @@ class BaseContentPage(BasePage, MetadataMixin):
|
||||||
"""
|
"""
|
||||||
return timedelta(seconds=(self.word_count / 265) * 60)
|
return timedelta(seconds=(self.word_count / 265) * 60)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def reading_time_display(self) -> str:
|
||||||
|
return NaturalTimeFormatter.string_for(
|
||||||
|
timezone.now() - self.reading_time
|
||||||
|
).removesuffix(" ago")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def show_reading_time(self) -> bool:
|
def show_reading_time(self) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load wagtailcore_tags humanize_tags cache util_tags %}
|
{% load wagtailcore_tags cache util_tags %}
|
||||||
|
|
||||||
{% cache FRAGMENT_CACHE_TTL|jitter:FRAGMENT_CACHE_TTL_JITTER "content-details" page.id request.is_preview %}
|
{% cache FRAGMENT_CACHE_TTL|jitter:FRAGMENT_CACHE_TTL_JITTER "content-details" page.id request.is_preview %}
|
||||||
<div class="content-details field is-grouped">
|
<div class="content-details field is-grouped">
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
<i class="far fa-lg fa-clock"></i>
|
<i class="far fa-lg fa-clock"></i>
|
||||||
</span>
|
</span>
|
||||||
<span>{{ page.reading_time|naturaldelta }}</span>
|
<span>{{ page.reading_time_display }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
{% extends "wagtailmetadata/parts/tags.html" %}
|
{% extends "wagtailmetadata/parts/tags.html" %}
|
||||||
|
|
||||||
{% load humanize_tags %}
|
|
||||||
|
|
||||||
{% block twitter %}
|
{% block twitter %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
{% if object.show_reading_time %}
|
{% if object.show_reading_time %}
|
||||||
<meta name="twitter:label1" content="Reading time" />
|
<meta name="twitter:label1" content="Reading time" />
|
||||||
<meta name="twitter:data1" content="{{ object.reading_time|naturaldelta }}" />
|
<meta name="twitter:data1" content="{{ object.reading_time_display }}" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
import humanize
|
|
||||||
from django.template import Library
|
|
||||||
|
|
||||||
register = Library()
|
|
||||||
|
|
||||||
register.filter(humanize.naturaldelta)
|
|
Loading…
Reference in a new issue