Use singleton URL cache

This commit is contained in:
Jake Howard 2022-08-28 20:22:55 +01:00
parent 7a4388bd69
commit 442aeb21b8
Signed by: jake
GPG Key ID: 57AFB45680EDD477
9 changed files with 16 additions and 13 deletions

View File

@ -109,7 +109,7 @@ class BlogPostCollectionListPage(BaseListingPage):
]
def get_listing_pages(self) -> models.QuerySet:
blog_list_page = BlogPostListPage.objects.all().live().get()
blog_list_page = BlogPostListPage.objects.get()
return BlogPostCollectionPage.objects.child_of(blog_list_page).live().public()

View File

@ -3,7 +3,7 @@
<footer class="footer">
<div class="content has-text-centered">
<p>
&copy; <a href="{% pageurl homepage %}">TheOrangeOne</a> {% now "Y" %}
&copy; <a href="{{ homepage_url }}">TheOrangeOne</a> {% now "Y" %}
</p>
<p id="to-top" class="is-size-7">
<a class="scroll-top">To top</a>

View File

@ -28,8 +28,8 @@
<i class="fa-solid fa-circle-half-stroke" aria-hidden="true"></i>
</span>
</a>
{% if search_page %}
<a class="navbar-item navbar-icon" href="{% pageurl search_page %}">
{% if search_page_url %}
<a class="navbar-item navbar-icon" href="{{ search_page_url }}">
<span class="icon">
<i class="fas fa-search" aria-hidden="true"></i>
</span>

View File

@ -1,5 +1,6 @@
from django.template import Library
from website.contrib.singleton_url.utils import SingletonURLCache
from website.home.models import HomePage
register = Library()
@ -8,5 +9,5 @@ register = Library()
@register.inclusion_tag("common/footer.html")
def footer() -> dict:
return {
"homepage": HomePage.objects.get(),
"homepage_url": SingletonURLCache.get_url(HomePage),
}

View File

@ -1,5 +1,6 @@
from django.template import Library
from website.contrib.singleton_url.utils import SingletonURLCache
from website.home.models import HomePage
from website.search.models import SearchPage
@ -16,5 +17,5 @@ def navbar() -> dict:
.public()
.filter(show_in_menus=True)
.order_by("title"),
"search_page": SearchPage.objects.defer_streamfields().first(),
"search_page_url": SingletonURLCache.get_url(SearchPage),
}

View File

@ -6,6 +6,7 @@ from wagtail.images.models import Image
from wagtailmetadata.models import WagtailImageMetadataMixin
from website.common.models import BasePage
from website.contrib.singleton_url.utils import SingletonURLCache
class HomePage(BasePage, WagtailImageMetadataMixin):
@ -48,5 +49,5 @@ class HomePage(BasePage, WagtailImageMetadataMixin):
.order_by("-date")
.first()
)
context["search_page"] = SearchPage.objects.defer_streamfields().first()
context["search_page_url"] = SingletonURLCache.get_url(SearchPage)
return context

View File

@ -6,8 +6,8 @@
<main {% if page.image %}style="background-image: url({% image_url page.image 'width-1200' %})"{% endif %}>
<div class="heading-wrapper">
<h1>{{ page.heading }}</h1>
{% if search_page %}
<form action="{% pageurl search_page %}">
{% if search_page_url %}
<form action="{{ search_page_url }}">
<input id="search-input" class="input" type="text" placeholder="Search" name="q">
</form>
{% endif %}

View File

@ -1,6 +1,5 @@
{% load wagtailcore_tags %}
{% if contact_page %}
Contact: {% pageurl contact_page %}
{% if contact_page_url %}
Contact: {{ contact_page_url }}
{% endif %}
Canonical: {{ security_txt }}
Expires: {{ expires }}

View File

@ -8,6 +8,7 @@ from django.views.decorators.cache import cache_page
from django.views.generic import TemplateView
from website.contact.models import ContactPage
from website.contrib.singleton_url.utils import SingletonURLCache
class SecurityView(TemplateView):
@ -23,7 +24,7 @@ class SecurityView(TemplateView):
def get_context_data(self, **kwargs: dict) -> dict:
context = super().get_context_data(**kwargs)
context["security_txt"] = self.request.build_absolute_uri(self.request.path)
context["contact_page"] = ContactPage.objects.first()
context["contact_page_url"] = SingletonURLCache.get_url(ContactPage)
context["expires"] = (
(timezone.now() + self.expires).replace(microsecond=0).isoformat()
)