From 5688746e4f11c87d684c59ab83b1407765701d7d Mon Sep 17 00:00:00 2001 From: SDE Date: Wed, 26 Jul 2023 16:22:26 +0300 Subject: [PATCH] 0.0.46 get routes --- RoutesApp/js_views.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py index 76ca4a4..e99c5e4 100644 --- a/RoutesApp/js_views.py +++ b/RoutesApp/js_views.py @@ -39,17 +39,22 @@ def get_routes_ajax(request): for route in routes: - if route.type_transport == 'avia': - route.from_airport = Airport.objects.get(id=route.from_address_point) - route.to_airport = Airport.objects.get(id=route.to_address_point) - route.from_city = route.from_airport.city - route.to_city = route.to_airport.city - else: - route.from_city = City.objects.get(id=route.from_address_point) - route.to_city = City.objects.get(id=route.to_address_point) + try: - route.from_country = route.from_city.country - route.to_country = route.from_city.country + if route.type_transport == 'avia': + route.from_airport = Airport.objects.get(id=route.from_address_point) + route.to_airport = Airport.objects.get(id=route.to_address_point) + route.from_city = route.from_airport.city + route.to_city = route.to_airport.city + else: + route.from_city = City.objects.get(id=route.from_address_point) + route.to_city = City.objects.get(id=route.to_address_point) + + route.from_country = route.from_city.country + route.to_country = route.from_city.country + except Exception as e: + msg = f'get route points = {str(e)}' + print(msg) Dict = { 'routes': routes @@ -69,8 +74,7 @@ def get_routes_ajax(request): 'all__': f'ошибка в запросе = {str(e)}' } } - html = render_to_string('blocks/profile/b_new_route.html', errors_Dict, request=request) - return JsonResponse({'html': html}, status=400) + return JsonResponse(errors_Dict, status=400)