Created
March 25, 2015 22:23
-
-
Save MarneeDear/7b7f87dda8019f1d433f to your computer and use it in GitHub Desktop.
DECORATOR Validate activate user json
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
__author__ = 'marnee' | |
import functools | |
from validators import validate_user_schema | |
def validate_json(func): | |
def _decorator(json_obj, *args, **kwargs): | |
# validate json | |
if validate_user_schema.validate_activate_user(json_obj): | |
return func(json_obj) | |
else: | |
return False | |
return functools.wraps(func)(_decorator) | |
@validate_json | |
def process_json(json_obj): | |
user = json_obj['user'] | |
print user | |
user_json = { | |
"user": { | |
"email": "email@email.com" | |
} | |
} | |
process_json(user_json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment