0.0.28
get_address_point
This commit is contained in:
@@ -2,6 +2,24 @@ from django.shortcuts import render
|
|||||||
from .models import *
|
from .models import *
|
||||||
import hashlib, json
|
import hashlib, json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from django.db import Q
|
||||||
|
|
||||||
|
|
||||||
|
def search_cities_in_db(search_str):
|
||||||
|
Q_obj = Q(name_en__icontains=search_str) | Q(name_ru__icontains=search_str) | \
|
||||||
|
Q(country__name_en__icontains=search_str) | Q(country__name_ru__icontains=search_str)
|
||||||
|
res_data = City.objects.filter(Q_obj).values('name', 'country__name')
|
||||||
|
return res_data
|
||||||
|
|
||||||
|
def search_airports_in_db(search_str):
|
||||||
|
Q_obj = Q(iata_code__icontains=search_str) | \
|
||||||
|
Q(name_en__icontains=search_str) | Q(name_ru__icontains=search_str) | \
|
||||||
|
Q(city__name_en__icontains=search_str) | Q(city__name_ru__icontains=search_str) | \
|
||||||
|
Q(city__country__name_en__icontains=search_str) | \
|
||||||
|
Q(city__country__name_ru__icontains=search_str)
|
||||||
|
res_data = Airport.objects.filter(Q_obj).values('name', 'iata_code', 'city__name', 'city__country__name')
|
||||||
|
return res_data
|
||||||
|
|
||||||
|
|
||||||
def get_country_area_id_by_countryName(class_obj, name):
|
def get_country_area_id_by_countryName(class_obj, name):
|
||||||
try:
|
try:
|
||||||
|
|||||||
11
ReferenceDataApp/js_urls.py
Normal file
11
ReferenceDataApp/js_urls.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
from django.urls import path
|
||||||
|
from .js_views import *
|
||||||
|
from django.contrib.auth import views
|
||||||
|
from RoutesApp.js_views import new_route_view_ajax
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
# path('get_airports/', get_airports_ajax, name='get_airports_ajax'),
|
||||||
|
path('get_address_point/', get_address_point_ajax, name='get_address_point_ajax'),
|
||||||
|
# path('get_cities/', get_cities_ajax, name='get_cities_ajax'),
|
||||||
|
]
|
||||||
55
ReferenceDataApp/js_views.py
Normal file
55
ReferenceDataApp/js_views.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
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)
|
||||||
@@ -21,6 +21,8 @@ urlpatterns += i18n_patterns(
|
|||||||
|
|
||||||
path('user_account/', include('AuthApp.js_urls')),
|
path('user_account/', include('AuthApp.js_urls')),
|
||||||
path('routes/', include('RoutesApp.js_urls')),
|
path('routes/', include('RoutesApp.js_urls')),
|
||||||
|
|
||||||
|
path('reference_data/', include('ReferenceDataApp.js_urls')),
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
Reference in New Issue
Block a user