2.1.13 get_cargo_type_by_transport_type_ajax

This commit is contained in:
SDE
2025-01-14 16:04:16 +03:00
parent 04f097c1a9
commit cfe1a9d585
2 changed files with 34 additions and 2 deletions

View File

@@ -7,8 +7,17 @@ from .js_views import *
# /routes/
urlpatterns = [
path('change_route/<int:route_id>/', 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/<int:route_id>/',
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'),

View File

@@ -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):