The contents of my form must be submitted to another application server for validation and execution (specifically, I call a RESTful web service with the posted values in the form). The service will either return a 200 SUCCESS or a 400/409 error with a body that describes the exact field errors.
When should I do this submission? Should I do it in the view:
if form.is_valid:
result = submit_to_service(POST)
if result.code in (400, 409):
somehow_set_errors_on_the_form(form)
else:
go_on...
Or in the Form.clean method?
def clean(self):
result = submit_to_service(POST)
if result.code in (400, 409):
for field in result.errors:
self._errors[field].append(result.errors[field])
else:
pass
Which of these is clearer?