Skip to content

Commit

Permalink
Merge pull request #35 from betagouv/sreuiller/contributions-list-order
Browse files Browse the repository at this point in the history
Liste des contributions : dans l'ordre alphabétique de la thématique de la concertation associée, puis du titre de la contribution
  • Loading branch information
SebastienReuiller authored Aug 4, 2023
2 parents 997cf71 + 8ba4299 commit 6c9429c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions event/tests/test_views_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,29 @@ def test_list_page_department_filter(self):
self.assertNotContains(response, contribution.title, html=True)


class ContributionListViewOrderTest(TestCase):
def setUp(self):
self.url = reverse("contribution_list")

event1 = EventFactory(pub_status=Event.PubStatus.PUB, theme=Event.Theme.BIODIV)
event2 = EventFactory(pub_status=Event.PubStatus.PUB, theme=Event.Theme.ASSIST)
event3 = EventFactory(pub_status=Event.PubStatus.PUB, theme=Event.Theme.SANTE)
self.contribution1 = ContributionFactory(event=event1, title="A", public=True)
self.contribution2 = ContributionFactory(event=event1, title="Z", public=True)
self.contribution3 = ContributionFactory(event=event2, title="T", public=True)
self.contribution4 = ContributionFactory(event=event2, title="S", public=True)
self.contribution5 = ContributionFactory(event=event3, title="B", public=True)

def test_contributions_are_sorted_alphabetically_by_theme_and_title(self):
response = self.client.get(self.url)
contributions_list = response.context["object_list"]
self.assertEqual(contributions_list[0], self.contribution4)
self.assertEqual(contributions_list[1], self.contribution3)
self.assertEqual(contributions_list[2], self.contribution1)
self.assertEqual(contributions_list[3], self.contribution2)
self.assertEqual(contributions_list[4], self.contribution5)


class ContributionDetailViewTest(TestCase):
def test_anonymous_user_cannot_see_not_public_contribution(self):
contribution = ContributionFactory(public=False)
Expand Down
2 changes: 1 addition & 1 deletion event/views/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_queryset(self):
filter_department = self.get_department()
if filter_department:
qs = qs.filter(event__zip_code__startswith=filter_department)
return qs.order_by("title")
return qs.order_by("event__theme", "title")

def get_context_data(self, **kwargs):
context = super().get_context_data()
Expand Down

0 comments on commit 6c9429c

Please sign in to comment.