Add template caching for listing components
This commit is contained in:
parent
6775a336e1
commit
23b8454fe4
4 changed files with 45 additions and 33 deletions
|
@ -68,6 +68,8 @@ exclude = '''
|
|||
| referrallink_snippet_link\.html
|
||||
| onlineaccount_snippet_link\.html
|
||||
| 500\.html
|
||||
| content-details\.html
|
||||
| listing-item\.html
|
||||
)
|
||||
'''
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% load wagtailcore_tags humanize_tags %}
|
||||
|
||||
<div class="content-details field is-grouped">
|
||||
{% 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">
|
||||
|
@ -32,4 +32,5 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endcache %}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue