0.7.29
fix search routes insert txt address points
This commit is contained in:
@@ -54,6 +54,14 @@ class City(BaseModel):
|
||||
else:
|
||||
return f'{self.id}'
|
||||
|
||||
def get_country_n_city_str(self):
|
||||
country = 'Неизвестно'
|
||||
city = self.name
|
||||
if self.country:
|
||||
country = self.country
|
||||
|
||||
return f'{city} / {country}'
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Город')
|
||||
|
||||
@@ -86,6 +86,11 @@ def get_profile_new_route_page_html(request, data):
|
||||
return html
|
||||
|
||||
|
||||
def get_country_n_city_str_by_type_transport_and_address_point(type_transport, address_point):
|
||||
city = get_city_by_type_transport_and_address_point(type_transport, address_point)
|
||||
return city.get_country_n_city_str()
|
||||
|
||||
|
||||
def get_city_by_type_transport_and_address_point(type_transport, address_point):
|
||||
from ReferenceDataApp.models import Airport, City
|
||||
|
||||
@@ -130,6 +135,8 @@ def get_routes_Dict(user=None, data=None):
|
||||
from_el = None
|
||||
to_el = None
|
||||
|
||||
res_Dict = {}
|
||||
|
||||
if data:
|
||||
for key, val in data.items():
|
||||
if val:
|
||||
@@ -144,6 +151,7 @@ def get_routes_Dict(user=None, data=None):
|
||||
items_list = val.split(',')
|
||||
kwargs.update({f'{key}__in': items_list})
|
||||
|
||||
|
||||
if key in (
|
||||
'departure_DT', 'arrival_DT'
|
||||
):
|
||||
@@ -158,9 +166,19 @@ def get_routes_Dict(user=None, data=None):
|
||||
|
||||
if key == 'from_address_point':
|
||||
kwargs.update({f'from_city__id': val})
|
||||
res_Dict.update({
|
||||
'from_address_point_txt': get_country_n_city_str_by_type_transport_and_address_point(
|
||||
'road', val
|
||||
)
|
||||
})
|
||||
|
||||
if key == 'to_address_point':
|
||||
kwargs.update({f'to_city__id': val})
|
||||
res_Dict.update({
|
||||
'to_address_point_txt': get_country_n_city_str_by_type_transport_and_address_point(
|
||||
'road', val
|
||||
)
|
||||
})
|
||||
|
||||
if key == 'from_el':
|
||||
from_el = int(val)
|
||||
@@ -183,7 +201,7 @@ def get_routes_Dict(user=None, data=None):
|
||||
if to_el and to_el >= routes_count:
|
||||
last_block_routes = True
|
||||
|
||||
res_Dict = {}
|
||||
|
||||
|
||||
try:
|
||||
|
||||
@@ -206,10 +224,10 @@ def get_routes_Dict(user=None, data=None):
|
||||
msg = f'get_routes_for_user get route Error = {str(e)}'
|
||||
print(msg)
|
||||
|
||||
res_Dict = {
|
||||
res_Dict.update({
|
||||
'routes': routes,
|
||||
'last_block_routes': last_block_routes
|
||||
}
|
||||
})
|
||||
return res_Dict
|
||||
|
||||
|
||||
|
||||
@@ -75,26 +75,18 @@ class Route(BaseModel):
|
||||
ordering = ('name',)
|
||||
|
||||
def from_country_n_city_str(self):
|
||||
country = 'Неизвестно'
|
||||
res = 'Неизвестно'
|
||||
if self.from_city:
|
||||
city = self.from_city.name
|
||||
if self.from_city.country:
|
||||
country = self.from_city.country
|
||||
else:
|
||||
city = 'Неизвестно'
|
||||
res = self.from_city.get_country_n_city_str()
|
||||
|
||||
return f'{city} / {country}'
|
||||
return res
|
||||
|
||||
def to_country_n_city_str(self):
|
||||
country = 'Неизвестно'
|
||||
res = 'Неизвестно'
|
||||
if self.to_city:
|
||||
city = self.to_city.name
|
||||
if self.to_city.country:
|
||||
country = self.to_city.country
|
||||
else:
|
||||
city = 'Неизвестно'
|
||||
res = self.to_city.get_country_n_city_str()
|
||||
|
||||
return f'{city} / {country}'
|
||||
return res
|
||||
|
||||
|
||||
def get_address_points(self):
|
||||
|
||||
@@ -28,11 +28,15 @@ def route_search_results_View(request):
|
||||
if routes_Dict:
|
||||
Dict = {
|
||||
'routes': routes_Dict['routes'],
|
||||
'route_form': RouteForm(initial=data),
|
||||
'last_block_routes': routes_Dict['last_block_routes'],
|
||||
'show_filter_and_results': True,
|
||||
'owner_type': data['owner_type']
|
||||
}
|
||||
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']})
|
||||
Dict.update({'route_form': RouteForm(initial=data)})
|
||||
|
||||
t = loader.get_template('pages/p_results_find_route.html')
|
||||
return HttpResponse(t.render(Dict, request))
|
||||
|
||||
Reference in New Issue
Block a user