1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 01:26:54 +00:00

Test calendar

This commit is contained in:
Yohann D'ANELLO 2020-11-03 16:26:43 +01:00
parent f422212aea
commit e73bb2d18b

View File

@ -171,10 +171,12 @@ class PhaseForm(forms.ModelForm):
def clean(self):
# Ensure that dates are in a right order
cleaned_data = super().clean()
if cleaned_data["end"] <= cleaned_data["start"]:
start = cleaned_data["start"]
end = cleaned_data["end"]
if end <= start:
self.add_error("end", _("Start date must be before the end date."))
if Phase.objects.filter(phase_number__lt=self.instance.phase_number, end__gt=cleaned_data["start"]).exists():
if Phase.objects.filter(phase_number__lt=self.instance.phase_number, end__gt=start).exists():
self.add_error("start", _("This phase must start after the previous phases."))
if Phase.objects.filter(phase_number__gt=self.instance.phase_number, start__lt=cleaned_data["end"]).exists():
if Phase.objects.filter(phase_number__gt=self.instance.phase_number, start__lt=end).exists():
self.add_error("end", _("This phase must end after the next phases."))
return cleaned_data