From 2ca15b41fe16c50a3f6190ec6662dc0769df5726 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 4 Oct 2023 12:10:05 +0200 Subject: [PATCH 1/5] =?UTF-8?q?fix(event):=C2=A0allow=20empty=20to=20preve?= =?UTF-8?q?nt=20404=20response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/event/tests/tests_views.py | 4 ++++ lacommunaute/event/views.py | 1 + 2 files changed, 5 insertions(+) diff --git a/lacommunaute/event/tests/tests_views.py b/lacommunaute/event/tests/tests_views.py index eff6dc04b..5fd554933 100644 --- a/lacommunaute/event/tests/tests_views.py +++ b/lacommunaute/event/tests/tests_views.py @@ -226,6 +226,10 @@ def test_view_with_args(self): response = self.client.get(reverse("event:month", kwargs={"year": event.date.year, "month": event.date.month})) self.assertContains(response, event.name, status_code=200) + def test_allow_empty(self): + response = self.client.get(reverse("event:month", kwargs={"year": 2000, "month": 1})) + self.assertContains(response, "Aucun évènement", status_code=200, html=True) + def test_navbar(self): event = EventFactory(date=timezone.now()) event_in_the_future = EventFactory(date=event.date + relativedelta(months=1)) diff --git a/lacommunaute/event/views.py b/lacommunaute/event/views.py index ab4d948ed..91143afc5 100644 --- a/lacommunaute/event/views.py +++ b/lacommunaute/event/views.py @@ -72,6 +72,7 @@ class EventDetailView(DetailView): class EventMonthArchiveView(MonthArchiveView): allow_future = True + allow_empty = True date_field = "date" queryset = Event.objects.all() month_format = "%m" From 14e48ac125ff62e3d97e2a49b537c519ad13025d Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 4 Oct 2023 12:13:31 +0200 Subject: [PATCH 2/5] =?UTF-8?q?fix(event):=C2=A0make=20better=20navbar=20t?= =?UTF-8?q?est?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/event/tests/tests_views.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lacommunaute/event/tests/tests_views.py b/lacommunaute/event/tests/tests_views.py index 5fd554933..126576ef3 100644 --- a/lacommunaute/event/tests/tests_views.py +++ b/lacommunaute/event/tests/tests_views.py @@ -1,9 +1,11 @@ from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta +from django.conf import settings from django.test import TestCase from django.urls import reverse -from django.utils import timezone +from django.utils import timezone, translation +from django.utils.formats import date_format from faker import Faker from lacommunaute.event.factories import EventFactory @@ -231,17 +233,21 @@ def test_allow_empty(self): self.assertContains(response, "Aucun évènement", status_code=200, html=True) def test_navbar(self): - event = EventFactory(date=timezone.now()) - event_in_the_future = EventFactory(date=event.date + relativedelta(months=1)) - event_in_the_past = EventFactory(date=event.date - relativedelta(months=1)) - response = self.client.get(reverse("event:current")) + with translation.override(settings.LANGUAGE_CODE): + current_date = timezone.now() + next_month = current_date + relativedelta(months=1) + previous_month = current_date - relativedelta(months=1) + + response = self.client.get(reverse("event:current")) + self.assertContains(response, date_format(current_date, "F Y"), status_code=200) + self.assertContains( response, reverse( "event:month", kwargs={ - "year": event_in_the_past.date.year, - "month": f"{event_in_the_past.date.month:02d}", + "year": previous_month.year, + "month": f"{previous_month.month:02d}", }, ), status_code=200, @@ -251,8 +257,8 @@ def test_navbar(self): reverse( "event:month", kwargs={ - "year": event_in_the_future.date.year, - "month": f"{event_in_the_future.date.month:02d}", + "year": next_month.year, + "month": f"{next_month.month:02d}", }, ), status_code=200, From 449e2bd9a458f44bfec885c4512d065c38d15f62 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 4 Oct 2023 12:14:59 +0200 Subject: [PATCH 3/5] =?UTF-8?q?fix(event):=C2=A0make=20better=20test=20wit?= =?UTF-8?q?h=20args=20an=20ArchiveMonthView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/event/tests/tests_views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lacommunaute/event/tests/tests_views.py b/lacommunaute/event/tests/tests_views.py index 126576ef3..9f325c6f1 100644 --- a/lacommunaute/event/tests/tests_views.py +++ b/lacommunaute/event/tests/tests_views.py @@ -224,9 +224,13 @@ def test_view_wo_args(self): self.assertContains(response, reverse("event:create")) def test_view_with_args(self): - event = EventFactory(date=timezone.now() + relativedelta(months=1)) - response = self.client.get(reverse("event:month", kwargs={"year": event.date.year, "month": event.date.month})) - self.assertContains(response, event.name, status_code=200) + event = EventFactory(date=timezone.now()) + old_event = EventFactory(date=timezone.now() - relativedelta(months=1)) + response = self.client.get( + reverse("event:month", kwargs={"year": old_event.date.year, "month": old_event.date.month}) + ) + self.assertNotContains(response, event.name, status_code=200) + self.assertContains(response, old_event.name, status_code=200) def test_allow_empty(self): response = self.client.get(reverse("event:month", kwargs={"year": 2000, "month": 1})) From 66109dc41b0848e17ab8376cd5af54a1011c2efa Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 4 Oct 2023 12:15:39 +0200 Subject: [PATCH 4/5] =?UTF-8?q?fix(event):=C2=A0test=20allow=5Ffuture=20on?= =?UTF-8?q?=20ArchiveMonthView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/event/tests/tests_views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lacommunaute/event/tests/tests_views.py b/lacommunaute/event/tests/tests_views.py index 9f325c6f1..0a33c95b1 100644 --- a/lacommunaute/event/tests/tests_views.py +++ b/lacommunaute/event/tests/tests_views.py @@ -232,6 +232,11 @@ def test_view_with_args(self): self.assertNotContains(response, event.name, status_code=200) self.assertContains(response, old_event.name, status_code=200) + def test_allow_future(self): + event = EventFactory(date=timezone.now() + relativedelta(months=1)) + response = self.client.get(reverse("event:month", kwargs={"year": event.date.year, "month": event.date.month})) + self.assertContains(response, event.name, status_code=200) + def test_allow_empty(self): response = self.client.get(reverse("event:month", kwargs={"year": 2000, "month": 1})) self.assertContains(response, "Aucun évènement", status_code=200, html=True) From 7a2ae9de31a97799c36d5a32faf0aa74f9204033 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 4 Oct 2023 12:18:18 +0200 Subject: [PATCH 5/5] =?UTF-8?q?fix(event):=C2=A0add=20missing=20block=20ti?= =?UTF-8?q?tle=20on=20ArchiveMonthView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/templates/event/event_archive_month.html | 1 + 1 file changed, 1 insertion(+) diff --git a/lacommunaute/templates/event/event_archive_month.html b/lacommunaute/templates/event/event_archive_month.html index 94eb24e8a..04cce29db 100644 --- a/lacommunaute/templates/event/event_archive_month.html +++ b/lacommunaute/templates/event/event_archive_month.html @@ -1,6 +1,7 @@ {% extends "layouts/base.html" %} {% load i18n %} +{% block title %}{% trans "Events" %}{{ block.super }}{% endblock %} {% block sub_title %}{% trans "Events" %} {{ month }}{% endblock sub_title %} {% block content %}