feat: re-add locate to ease use

This commit is contained in:
moanos [he/him] 2025-01-01 09:44:56 +01:00
parent e8b3bf6516
commit e2adb20231

View File

@ -28,7 +28,7 @@ class Search:
self.sex = None self.sex = None
self.area_search = None self.area_search = None
self.max_distance = None self.max_distance = None
self.location = None self.location = None # Can either be Location (DjangoModel) or LocationProxy
self.place_not_found = False # Indicates that a location was given but could not be geocoded self.place_not_found = False # Indicates that a location was given but could not be geocoded
self.search_form = None self.search_form = None
@ -55,6 +55,12 @@ class Search:
return False return False
return self.location == other.location and self.sex == other.sex and self.max_distance == other.max_distance return self.location == other.location and self.sex == other.sex and self.max_distance == other.max_distance
def _locate(self):
try:
self.location = LocationProxy(self.location_string)
except ValueError:
self.place_not_found = True
def adoption_notice_fits_search(self, adoption_notice: AdoptionNotice): def adoption_notice_fits_search(self, adoption_notice: AdoptionNotice):
# Make sure sex is set and sex is not set to all (then it can be disregarded) # Make sure sex is set and sex is not set to all (then it can be disregarded)
if self.sex is not None and self.sex != SexChoicesWithAll.ALL: if self.sex is not None and self.sex != SexChoicesWithAll.ALL:
@ -88,11 +94,7 @@ class Search:
self.area_search = True self.area_search = True
self.location_string = self.search_form.cleaned_data["location_string"] self.location_string = self.search_form.cleaned_data["location_string"]
self.max_distance = int(self.search_form.cleaned_data["max_distance"]) self.max_distance = int(self.search_form.cleaned_data["max_distance"])
self._locate()
try:
self.location = LocationProxy(self.location_string)
except ValueError:
self.place_not_found = True
else: else:
self.search_form = AdoptionNoticeSearchForm() self.search_form = AdoptionNoticeSearchForm()