diff --git a/website/common/models.py b/website/common/models.py index 427b397..5b0642e 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -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)) diff --git a/website/common/tests/test_pages.py b/website/common/tests/test_pages.py index 9968746..8dfffb4 100644 --- a/website/common/tests/test_pages.py +++ b/website/common/tests/test_pages.py @@ -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" + )