0.1.2
change type_transport routines
This commit is contained in:
@@ -16,6 +16,28 @@ class CreateRouteForm(forms.ModelForm):
|
||||
'receive_msg_by_sms', 'owner', 'owner_type'
|
||||
]
|
||||
|
||||
def clean(self):
|
||||
# print('check')
|
||||
cleaned_data = super(CreateRouteForm, self).clean()
|
||||
|
||||
data = dict(self.data)
|
||||
|
||||
if 'from_place' in data and data['from_place'] not in [item[0] for item in self.fields['from_place'].choices]:
|
||||
self.cleaned_data['from_place'] = transfer_location_choices[0][0]
|
||||
if 'to_place' in data and data['to_place'] not in [item[0] for item in self.fields['to_place'].choices]:
|
||||
self.cleaned_data['to_place'] = transfer_location_choices[0][0]
|
||||
if 'cargo_type' in data and data['cargo_type'] not in [item[0] for item in self.fields['cargo_type'].choices]:
|
||||
self.cleaned_data['cargo_type'] = cargo_type_choices[0][0]
|
||||
|
||||
# reg_user = check_authorizationBy_cleaned_data(cleaned_data)
|
||||
# # print(reg_user)
|
||||
# if not reg_user:
|
||||
# raise ValidationError(_(u'Пользователь с введенными регистрационными данными не зарегистрирован. Проверьте правильность ввода e-mail и пароля.'))
|
||||
# else:
|
||||
# if not check_activate_by_user(reg_user):
|
||||
# raise ValidationError(_(u'Указанная учетная запись не была Активирована'))
|
||||
return cleaned_data
|
||||
|
||||
|
||||
# class RegistrationForm(forms.Form):
|
||||
# type_transport = forms.ChoiceField(choices=type_transport_choices, initial='avia', required=True, label='Выберите способ перевозки')
|
||||
|
||||
@@ -27,17 +27,77 @@ def new_route_view_ajax(request):
|
||||
|
||||
data = request.POST
|
||||
|
||||
form = CreateRouteForm(data)
|
||||
|
||||
if not form.is_valid():
|
||||
pass
|
||||
|
||||
if form.cleaned_data['type_transport'] == 'avia':
|
||||
pass
|
||||
if 'type_transport' in data:
|
||||
if data['type_transport'] == 'avia':
|
||||
transfer_location_choices = (
|
||||
('airport', _('В аэропорту')),
|
||||
('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 = CreateRouteForm(data)
|
||||
#
|
||||
# if not form.is_valid():
|
||||
# pass
|
||||
|
||||
else:
|
||||
transfer_location_choices = (
|
||||
('city', _('По городу')),
|
||||
('other', _('По договоренности'))
|
||||
)
|
||||
|
||||
cargo_type_choices = (
|
||||
('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
|
||||
|
||||
form = CreateRouteForm(data)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if not form.is_valid():
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Dict = {
|
||||
'form': form
|
||||
}
|
||||
|
||||
# print(form)
|
||||
except Exception as e:
|
||||
form.errors.apend({'__all__': f'Ошибка: {str(e)}'})
|
||||
form.errors.append({'__all__': f'Ошибка: {str(e)}'})
|
||||
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
Reference in New Issue
Block a user