Use relative URL for singletons

It's rare they'll be needed externally, and this way there's less to do
This commit is contained in:
Jake Howard 2022-08-31 09:12:16 +01:00
parent ce3690384e
commit 27dc383d17
Signed by: jake
GPG Key ID: 57AFB45680EDD477
3 changed files with 8 additions and 3 deletions

View File

@ -9,7 +9,7 @@ from .utils import SingletonPageCache
class SingletonURLTestCase(TestCase):
def test_gets_url(self) -> None:
with self.assertNumQueries(2):
self.assertEqual(SingletonPageCache.get_url(HomePage), "http://localhost/")
self.assertEqual(SingletonPageCache.get_url(HomePage), "/")
def test_missing_page(self) -> None:
with self.assertNumQueries(1):

View File

@ -25,7 +25,7 @@ class SingletonPageCache:
if page is None:
return None
url = page.get_full_url(request)
url = page.get_url(request)
cache.set(cache_key, url, 86400)

View File

@ -24,7 +24,12 @@ 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_url"] = SingletonPageCache.get_url(ContactPage)
contact_page_path = SingletonPageCache.get_url(ContactPage)
context["contact_page_url"] = (
self.request.build_absolute_uri(contact_page_path)
if contact_page_path
else None
)
context["expires"] = (
(timezone.now() + self.expires).replace(microsecond=0).isoformat()
)