From c8f2a34567188159fb9dd5c126a940ca4a5eac1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Tue, 8 Oct 2024 15:26:05 +0200 Subject: [PATCH] clean locations if not geo range zone --- lemarche/www/dashboard_siaes/forms.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lemarche/www/dashboard_siaes/forms.py b/lemarche/www/dashboard_siaes/forms.py index 8b9928082..cc6fd93b1 100644 --- a/lemarche/www/dashboard_siaes/forms.py +++ b/lemarche/www/dashboard_siaes/forms.py @@ -307,14 +307,13 @@ def clean(self): if geo_range == siae_constants.GEO_RANGE_CUSTOM and not geo_range_custom_distance: self.add_error("geo_range_custom_distance", "Une distance en kilomètres est requise pour cette option.") - # TODO: check if locations are set if geo_range is set to ZONES + if geo_range == siae_constants.GEO_RANGE_ZONES: + if not cleaned_data.get("locations"): + self.add_error(None, "Vous devez choisir au moins une zone d'intervention personnalisée.") + else: + cleaned_data["locations"] = [] return cleaned_data - def save(self, *args, **kwargs): - if self.instance.pk and self.cleaned_data.get("geo_range") is not siae_constants.GEO_RANGE_ZONES: - self.instance.locations.clear() - return super().save(*args, **kwargs) - class Meta: model = SiaeActivity fields = [