Skip to content

Instantly share code, notes, and snippets.

@kotnik
Last active December 23, 2015 01:39
Show Gist options
  • Save kotnik/6561982 to your computer and use it in GitHub Desktop.
Save kotnik/6561982 to your computer and use it in GitHub Desktop.
Validate schema with Colander for either uuid or mail are in the request.
@deferred
def deferred_check_missing(node, kw):
try:
json_request = kw.get("request").json_body
except ValueError:
raise Invalid(node, "Malformed JSON provided")
if "mail" not in json_request and "uuid" not in json_request:
raise Invalid(node, "Both mail and uuid are missing")
return None
class ImportSchema(ACLMappingSchema):
mail = SchemaNode(String(),
missing=deferred_check_missing,
)
uuid = SchemaNode(String(),
missing=None
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment