0.12.1 fix form from and to place fields choices
This commit is contained in:
@@ -6,6 +6,47 @@ from django.core.exceptions import ValidationError
|
|||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RouteForm(forms.ModelForm):
|
class RouteForm(forms.ModelForm):
|
||||||
from_address_point_txt = forms.CharField(required=True)
|
from_address_point_txt = forms.CharField(required=True)
|
||||||
to_address_point_txt = forms.CharField(required=True)
|
to_address_point_txt = forms.CharField(required=True)
|
||||||
|
|||||||
@@ -7,12 +7,19 @@ from datetime import datetime
|
|||||||
elements_on_page = 25
|
elements_on_page = 25
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_profile_new_route_page_html(request, data):
|
def get_profile_new_route_page_html(request, data):
|
||||||
|
|
||||||
form = RouteForm()
|
form = RouteForm()
|
||||||
Dict = {
|
Dict = {
|
||||||
'form': form
|
'form': form
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
errors_off = True
|
errors_off = True
|
||||||
@@ -27,48 +34,51 @@ def get_profile_new_route_page_html(request, data):
|
|||||||
if 'to_address_point_txt' in data:
|
if 'to_address_point_txt' in data:
|
||||||
del data['to_address_point_txt']
|
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:
|
if 'type_transport' in data:
|
||||||
if data['type_transport'] == 'avia':
|
form = routeForm_assign_choices_by_type_transport(form, data['type_transport'])
|
||||||
transfer_location_choices = (
|
|
||||||
('airport', _('В аэропорту')),
|
|
||||||
('city', _('По городу')),
|
|
||||||
('other', _('По договоренности'))
|
|
||||||
)
|
|
||||||
|
|
||||||
cargo_type_choices = (
|
# form.fields['from_place'].choices = transfer_location_choices
|
||||||
('cargo', _('Груз')),
|
# form.fields['to_place'].choices = transfer_location_choices
|
||||||
('parcel', _('Бандероль')),
|
# form.fields['cargo_type'].choices = cargo_type_choices
|
||||||
('package', _('Посылка')),
|
#
|
||||||
('letter', _('Письмо\Документ'))
|
# 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
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
# form = CreateRouteForm(initial=data)
|
# form = CreateRouteForm(initial=data)
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ def edit_route_ajax(request):
|
|||||||
route = Route.objects.get(id=data['route_id'])
|
route = Route.objects.get(id=data['route_id'])
|
||||||
|
|
||||||
form = RouteForm(instance=route)
|
form = RouteForm(instance=route)
|
||||||
|
form = routeForm_assign_choices_by_type_transport(form, route.type_transport)
|
||||||
|
|
||||||
route_address_points_Dict = route.get_address_points()
|
route_address_points_Dict = route.get_address_points()
|
||||||
form.initial.update({
|
form.initial.update({
|
||||||
'from_address_point_txt': route_address_points_Dict['from_address_point_txt'],
|
'from_address_point_txt': route_address_points_Dict['from_address_point_txt'],
|
||||||
|
|||||||
Reference in New Issue
Block a user