Skip to content

Commit

Permalink
💫 [IMPR] Prevent from entering end date before start date in interven…
Browse files Browse the repository at this point in the history
…tion form (refs #3825)
  • Loading branch information
Chatewgne committed Jan 2, 2024
1 parent 3cbfb31 commit c17f95d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion geotrek/maintenance/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions geotrek/maintenance/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit c17f95d

Please sign in to comment.