Commit be2eb14f8620322e3fedec18f01138d64ee225eb
1 parent
990a9752
Exists in
master
fix: origins and destinations duality
When a file is provided, the textarea can be empty.
Showing
1 changed file
with
25 additions
and
2 deletions
Show diff stats
flaskr/forms.py
... | ... | @@ -94,7 +94,7 @@ class EstimateForm(FlaskForm): |
94 | 94 | label=form_content['origin_addresses']['label'], |
95 | 95 | description=form_content['origin_addresses']['description'], |
96 | 96 | validators=[ |
97 | - validators.DataRequired(), | |
97 | + # validators.DataRequired(), | |
98 | 98 | ], |
99 | 99 | render_kw={ |
100 | 100 | "placeholder": form_content['origin_addresses']['placeholder'], |
... | ... | @@ -104,7 +104,7 @@ class EstimateForm(FlaskForm): |
104 | 104 | label=form_content['destination_addresses']['label'], |
105 | 105 | description=form_content['destination_addresses']['description'], |
106 | 106 | validators=[ |
107 | - validators.DataRequired(), | |
107 | + # validators.DataRequired(), | |
108 | 108 | ], |
109 | 109 | render_kw={ |
110 | 110 | "placeholder": form_content['destination_addresses']['placeholder'], |
... | ... | @@ -176,6 +176,29 @@ class EstimateForm(FlaskForm): |
176 | 176 | ) |
177 | 177 | return False |
178 | 178 | |
179 | + # Origins must be set either by field or file | |
180 | + if ( | |
181 | + (not self.origin_addresses.data) | |
182 | + and | |
183 | + (not self.origin_addresses_file.data) | |
184 | + ): | |
185 | + self.origin_addresses.errors.append( | |
186 | + "You need to provide either a list of cities or a file." | |
187 | + ) | |
188 | + return False | |
189 | + | |
190 | + # Destinations must be set either by field or file | |
191 | + if ( | |
192 | + (not self.destination_addresses.data) | |
193 | + and | |
194 | + (not self.destination_addresses_file.data) | |
195 | + ): | |
196 | + self.destination_addresses.errors.append( | |
197 | + "You need to provide either a list of cities or a file." | |
198 | + ) | |
199 | + return False | |
200 | + | |
201 | + # At least one model should be used | |
179 | 202 | uses_at_least_one_model = False |
180 | 203 | for model in models: |
181 | 204 | use_model = getattr(self, 'use_model_%s' % model.slug) |
... | ... |