Ensure request is passed into the singleton URL cache
This removes needing extra queries
This commit is contained in:
parent
25e49de081
commit
df09ec0f38
8 changed files with 16 additions and 14 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<nav class="navbar is-family-code" role="navigation" aria-label="main navigation">
|
<nav class="navbar is-family-code" role="navigation" aria-label="main navigation">
|
||||||
<div class="navbar-brand">
|
<div class="navbar-brand">
|
||||||
<a class="navbar-item home-link" href="{% pageurl homepage %}">
|
<a class="navbar-item home-link" href="{{ homepage_url }}">
|
||||||
/home/theorangeone
|
/home/theorangeone
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@ from website.home.models import HomePage
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag("common/footer.html")
|
@register.inclusion_tag("common/footer.html", takes_context=True)
|
||||||
def footer() -> dict:
|
def footer(context: dict) -> dict:
|
||||||
|
request = context["request"]
|
||||||
return {
|
return {
|
||||||
"homepage_url": SingletonPageCache.get_url(HomePage),
|
"homepage_url": SingletonPageCache.get_url(HomePage, request),
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,16 @@ from website.search.models import SearchPage
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag("common/navbar.html")
|
@register.inclusion_tag("common/navbar.html", takes_context=True)
|
||||||
def navbar() -> dict:
|
def navbar(context: dict) -> dict:
|
||||||
homepage = HomePage.objects.live().get()
|
request = context["request"]
|
||||||
|
homepage = HomePage.objects.get()
|
||||||
return {
|
return {
|
||||||
"homepage": homepage,
|
"homepage_url": SingletonPageCache.get_url(HomePage, request),
|
||||||
"nav_pages": homepage.get_children()
|
"nav_pages": homepage.get_children()
|
||||||
.live()
|
.live()
|
||||||
.public()
|
.public()
|
||||||
.filter(show_in_menus=True)
|
.filter(show_in_menus=True)
|
||||||
.order_by("title"),
|
.order_by("title"),
|
||||||
"search_page_url": SingletonPageCache.get_url(SearchPage),
|
"search_page_url": SingletonPageCache.get_url(SearchPage, request),
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ListingPageTestCase(TestCase):
|
||||||
ContentPageFactory(parent=cls.page)
|
ContentPageFactory(parent=cls.page)
|
||||||
|
|
||||||
def test_accessible(self) -> None:
|
def test_accessible(self) -> None:
|
||||||
with self.assertNumQueries(33):
|
with self.assertNumQueries(32):
|
||||||
response = self.client.get(self.page.url)
|
response = self.client.get(self.page.url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(len(response.context["listing_pages"]), 2)
|
self.assertEqual(len(response.context["listing_pages"]), 2)
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Error404PageTestCase(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_queries(self) -> None:
|
def test_queries(self) -> None:
|
||||||
with self.assertNumQueries(17):
|
with self.assertNumQueries(16):
|
||||||
self.client.get(self.url)
|
self.client.get(self.url)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,5 +49,5 @@ class HomePage(BasePage, WagtailImageMetadataMixin):
|
||||||
.order_by("-date")
|
.order_by("-date")
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
context["search_page_url"] = SingletonPageCache.get_url(SearchPage)
|
context["search_page_url"] = SingletonPageCache.get_url(SearchPage, request)
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -89,7 +89,7 @@ class SearchPageResultsTestCase(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_too_high_page(self) -> None:
|
def test_too_high_page(self) -> None:
|
||||||
with self.assertNumQueries(48):
|
with self.assertNumQueries(46):
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
self.url, {"q": "post", "page": 3}, HTTP_HX_REQUEST="true"
|
self.url, {"q": "post", "page": 3}, HTTP_HX_REQUEST="true"
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,7 +24,7 @@ class SecurityView(TemplateView):
|
||||||
def get_context_data(self, **kwargs: dict) -> dict:
|
def get_context_data(self, **kwargs: dict) -> dict:
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["security_txt"] = self.request.build_absolute_uri(self.request.path)
|
context["security_txt"] = self.request.build_absolute_uri(self.request.path)
|
||||||
contact_page_path = SingletonPageCache.get_url(ContactPage)
|
contact_page_path = SingletonPageCache.get_url(ContactPage, self.request)
|
||||||
context["contact_page_url"] = (
|
context["contact_page_url"] = (
|
||||||
self.request.build_absolute_uri(contact_page_path)
|
self.request.build_absolute_uri(contact_page_path)
|
||||||
if contact_page_path
|
if contact_page_path
|
||||||
|
|
Loading…
Reference in a new issue