From b2a76abe017b5e6b73375c46280d1aba24181ea3 Mon Sep 17 00:00:00 2001 From: SDE Date: Mon, 13 Jan 2025 02:04:16 +0300 Subject: [PATCH] 2.1.11 split mover and customer forms --- RoutesApp/forms.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/RoutesApp/forms.py b/RoutesApp/forms.py index 1c79498..8188075 100644 --- a/RoutesApp/forms.py +++ b/RoutesApp/forms.py @@ -86,18 +86,22 @@ class RouteForm(forms.ModelForm): # if error: # self.add_error('extra_phone', error) - if 'departure_DT' in cleaned_data and 'arrival_DT' in cleaned_data and cleaned_data['arrival_DT'] < cleaned_data['departure_DT']: + if ( + 'departure_DT' in cleaned_data and 'arrival_DT' in cleaned_data + and cleaned_data['arrival_DT'] and cleaned_data['departure_DT'] + and cleaned_data['arrival_DT'] < cleaned_data['departure_DT'] + ): self.add_error('arrival_DT', _('Указана неверная дата прибытия')) - if 'from_place' in self.data and self.data['from_place'] not in [item[0] for item in self.fields['from_place'].choices]: - cleaned_data['from_place'] = self.fields['from_place'].choices[0][0] - if 'from_place' in self.errors and self.errors['from_place'].data[0].code == 'invalid_choice': - del self.errors['from_place'] - if 'to_place' in self.data and self.data['to_place'] not in [item[0] for item in self.fields['to_place'].choices]: - cleaned_data['to_place'] = self.fields['to_place'].choices[0][0] - if 'to_place' in self.errors and self.errors['to_place'].data[0].code == 'invalid_choice': - del self.errors['to_place'] + # if 'from_place' in self.data and self.data['from_place'] not in [item[0] for item in self.fields['from_place'].choices]: + # cleaned_data['from_place'] = self.fields['from_place'].choices[0][0] + # if 'from_place' in self.errors and self.errors['from_place'].data[0].code == 'invalid_choice': + # del self.errors['from_place'] + # if 'to_place' in self.data and self.data['to_place'] not in [item[0] for item in self.fields['to_place'].choices]: + # cleaned_data['to_place'] = self.fields['to_place'].choices[0][0] + # if 'to_place' in self.errors and self.errors['to_place'].data[0].code == 'invalid_choice': + # del self.errors['to_place'] if 'cargo_type' in self.data and self.data['cargo_type'] not in [item[0] for item in self.fields['cargo_type'].choices]: cleaned_data['cargo_type'] = self.fields['cargo_type'].choices[0][0] if 'cargo_type' in self.errors and self.errors['cargo_type'].data[0].code == 'invalid_choice':