diff --git a/backend/donations/views/api.py b/backend/donations/views/api.py index 95108611..7ef2ee9f 100644 --- a/backend/donations/views/api.py +++ b/backend/donations/views/api.py @@ -1,5 +1,6 @@ import logging from datetime import date +from typing import Dict, List from django.conf import settings from django.contrib.auth.decorators import login_required @@ -27,6 +28,16 @@ logger = logging.getLogger(__name__) +def get_ngo_response_item(ngo) -> Dict: + return { + "name": ngo.name, + "url": reverse("twopercent", kwargs={"ngo_url": ngo.slug}), + "logo": ngo.logo.url if ngo.logo else None, + "active_region": ngo.active_region, + "description": ngo.description, + } + + class UpdateFromNgohub(BaseTemplateView): def post(self, request, *args, **kwargs): redirect_success = redirect(reverse("organization")) @@ -116,15 +127,7 @@ def get(self, request, *args, **kwargs): if not ngo.slug: continue - response.append( - { - "name": ngo.name, - "url": reverse("twopercent", kwargs={"ngo_url": ngo.slug}), - "logo": ngo.logo.url if ngo.logo else None, - "active_region": ngo.active_region, - "description": ngo.description, - } - ) + response.append(get_ngo_response_item(ngo)) return JsonResponse(response, safe=False) @@ -166,20 +169,12 @@ def get(self, request, *args, **kwargs): .distinct("name") ) - response = [] + response: List[Dict] = [] for ngo in ngos: if not ngo.slug: continue - response.append( - { - "name": ngo.name, - "url": reverse("twopercent", kwargs={"ngo_url": ngo.slug}), - "logo": ngo.logo.url if ngo.logo else None, - "active_region": ngo.active_region, - "description": ngo.description, - } - ) + response.append(get_ngo_response_item(ngo)) return JsonResponse(response, safe=False)