diff --git a/src/fellchensammlung/forms.py b/src/fellchensammlung/forms.py
index 246fc03..a522dbd 100644
--- a/src/fellchensammlung/forms.py
+++ b/src/fellchensammlung/forms.py
@@ -126,3 +126,12 @@ class ModerationActionForm(forms.ModelForm):
class CustomRegistrationForm(RegistrationForm):
class Meta(RegistrationForm.Meta):
model = User
+
+
+def _get_distances():
+ return {i: i for i in [10, 20, 50, 100, 200, 500]}
+
+
+class AdoptionNoticeSearchForm(forms.Form):
+ postcode = forms.CharField(max_length=20, label=_("Postleitzahl"))
+ max_distance = forms.ChoiceField(choices=_get_distances, label=_("Max. Distanz"))
diff --git a/src/fellchensammlung/templates/fellchensammlung/search.html b/src/fellchensammlung/templates/fellchensammlung/search.html
index b70aa5c..fd8174a 100644
--- a/src/fellchensammlung/templates/fellchensammlung/search.html
+++ b/src/fellchensammlung/templates/fellchensammlung/search.html
@@ -6,17 +6,7 @@
{% csrf_token %}
-
-
-
+ {{ search_form.as_p }}
{% include "fellchensammlung/lists/list-adoption-notices.html" %}
diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py
index b164b2f..e8948c7 100644
--- a/src/fellchensammlung/views.py
+++ b/src/fellchensammlung/views.py
@@ -13,7 +13,8 @@ from notfellchen import settings
from fellchensammlung import logger
from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
Member, Location
-from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm, AnimalForm
+from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm, AnimalForm, \
+ AdoptionNoticeSearchForm
from .models import Language, Announcement
from .tools.geo import GeoAPI
@@ -89,6 +90,7 @@ def animal_detail(request, animal_id):
def search(request):
if request.method == 'POST':
+ search_form = AdoptionNoticeSearchForm(request.POST)
max_distance = int(request.POST.get('max_distance'))
if max_distance == "":
max_distance = None
@@ -97,12 +99,12 @@ def search(request):
latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")
adoption_notices_in_distance = [a for a in latest_adoption_list if a.in_distance(search_position, max_distance)]
- context = {"adoption_notices": adoption_notices_in_distance}
- return render(request, 'fellchensammlung/search.html', context=context)
+ context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form}
else:
latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")
- context = {"adoption_notices": latest_adoption_list}
- return render(request, 'fellchensammlung/search.html', context=context)
+ search_form = AdoptionNoticeSearchForm()
+ context = {"adoption_notices": latest_adoption_list, "search_form": search_form}
+ return render(request, 'fellchensammlung/search.html', context=context)
@login_required