From c476fa6d775350c8c2801a338440d4621e77ec80 Mon Sep 17 00:00:00 2001 From: SDE Date: Mon, 17 Feb 2025 15:14:35 +0300 Subject: [PATCH] 2.1.34 route_search_results_View fix cities --- GeneralApp/funcs.py | 1 + GeneralApp/views.py | 1 - ReferenceDataApp/funcs.py | 7 +++++++ RoutesApp/views.py | 24 ++++++++++++++++-------- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/GeneralApp/funcs.py b/GeneralApp/funcs.py index abf165d..57e94a5 100644 --- a/GeneralApp/funcs.py +++ b/GeneralApp/funcs.py @@ -8,6 +8,7 @@ from BaseModels.print_funcs import print_ext + def get_and_set_lang(request): from django.utils.translation import activate, get_language lang = None diff --git a/GeneralApp/views.py b/GeneralApp/views.py index 0c58b2c..175b8ec 100644 --- a/GeneralApp/views.py +++ b/GeneralApp/views.py @@ -26,7 +26,6 @@ def generate_routes(request, routes_count): ): raise Http404 - from RoutesApp.funcs import get_city_by_type_transport_and_address_point from RoutesApp.models import Route from ReferenceDataApp.models import Airport, City diff --git a/ReferenceDataApp/funcs.py b/ReferenceDataApp/funcs.py index 0be3ce6..4ca247f 100644 --- a/ReferenceDataApp/funcs.py +++ b/ReferenceDataApp/funcs.py @@ -7,6 +7,13 @@ from timezonefinder import TimezoneFinder tzf = TimezoneFinder() +def get_city_by_id(city_id): + try: + return City.objects.get(id=city_id) + except City.DoesNotExist: + return None + + def search_cities_in_db(search_str): res_data = [] Q_obj = Q(name_en__icontains=search_str) | Q(name_ru__icontains=search_str) | \ diff --git a/RoutesApp/views.py b/RoutesApp/views.py index 33b5237..3a8bf36 100644 --- a/RoutesApp/views.py +++ b/RoutesApp/views.py @@ -1,6 +1,8 @@ from django.shortcuts import render from uuid import uuid1 + +from ReferenceDataApp.funcs import get_city_by_id from .models import * from django.contrib import auth from django.http import HttpResponse, Http404 @@ -39,17 +41,23 @@ def route_search_results_View(request): 'page_type': 'routes', 'next_page_els_count': routes_Dict['next_page_els_count'], } - if 'from_address_point_txt' in routes_Dict: - data.update({'from_address_point_txt': routes_Dict['from_address_point_txt']}) - if 'to_address_point_txt' in routes_Dict: - data.update({'to_address_point_txt': routes_Dict['to_address_point_txt']}) + + from_city = None + to_city = None + if 'from_city' in data and data['from_city']: + from_city = get_city_by_id(data['from_city']) + data.update({'from_city': from_city}) + if 'to_city' in data and data['to_city']: + to_city = get_city_by_id(data['to_city']) + data.update({'to_city': to_city}) + Dict.update({'route_form': RouteForm(initial=data, owner_type=owner_type)}) title = _('Результат поиска маршрутов') - if 'from_address_point_txt' in data: - title = f'{title} из {data["from_address_point_txt"]}' - if 'to_address_point_txt' in data: - title = f'{title} в {data["to_address_point_txt"]}' + if from_city: + title = f'{title} из {from_city.name}' + if to_city: + title = f'{title} в {to_city.name}' Dict.update({ 'page': {