diff --git a/src/fellchensammlung/api/serializers.py b/src/fellchensammlung/api/serializers.py index 7ce03be..cd0fff8 100644 --- a/src/fellchensammlung/api/serializers.py +++ b/src/fellchensammlung/api/serializers.py @@ -145,10 +145,15 @@ class AnimalGetSerializer(serializers.ModelSerializer): class RescueOrganizationSerializer(serializers.ModelSerializer): + url = serializers.SerializerMethodField() + class Meta: model = RescueOrganization exclude = ["internal_comment", "allows_using_materials"] + def get_url(self, obj): + return obj.get_absolute_url() + class ImageCreateSerializer(serializers.ModelSerializer): @staticmethod diff --git a/src/fellchensammlung/api/urls.py b/src/fellchensammlung/api/urls.py index 785f29a..bb9d101 100644 --- a/src/fellchensammlung/api/urls.py +++ b/src/fellchensammlung/api/urls.py @@ -2,10 +2,11 @@ from django.urls import path from .views import ( AdoptionNoticeApiView, AnimalApiView, RescueOrganizationApiView, AddImageApiView, SpeciesApiView, LocationApiView, - AdoptionNoticeGeoJSONView, RescueOrgGeoJSONView, AdoptionNoticePerOrgApiView + AdoptionNoticeGeoJSONView, RescueOrgGeoJSONView, AdoptionNoticePerOrgApiView, index ) urlpatterns = [ + path("", index, name="api-base-url"), path("adoption_notice", AdoptionNoticeApiView.as_view(), name="api-adoption-notice-list"), path("adoption_notice.geojson", AdoptionNoticeGeoJSONView.as_view(), name="api-adoption-notice-list-geojson"), path("adoption_notice//", AdoptionNoticeApiView.as_view(), name="api-adoption-notice-detail"), diff --git a/src/fellchensammlung/api/views.py b/src/fellchensammlung/api/views.py index 251fb63..762b808 100644 --- a/src/fellchensammlung/api/views.py +++ b/src/fellchensammlung/api/views.py @@ -1,4 +1,6 @@ from django.db.models import Q +from django.shortcuts import redirect +from django.urls import reverse from drf_spectacular.types import OpenApiTypes from rest_framework.generics import ListAPIView @@ -450,3 +452,7 @@ class AdoptionNoticePerOrgApiView(APIView): adoption_notices = temporary_an_storage serializer = AdoptionNoticeSerializer(adoption_notices, many=True, context={"request": request}) return Response(serializer.data, status=status.HTTP_200_OK) + + +def index(request): + return redirect(reverse("swagger-ui")) diff --git a/src/fellchensammlung/forms.py b/src/fellchensammlung/forms.py index 8038c90..ebd2196 100644 --- a/src/fellchensammlung/forms.py +++ b/src/fellchensammlung/forms.py @@ -186,6 +186,11 @@ class RescueOrgSearchForm(forms.Form): label=_("Suchradius")) +class RescueOrgSearchByNameForm(forms.Form): + template_name = "fellchensammlung/forms/form_snippets.html" + name = forms.CharField(max_length=100, label=_("Name der Organisation"), required=False) + + class CloseAdoptionNoticeForm(forms.ModelForm): template_name = "fellchensammlung/forms/form_snippets.html" diff --git a/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html b/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html index 34e5040..3a10b4e 100644 --- a/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html +++ b/src/fellchensammlung/templates/fellchensammlung/animal-shelters.html @@ -33,6 +33,11 @@ {% trans 'Suchen' %} +
+
+ {% csrf_token %} + {{ org_name_search_form }} +
{% endif %} @@ -69,4 +74,57 @@ {% endfor %} + {% endblock %} diff --git a/src/fellchensammlung/templatetags/custom_tags.py b/src/fellchensammlung/templatetags/custom_tags.py index cf94e50..0bc962c 100644 --- a/src/fellchensammlung/templatetags/custom_tags.py +++ b/src/fellchensammlung/templatetags/custom_tags.py @@ -5,6 +5,7 @@ from django.template.defaultfilters import stringfilter from django.utils.safestring import mark_safe from urllib.parse import urlparse from django.utils import timezone +from django.urls import reverse from fellchensammlung.tools.misc import time_since_as_hr_string from notfellchen import settings @@ -54,6 +55,11 @@ def get_oxitraffic_script_if_enabled(): return "" +@register.simple_tag +def api_base_url(): + return reverse("api-base-url") + + @register.filter @stringfilter def pointdecimal(value): diff --git a/src/fellchensammlung/tools/search.py b/src/fellchensammlung/tools/search.py index 68f9b7b..183dc35 100644 --- a/src/fellchensammlung/tools/search.py +++ b/src/fellchensammlung/tools/search.py @@ -173,6 +173,7 @@ class AdoptionNoticeSearch: class RescueOrgSearch: def __init__(self, request): + self.name = None self.area_search = None self.max_distance = None self.location = None # Can either be Location (DjangoModel) or LocationProxy @@ -229,6 +230,7 @@ class RescueOrgSearch: return fitting_rescue_orgs def rescue_org_search_from_request(self, request): + # Only search if request method is get with action search if request.method == 'GET' and request.GET.get("action", False) == "search": self.search_form = RescueOrgSearchForm(request.GET) self.search_form.is_valid() diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index d6e8d4a..4b64ab5 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -25,7 +25,7 @@ from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, Moderatio ImportantLocation, SpeciesSpecificURL, NotificationTypeChoices, SocialMediaPost from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, \ CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm, RescueOrgInternalComment, \ - UpdateRescueOrgRegularCheckStatus, UserModCommentForm, CloseAdoptionNoticeForm + UpdateRescueOrgRegularCheckStatus, UserModCommentForm, CloseAdoptionNoticeForm, RescueOrgSearchByNameForm from .models import Language, Announcement from .tools import i18n, img from .tools.fedi import post_an_to_fedi @@ -851,6 +851,7 @@ def list_rescue_organizations(request, species=None, template='fellchensammlung/ context = {"rescue_organizations_to_list": rescue_organizations_to_list, "show_rescue_orgs": True, "elided_page_range": paginator.get_elided_page_range(page_number, on_each_side=2, on_ends=1), + "org_name_search_form": RescueOrgSearchByNameForm(), } if org_search: additional_context = {