Skip to content

Instantly share code, notes, and snippets.

@fredpalmer
Created August 13, 2010 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredpalmer/523182 to your computer and use it in GitHub Desktop.
Save fredpalmer/523182 to your computer and use it in GitHub Desktop.
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