Skip to content

Commit

Permalink
clean locations if not geo range zone
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Oct 15, 2024
1 parent ed2fe1b commit c8f2a34
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lemarche/www/dashboard_siaes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit c8f2a34

Please sign in to comment.