Merge remote-tracking branch 'origin/v2' into v2

This commit is contained in:
SBD
2025-01-14 19:11:29 +03:00
3 changed files with 16 additions and 83 deletions

View File

@@ -4,46 +4,9 @@ from django.contrib.auth.forms import AuthenticationForm
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ValidationError
from .models import *
import copy
def routeForm_assign_choices_by_type_transport(form, type_transport):
if type_transport == 'avia':
transfer_location_choices = (
('airport', _('В аэропорту')),
('city', _('По городу')),
('other', _('По договоренности'))
)
cargo_type_choices = (
('cargo', _('Груз')),
('parcel', _('Бандероль')),
('package', _('Посылка')),
('letter', _('Письмо\Документ'))
)
else:
transfer_location_choices = (
('city', _('По городу')),
('other', _('По договоренности'))
)
cargo_type_choices = (
('passenger', _('Пассажир')),
('cargo', _('Груз')),
('parcel', _('Бандероль')),
('package', _('Посылка')),
('letter', _('Письмо\Документ'))
)
form.fields['from_place'].choices = transfer_location_choices
form.fields['to_place'].choices = transfer_location_choices
form.fields['cargo_type'].choices = cargo_type_choices
form.base_fields['from_place'].choices = transfer_location_choices
form.base_fields['to_place'].choices = transfer_location_choices
form.base_fields['cargo_type'].choices = cargo_type_choices
return form

View File

@@ -10,8 +10,19 @@ from django.db.models import F, Q
elements_on_page = 25
def get_cargo_types_by_type_transport(type_transport, form=None):
cargo_types = copy.deepcopy(cargo_type_choices)
if type_transport in ['avia']:
cargo_types = cargo_types[:2] + cargo_types[3:]
if not form:
return cargo_types
form.fields['cargo_type'].choices = cargo_types
form.base_fields['cargo_type'].choices = cargo_types
return form
@@ -28,53 +39,13 @@ def get_profile_new_route_page_html(request, data):
errors_off = True
# if 'from_address_point' in data:
# del data['from_address_point']
# if 'from_address_point_txt' in data:
# del data['from_address_point_txt']
#
# if 'to_address_point' in data:
# del data['to_address_point']
# if 'to_address_point_txt' in data:
# del data['to_address_point_txt']
# if data['type_transport'] == 'avia':
# transfer_location_choices = (
# ('airport', _('В аэропорту')),
# ('city', _('По городу')),
# ('other', _('По договоренности'))
# )
#
# cargo_type_choices = (
# ('cargo', _('Груз')),
# ('parcel', _('Бандероль')),
# ('package', _('Посылка')),
# ('letter', _('Письмо\Документ'))
# )
#
#
# else:
# transfer_location_choices = (
# ('city', _('По городу')),
# ('other', _('По договоренности'))
# )
#
# cargo_type_choices = (
# ('passenger', _('Пассажир')),
# ('cargo', _('Груз')),
# ('parcel', _('Бандероль')),
# ('package', _('Посылка')),
# ('letter', _('Письмо\Документ'))
# )
form = RouteForm(data)
if not form.is_valid():
pass
form = RouteForm(initial=form.cleaned_data)
if 'type_transport' in data:
form = routeForm_assign_choices_by_type_transport(form, data['type_transport'])
form = get_cargo_types_by_type_transport(data['type_transport'], form)
if 'owner_type' in data:

View File

@@ -174,7 +174,8 @@ def edit_route_ajax(request):
route = Route.objects.get(id=data['route_id'])
form = RouteForm(instance=route)
form = routeForm_assign_choices_by_type_transport(form, route.type_transport)
form = get_cargo_types_by_type_transport(route.type_transport, form)
# routeForm_assign_choices_by_type_transport(form, route.type_transport)
route_address_points_Dict = route.get_address_points()
form.initial.update({
@@ -358,9 +359,7 @@ def get_cargo_type_by_transport_type_ajax(request):
if not data or not 'type_transport' in data:
return JsonResponse({'html': 'недостаточно данных'}, status=400)
cargo_types = copy.deepcopy(cargo_type_choices)
if data['type_transport'] in ['avia']:
cargo_types = cargo_types[:2] + cargo_types[3:]
cargo_types = get_cargo_types_by_type_transport(data['type_transport'])
return JsonResponse({'cargo_types': cargo_types})