Created
August 13, 2010 16:49
-
-
Save fredpalmer/523182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SmartResource(Resource): | |
def form_validation_response(self, e): | |
""" | |
Overridden method from piston's Resource class to handle | |
form validation errors. | |
""" | |
# Create a 400 status_code response | |
resp = rc.BAD_REQUEST | |
# Serialize the error.form.errors object | |
json_errors = json.dumps( | |
dict( | |
(k, map(unicode, v)) | |
for (k,v) in e.form.errors.iteritems() | |
) | |
) | |
resp.write(", " + json_errors) | |
return resp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment