Last active
December 23, 2015 01:39
-
-
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.
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
@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