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">
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item home-link" href="{% pageurl homepage %}">
|
||||
<a class="navbar-item home-link" href="{{ homepage_url }}">
|
||||
/home/theorangeone
|
||||
</a>
|
||||
|
||||
|
|
|
@ -6,8 +6,9 @@ from website.home.models import HomePage
|
|||
register = Library()
|
||||
|
||||
|
||||
@register.inclusion_tag("common/footer.html")
|
||||
def footer() -> dict:
|
||||
@register.inclusion_tag("common/footer.html", takes_context=True)
|
||||
def footer(context: dict) -> dict:
|
||||
request = context["request"]
|
||||
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.inclusion_tag("common/navbar.html")
|
||||
def navbar() -> dict:
|
||||
homepage = HomePage.objects.live().get()
|
||||
@register.inclusion_tag("common/navbar.html", takes_context=True)
|
||||
def navbar(context: dict) -> dict:
|
||||
request = context["request"]
|
||||
homepage = HomePage.objects.get()
|
||||
return {
|
||||
"homepage": homepage,
|
||||
"homepage_url": SingletonPageCache.get_url(HomePage, request),
|
||||
"nav_pages": homepage.get_children()
|
||||
.live()
|
||||
.public()
|
||||
.filter(show_in_menus=True)
|
||||
.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)
|
||||
|
||||
def test_accessible(self) -> None:
|
||||
with self.assertNumQueries(33):
|
||||
with self.assertNumQueries(32):
|
||||
response = self.client.get(self.page.url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response.context["listing_pages"]), 2)
|
||||
|
|
|
@ -16,7 +16,7 @@ class Error404PageTestCase(TestCase):
|
|||
)
|
||||
|
||||
def test_queries(self) -> None:
|
||||
with self.assertNumQueries(17):
|
||||
with self.assertNumQueries(16):
|
||||
self.client.get(self.url)
|
||||
|
||||
|
||||
|
|
|
@ -49,5 +49,5 @@ class HomePage(BasePage, WagtailImageMetadataMixin):
|
|||
.order_by("-date")
|
||||
.first()
|
||||
)
|
||||
context["search_page_url"] = SingletonPageCache.get_url(SearchPage)
|
||||
context["search_page_url"] = SingletonPageCache.get_url(SearchPage, request)
|
||||
return context
|
||||
|
|
|
@ -89,7 +89,7 @@ class SearchPageResultsTestCase(TestCase):
|
|||
)
|
||||
|
||||
def test_too_high_page(self) -> None:
|
||||
with self.assertNumQueries(48):
|
||||
with self.assertNumQueries(46):
|
||||
response = self.client.get(
|
||||
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:
|
||||
context = super().get_context_data(**kwargs)
|
||||
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"] = (
|
||||
self.request.build_absolute_uri(contact_page_path)
|
||||
if contact_page_path
|
||||
|
|
Loading…
Reference in a new issue