diff --git a/RoutesApp/js_urls.py b/RoutesApp/js_urls.py index 3bbefe0..9c211ec 100644 --- a/RoutesApp/js_urls.py +++ b/RoutesApp/js_urls.py @@ -7,8 +7,17 @@ from .js_views import * # /routes/ urlpatterns = [ - path('change_route//', create_or_change_route_ajax, name='change_route_ajax'), - path('create_or_change_route/', create_or_change_route_ajax, name='create_or_change_route_ajax'), + path( + 'change_route//', + create_or_change_route_ajax, name='change_route_ajax'), + path( + 'create_or_change_route/', + create_or_change_route_ajax, name='create_or_change_route_ajax'), + + path( + 'get_cargo_type_by_transport_type/', + get_cargo_type_by_transport_type_ajax, + name='get_cargo_type_by_transport_type_ajax'), path('edit_route/', edit_route_ajax, name='edit_route_ajax'), path('del_route/', del_route_ajax, name='del_route_ajax'), diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py index 7435cf6..47b6ece 100644 --- a/RoutesApp/js_views.py +++ b/RoutesApp/js_views.py @@ -344,6 +344,29 @@ def get_my_routes_ajax(request): return JsonResponse(errors_Dict, status=400) +def get_cargo_type_by_transport_type_ajax(request): + if request.method != 'POST': + raise Http404 + + try: + + data = request.POST + if not data: + data = json.loads(request.body) + + if not data or not 'type_transport' in data: + return JsonResponse({'html': 'недостаточно данных'}, status=400) + + cargo_type = cargo_type_choices + if data['type_transport'] in ['avia']: + cargo_type = cargo_type[1:] + + return JsonResponse(cargo_type) + + except Exception as e: + + msg = f'get_cargo_type_by_transport_type_ajax Exception = {str(e)}' + return JsonResponse({'error': msg}, status=400) def create_or_change_route_ajax(request, route_id=None):