Files
company_website/apps/customers/views.py
T

34 lines
1.2 KiB
Python

from django.shortcuts import render
from django.http import JsonResponse
from .models import CustomerLocation
from django.utils.translation import get_language
from django.conf import settings
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).order_by('sort_order', '-id')
data = []
for index, loc in enumerate(locations, start=1):
icon_url = None
if loc.marker_icon:
icon_url = settings.MEDIA_URL + str(loc.marker_icon)
data.append({
'id': loc.id,
'index': index,
'name': getattr(loc, f'name_{suffix}'),
'address': getattr(loc, f'address_{suffix}'),
'description': getattr(loc, f'description_{suffix}'),
'lat': loc.latitude,
'lng': loc.longitude,
'color': loc.marker_color or '#165DFF',
'icon': icon_url,
})
return JsonResponse({'locations': data})