Remove trailing question-mark

This commit is contained in:
Jake Howard 2023-10-22 15:26:28 +01:00
parent 6b53c42f14
commit 9a8166a39e
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 21 additions and 2 deletions

View file

@ -274,7 +274,13 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
query_data = self.serializer.validated_data.copy()
if query_data["page"] == 1:
del query_data["page"]
return super().get_meta_url() + "?" + urlencode(query_data)
url = super().get_meta_url()
if not query_data:
return url
return url + "?" + urlencode(query_data)
@route(r"^feed/$")
@method_decorator(cache_page(60 * 30))

View file

@ -2,7 +2,7 @@ from django.template.loader import get_template
from django.test import SimpleTestCase, TestCase
from website.common.factories import ContentPageFactory, ListingPageFactory
from website.common.models import BasePage
from website.common.models import BaseListingPage, BasePage
from website.common.utils import get_page_models
from website.home.models import HomePage
@ -66,3 +66,16 @@ class ListingPageTestCase(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/xml")
self.assertContains(response, "xml-stylesheet")
def test_meta_url(self) -> None:
response = self.client.get(self.page.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["page"].get_meta_url(), self.page.full_url)
def test_meta_url_with_page(self) -> None:
ContentPageFactory.create_batch(BaseListingPage.PAGE_SIZE, parent=self.page)
response = self.client.get(self.page.url, {"page": 2})
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.context["page"].get_meta_url(), self.page.full_url + "?page=2"
)