From 69894d2edb10fd96a868eb6b76a44adf195b0a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Fri, 4 Aug 2023 12:01:51 +0200 Subject: [PATCH] hide pagination when not needed --- event/tests/test_views_participant.py | 46 ++++++++++++++++++++++++++ templates/event/contribution_list.html | 8 +++-- templates/event/event_list.html | 8 +++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/event/tests/test_views_participant.py b/event/tests/test_views_participant.py index cb11330..4328210 100644 --- a/event/tests/test_views_participant.py +++ b/event/tests/test_views_participant.py @@ -106,6 +106,29 @@ def test_events_are_sorted_alphabetically_by_theme_and_subject(self): self.assertEqual(events_list[4], self.event5) +class EventListViewPaginationTest(TestCase): + def setUp(self): + self.url = reverse("event_list") + + def test_list_page_pagination_visibility(self): + response = self.client.get(self.url) + self.assertNotContains(response, "Page suivante") + + EventFactory.create_batch(10, pub_status=Event.PubStatus.PUB) + response = self.client.get(self.url) + self.assertNotContains(response, "Page suivante") + + # Paginate by 10 + EventFactory(pub_status=Event.PubStatus.PUB) + response = self.client.get(self.url) + self.assertContains(response, "Page suivante") + self.assertContains(response, "?page=2") + + response = self.client.get(f"{self.url}?page=2") + self.assertContains(response, "Page précédente") + self.assertContains(response, self.url) + + class EventRegistrationViewTest(TestCase): def setUp(self): respx.post(settings.BREVO_SMTP_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) @@ -267,6 +290,29 @@ def test_contributions_are_sorted_alphabetically_by_theme_and_title(self): self.assertEqual(contributions_list[4], self.contribution5) +class ContributionListViewPaginationTest(TestCase): + def setUp(self): + self.url = reverse("contribution_list") + + def test_list_page_pagination_visibility(self): + response = self.client.get(self.url) + self.assertNotContains(response, "Page suivante") + + ContributionFactory.create_batch(10, public=True, event__pub_status=Event.PubStatus.PUB) + response = self.client.get(self.url) + self.assertNotContains(response, "Page suivante") + + # Paginate by 10 + ContributionFactory(public=True, event__pub_status=Event.PubStatus.PUB) + response = self.client.get(self.url) + self.assertContains(response, "Page suivante") + self.assertContains(response, "?page=2") + + response = self.client.get(f"{self.url}?page=2") + self.assertContains(response, "Page précédente") + self.assertContains(response, self.url) + + class ContributionDetailViewTest(TestCase): def test_anonymous_user_cannot_see_not_public_contribution(self): contribution = ContributionFactory(public=False) diff --git a/templates/event/contribution_list.html b/templates/event/contribution_list.html index a004385..17f9164 100644 --- a/templates/event/contribution_list.html +++ b/templates/event/contribution_list.html @@ -46,8 +46,10 @@

{{ paginator.count }} résultat{{ paginator.count|pluralizefr -
- {% dsfr_pagination page_obj %} -
+ {% if page_obj.paginator.num_pages > 1 %} +
+ {% dsfr_pagination page_obj %} +
+ {% endif %} {% endblock %} diff --git a/templates/event/event_list.html b/templates/event/event_list.html index 2b8fbbd..bc97dbe 100644 --- a/templates/event/event_list.html +++ b/templates/event/event_list.html @@ -46,8 +46,10 @@

{{ paginator.count }} résultat{{ paginator.count|pluralizefr -
- {% dsfr_pagination page_obj %} -
+ {% if page_obj.paginator.num_pages > 1 %} +
+ {% dsfr_pagination page_obj %} +
+ {% endif %} {% endblock %}