From 71e69356b83d38891cbcdd9ab55904f36db11514 Mon Sep 17 00:00:00 2001 From: moanos Date: Fri, 31 May 2024 16:00:52 +0200 Subject: [PATCH] feat: Filter adoption notices to show only active ones --- src/fellchensammlung/models.py | 4 ++++ src/fellchensammlung/views.py | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index a1aea86..98b101d 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -256,6 +256,10 @@ class AdoptionNotice(models.Model): domain = urlparse(self.further_information).netloc return f"{domain}" + @property + def is_active(self): + return self.status.is_active + class Animal(models.Model): MALE_NEUTERED = "M_N" diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index e8948c7..cd81986 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -22,10 +22,11 @@ from .tools.geo import GeoAPI def index(request): """View function for home page of site.""" latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")[:5] + active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active] language_code = translation.get_language() lang = Language.objects.get(languagecode=language_code) active_announcements = Announcement.get_active_announcements(lang) - context = {"adoption_notices": latest_adoption_list, "announcements": active_announcements} + context = {"adoption_notices": active_adoptions, "announcements": active_announcements} return render(request, 'fellchensammlung/index.html', context=context) @@ -98,12 +99,14 @@ def search(request): search_position = geo_api.get_coordinates_from_query(request.POST['postcode']) 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)] + active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active] + adoption_notices_in_distance = [a for a in active_adoptions if a.in_distance(search_position, max_distance)] context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form} else: latest_adoption_list = AdoptionNotice.objects.order_by("-created_at") + active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active] search_form = AdoptionNoticeSearchForm() - context = {"adoption_notices": latest_adoption_list, "search_form": search_form} + context = {"adoption_notices": active_adoptions, "search_form": search_form} return render(request, 'fellchensammlung/search.html', context=context)