Refactor search functionality: remove obsolete JavaScript and HTML templates; enhance error handling and response rendering for park search results

This commit is contained in:
pacnpal
2025-02-13 10:29:57 -05:00
parent c197051b25
commit bba707fa98
7 changed files with 164 additions and 173 deletions

View File

@@ -74,17 +74,20 @@ def search_parks(request: HttpRequest) -> HttpResponse:
parks = park_filter.qs[:8] # Limit to 8 suggestions
response = render(request, "parks/partials/park_search_results.html", {
"parks": parks,
"is_quick_search": True
if not parks:
return HttpResponse(
'<div class="p-4 text-sm text-gray-500">No parks found matching your search.</div>'
)
response = render(request, "parks/partials/park_list_item.html", {
"object_list": parks # Use object_list to match template's for loop
})
response['HX-Trigger'] = 'searchComplete'
return response
except Exception as e:
response = render(request, "parks/partials/park_search_results.html", {
"error": f"Error performing search: {str(e)}",
"is_quick_search": True
response = render(request, "parks/partials/park_list_item.html", {
"error": f"Error performing search: {str(e)}"
})
response['HX-Trigger'] = 'searchError'
return response