8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Fix form validation

This commit is contained in:
Hugo Levy-Falk 2019-09-28 12:38:57 +02:00 committed by chirac
parent b38521db69
commit 5c0a4ce748

View file

@ -300,15 +300,16 @@ class MandateForm(ModelForm):
def clean(self): def clean(self):
cleaned_data = super(MandateForm, self).clean() cleaned_data = super(MandateForm, self).clean()
start_date, end_date = cleaned_data['start_date'], cleaned_data['end_date'] start_date, end_date = cleaned_data['start_date'], cleaned_data['end_date']
included_mandates = Mandate.objects.filter( if end_date:
Q(start_date__gte=start_date, start_date__lt=end_date) included_mandates = Mandate.objects.filter(
| Q(end_date__gt=start_date, end_date__lte=end_date) Q(start_date__gte=start_date, start_date__lt=end_date)
) | Q(end_date__gt=start_date, end_date__lte=end_date)
if included_mandates:
raise forms.ValidationError(
_("The specified dates overlap with an existing mandate."),
code='invalid'
) )
if included_mandates:
raise forms.ValidationError(
_("The specified dates overlap with an existing mandate."),
code='invalid'
)
return cleaned_data return cleaned_data
def save(self, commit=True): def save(self, commit=True):