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 e9c5217
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
12 changes: 11 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,15 @@ 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 end_date and 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
</tr>
<tr>
<th>{{ intervention|verbose:"end_date" }}</th>
<td>{{ intervention.end_date }}</td>
<td>{% if intervention.end_date %}{{ intervention.end_date }}
{% else %}<span class="none">{% trans "None" %}</span>{% endif %}
</td>
</tr>
<tr>
<th>{{ intervention|verbose:"stake" }}</th>
Expand Down

0 comments on commit e9c5217

Please sign in to comment.