55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from django.shortcuts import render
|
|
|
|
from uuid import uuid1
|
|
from .models import *
|
|
from django.contrib import auth
|
|
from django.http import HttpResponse, Http404, JsonResponse
|
|
from django.template import loader, RequestContext
|
|
from django.contrib.auth.decorators import login_required
|
|
from BaseModels.mailSender import techSendMail
|
|
from django.utils.translation import gettext as _
|
|
from datetime import datetime
|
|
from django.template.loader import render_to_string
|
|
from django.urls import reverse
|
|
from django.db.models import Q
|
|
|
|
def get_address_point_ajax(request):
|
|
from .funcs import search_cities_in_db, search_airports_in_db
|
|
|
|
if request.method != 'POST':
|
|
raise Http404
|
|
|
|
try:
|
|
|
|
data = request.POST
|
|
|
|
if not 'search_str' in data or not 'type_transport' in data:
|
|
errors_Dict = {
|
|
'errors': {
|
|
'all__': f'ошибка в запросе = недостаточно данных'
|
|
}
|
|
}
|
|
return JsonResponse(errors_Dict, status=400)
|
|
|
|
if len(data['search_str'].strip()) < 0:
|
|
res_data = []
|
|
else:
|
|
if data['type_transport'] == 'avia':
|
|
res_data = search_airports_in_db(data['search_str'])
|
|
else:
|
|
res_data = search_cities_in_db(data['search_str'])
|
|
|
|
res_Dict = {
|
|
'data': res_data
|
|
}
|
|
|
|
return JsonResponse(res_Dict)
|
|
|
|
except Exception as e:
|
|
|
|
errors_Dict = {
|
|
'errors': {
|
|
'all__': f'ошибка в запросе = {str(e)}'
|
|
}
|
|
}
|
|
return JsonResponse(errors_Dict, status=400) |