diff --git a/src/fellchensammlung/tools/search.py b/src/fellchensammlung/tools/search.py index 6489ec0..a188273 100644 --- a/src/fellchensammlung/tools/search.py +++ b/src/fellchensammlung/tools/search.py @@ -28,7 +28,7 @@ class Search: self.sex = None self.area_search = 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.search_form = None @@ -55,6 +55,12 @@ class Search: return False 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): # 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: @@ -88,11 +94,7 @@ class Search: self.area_search = True self.location_string = self.search_form.cleaned_data["location_string"] self.max_distance = int(self.search_form.cleaned_data["max_distance"]) - - try: - self.location = LocationProxy(self.location_string) - except ValueError: - self.place_not_found = True + self._locate() else: self.search_form = AdoptionNoticeSearchForm()