Files
company_website/apps/customers/views.py
T
2026-08-03 14:42:40 +08:00

31 lines
1.1 KiB
Python

from django.shortcuts import render
from django.http import JsonResponse
from .models import CustomerLocation
from django.utils.translation import get_language
def customer_map(request):
breadcrumb_items = [{'name': '客户案例', 'url': ''}]
return render(request, 'customers/map.html', {'breadcrumb_items': breadcrumb_items})
def customer_locations_api(request):
lang = get_language()
suffix = 'en' if lang.startswith('en') else 'zh'
locations = CustomerLocation.objects.filter(is_active=True).values(
'id', f'name_{suffix}', f'address_{suffix}', f'description_{suffix}',
'latitude', 'longitude', 'marker_color'
)
data = []
for loc in locations:
data.append({
'id': loc['id'],
'name': loc[f'name_{suffix}'],
'address': loc[f'address_{suffix}'],
'description': loc[f'description_{suffix}'],
'lat': loc['latitude'],
'lng': loc['longitude'],
'color': loc['marker_color'] or '#165DFF',
})
return JsonResponse({'locations': data})