Skip to content

Commit

Permalink
refactor search code
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Dec 20, 2024
1 parent 9654de6 commit 156f2db
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions backend/donations/views/api.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 156f2db

Please sign in to comment.