mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 11:31:07 -05:00
Enhance park search functionality: update view mode handling and improve park list item layout
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import requests
|
||||
from decimal import Decimal, ROUND_DOWN
|
||||
from typing import Any, Optional, cast, Literal
|
||||
from django.views.generic import DetailView, ListView, CreateView, UpdateView
|
||||
from decimal import InvalidOperation
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.urls import reverse
|
||||
from django.db.models import Q, Count, QuerySet
|
||||
@@ -23,6 +25,70 @@ from search.mixins import HTMXFilterableMixin
|
||||
ViewMode = Literal["grid", "list"]
|
||||
|
||||
|
||||
def normalize_osm_result(result: dict) -> dict:
|
||||
"""Normalize OpenStreetMap result to a consistent format with enhanced address details"""
|
||||
from .location_utils import get_english_name, normalize_coordinate
|
||||
|
||||
# Get address details
|
||||
address = result.get('address', {})
|
||||
|
||||
# Normalize coordinates
|
||||
lat = normalize_coordinate(float(result.get('lat')), 9, 6)
|
||||
lon = normalize_coordinate(float(result.get('lon')), 10, 6)
|
||||
|
||||
# Get English names where possible
|
||||
name = ''
|
||||
if 'namedetails' in result:
|
||||
name = get_english_name(result['namedetails'])
|
||||
|
||||
# Build street address from available components
|
||||
street_parts = []
|
||||
if address.get('house_number'):
|
||||
street_parts.append(address['house_number'])
|
||||
if address.get('road') or address.get('street'):
|
||||
street_parts.append(address.get('road') or address.get('street'))
|
||||
elif address.get('pedestrian'):
|
||||
street_parts.append(address['pedestrian'])
|
||||
elif address.get('footway'):
|
||||
street_parts.append(address['footway'])
|
||||
|
||||
# Handle additional address components
|
||||
suburb = address.get('suburb', '')
|
||||
district = address.get('district', '')
|
||||
neighborhood = address.get('neighbourhood', '')
|
||||
|
||||
# Build city from available components
|
||||
city = (address.get('city') or
|
||||
address.get('town') or
|
||||
address.get('village') or
|
||||
address.get('municipality') or
|
||||
'')
|
||||
|
||||
# Get detailed state/region information
|
||||
state = (address.get('state') or
|
||||
address.get('province') or
|
||||
address.get('region') or
|
||||
'')
|
||||
|
||||
# Get postal code with fallbacks
|
||||
postal_code = (address.get('postcode') or
|
||||
address.get('postal_code') or
|
||||
'')
|
||||
|
||||
return {
|
||||
'display_name': name or result.get('display_name', ''),
|
||||
'lat': lat,
|
||||
'lon': lon,
|
||||
'street': ' '.join(street_parts).strip(),
|
||||
'suburb': suburb,
|
||||
'district': district,
|
||||
'neighborhood': neighborhood,
|
||||
'city': city,
|
||||
'state': state,
|
||||
'country': address.get('country', ''),
|
||||
'postal_code': postal_code,
|
||||
}
|
||||
|
||||
def get_view_mode(request: HttpRequest) -> ViewMode:
|
||||
"""Get the current view mode from request, defaulting to grid"""
|
||||
view_mode = request.GET.get('view_mode', 'grid')
|
||||
@@ -202,6 +268,8 @@ def search_parks(request: HttpRequest) -> HttpResponse:
|
||||
if not search_query:
|
||||
return HttpResponse('')
|
||||
|
||||
# Get current view mode from request
|
||||
current_view_mode = request.GET.get('view_mode', 'grid')
|
||||
park_filter = ParkFilter({
|
||||
'search': search_query
|
||||
}, queryset=get_base_park_queryset())
|
||||
@@ -215,7 +283,7 @@ def search_parks(request: HttpRequest) -> HttpResponse:
|
||||
"parks/partials/park_list_item.html",
|
||||
{
|
||||
"parks": parks,
|
||||
"view_mode": get_view_mode(request),
|
||||
"view_mode": current_view_mode,
|
||||
"search_query": search_query,
|
||||
"is_search": True
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user