|
|
|
|
@ -96,22 +96,12 @@ def city_change(request, url): |
|
|
|
|
|
|
|
|
|
def search_city(request): |
|
|
|
|
term = request.GET.get('term') |
|
|
|
|
# if not term: |
|
|
|
|
# qs = City.objects.language().filter(country=country)[:200] |
|
|
|
|
# else: |
|
|
|
|
# qs = City.objects.language().filter(country=country, translations__name__contains=term) |
|
|
|
|
# result = [{'id': city.id, 'label': city.name} for city in qs] |
|
|
|
|
|
|
|
|
|
lang = get_language() |
|
|
|
|
country = request.GET.get('country') |
|
|
|
|
if not term: |
|
|
|
|
qs = SearchQuerySet().models(City).order_by('text')[:30] |
|
|
|
|
qs = City.objects.language().filter(country=country)[:200] |
|
|
|
|
else: |
|
|
|
|
qs = SearchQuerySet().models(City).autocomplete(content_auto=term.capitalize()).order_by('text')[:30] |
|
|
|
|
result = [] |
|
|
|
|
for item in qs: |
|
|
|
|
label = get_by_lang(item, 'name', lang) |
|
|
|
|
if label: |
|
|
|
|
result.append({'id': item.pk, 'label': label}) |
|
|
|
|
qs = City.objects.language().filter(country=country, translations__name__contains=term) |
|
|
|
|
result = [{'id': city.id, 'label': city.name} for city in qs] |
|
|
|
|
return JsonResponse(json.dumps(result), content_type='application/json', safe=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|