diff --git a/src/fellchensammlung/forms.py b/src/fellchensammlung/forms.py index fd40827..aed247e 100644 --- a/src/fellchensammlung/forms.py +++ b/src/fellchensammlung/forms.py @@ -147,3 +147,11 @@ class AdoptionNoticeSearchForm(forms.Form): max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.ONE_HUNDRED, label=_("Suchradius")) location_string = forms.CharField(max_length=100, label=_("Stadt"), required=False) + + +class RescueOrgSearchForm(forms.Form): + template_name = "fellchensammlung/forms/form_snippets.html" + + location_string = forms.CharField(max_length=100, label=_("Stadt"), required=False) + max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.ONE_HUNDRED, + label=_("Suchradius")) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index e222457..a437b04 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -272,6 +272,14 @@ class RescueOrganization(models.Model): def child_organizations(self): return RescueOrganization.objects.filter(parent_org=self) + def in_distance(self, position, max_distance, unknown_true=True): + """ + Returns a boolean indicating if the Location of the adoption notice is within a given distance to the position + + If the location is none, we by default return that the location is within the given distance + """ + return geo.object_in_distance(self, position, max_distance, unknown_true) + # Admins can perform all actions and have the highest trust associated with them # Moderators can make moderation decisions regarding the deletion of content @@ -500,11 +508,7 @@ class AdoptionNotice(models.Model): If the location is none, we by default return that the location is within the given distance """ - if unknown_true and self.position is None: - return True - - distance = geo.calculate_distance_between_coordinates(self.position, position) - return distance < max_distance + return geo.object_in_distance(self, position, max_distance, unknown_true) @property def is_active(self): diff --git a/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html b/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html index 2edf8d8..149cfe3 100644 --- a/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html +++ b/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html @@ -16,11 +16,26 @@ {% block canonical_url %}{% host %}{% url 'rescue-organizations' %}{% endblock %} {% block content %} -