From c17f95d4fae6006d1b2b11c8fde2079c84bdcff0 Mon Sep 17 00:00:00 2001 From: Chatewgne Date: Tue, 2 Jan 2024 12:40:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20[IMPR]=20Prevent=20from=20enteri?= =?UTF-8?q?ng=20end=20date=20before=20start=20date=20in=20intervention=20f?= =?UTF-8?q?orm=20(refs=20#3825)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geotrek/maintenance/forms.py | 14 +++++++++++++- .../maintenance/locale/fr/LC_MESSAGES/django.po | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/geotrek/maintenance/forms.py b/geotrek/maintenance/forms.py index 10b514d225..5e170c9037 100644 --- a/geotrek/maintenance/forms.py +++ b/geotrek/maintenance/forms.py @@ -1,3 +1,5 @@ +from datetime import datetime + from crispy_forms.helper import FormHelper from crispy_forms.layout import Div, Fieldset, Layout from django import forms @@ -7,7 +9,6 @@ from django.forms import FloatField from django.forms.models import inlineformset_factory from django.utils.translation import gettext_lazy as _ - from geotrek.common.forms import CommonForm from geotrek.core.fields import TopologyField from geotrek.core.models import Topology @@ -154,6 +155,17 @@ def __init__(self, *args, target_type=None, target_id=None, **kwargs): if self.instance.pk and self.instance.target and hasattr(self.instance.target, "report_interventions"): self.fields["end_date"].required = True + + def clean(self, *args, **kwargs): + clean_data = super().clean(*args, **kwargs) + begin_date = clean_data.get('begin_date') + end_date = clean_data.get('end_date') + if not end_date: + pass + if begin_date > end_date: + self.add_error('end_date', _('Begin date is after end date')) + return clean_data + def save(self, *args, **kwargs): target = self.instance.target if 'geotrek.feedback' in settings.INSTALLED_APPS and settings.SURICATE_WORKFLOW_ENABLED and isinstance(target, Report): diff --git a/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po b/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po index bbedb09c31..6637f48ce8 100644 --- a/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po +++ b/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po @@ -118,6 +118,9 @@ msgstr "Tronçons" msgid "On {}" msgstr "Sur {}" +msgid "Begin date is after end date" +msgstr "La date de début est après la date de fin" + msgid "Fundings" msgstr "Financements"