From 7b915f0c6c5c97e47feb844e2cfd2554206db2e9 Mon Sep 17 00:00:00 2001 From: SDE Date: Tue, 14 Jan 2025 19:00:19 +0300 Subject: [PATCH] 2.1.16 change cargo_type and transport_type names --- RoutesApp/forms.py | 39 +------------------------------ RoutesApp/funcs.py | 53 ++++++++++--------------------------------- RoutesApp/js_views.py | 7 +++--- 3 files changed, 16 insertions(+), 83 deletions(-) diff --git a/RoutesApp/forms.py b/RoutesApp/forms.py index 8188075..b8860bb 100644 --- a/RoutesApp/forms.py +++ b/RoutesApp/forms.py @@ -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 diff --git a/RoutesApp/funcs.py b/RoutesApp/funcs.py index 14823ec..c59f28d 100644 --- a/RoutesApp/funcs.py +++ b/RoutesApp/funcs.py @@ -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: diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py index 208a5b6..5a29c8e 100644 --- a/RoutesApp/js_views.py +++ b/RoutesApp/js_views.py @@ -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})