Add template caching for listing components

This commit is contained in:
Jake Howard 2022-10-02 17:27:55 +01:00
parent 6775a336e1
commit 23b8454fe4
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 45 additions and 33 deletions

View file

@ -68,6 +68,8 @@ exclude = '''
| referrallink_snippet_link\.html
| onlineaccount_snippet_link\.html
| 500\.html
| content-details\.html
| listing-item\.html
)
'''

View file

@ -1,7 +1,7 @@
{% load wagtailcore_tags humanize_tags %}
{% load wagtailcore_tags humanize_tags cache util_tags %}
{% cache 600|jitter:60 "content-details" page.id request.is_preview %}
<div class="content-details field is-grouped">
{% if page.date %}
<span class="icon-text">
<span class="icon">
@ -33,3 +33,4 @@
</div>
{% endif %}
</div>
{% endcache %}

View file

@ -1,4 +1,4 @@
{% load wagtailcore_tags %}
{% load wagtailcore_tags cache util_tags %}
<article class="media listing-item">
<div class="columns">
@ -13,7 +13,9 @@
<div>
<h2 class="title is-3"><a href="{% pageurl page %}">{{ page.title }}</a></h2>
{% include "common/content-details.html" %}
{% cache 900|jitter:60 "summary" page.id request.is_preview %}
<p>{{ page.summary }}</p>
{% endcache %}
</div>
</div>
</div>

View file

@ -1,3 +1,5 @@
import random
from django.template import Library
from django.utils.encoding import force_str
from wagtail.models import Page
@ -18,6 +20,11 @@ def pagefullurl(context: dict, page: Page) -> str:
return page.get_full_url(context["request"])
@register.filter()
def jitter(original: float, jitter: float) -> float:
return random.uniform(original + jitter, original - jitter)
@register.filter()
def extract_text(html: str | RichText) -> str:
return utils.extract_text(force_str(html))