Skip to content

Commit

Permalink
[#1258] Allow context['schema'] and skip validate in validate decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
joetsoi committed Nov 5, 2013
1 parent e119439 commit 8b62a87
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ckan/logic/__init__.py
Expand Up @@ -502,13 +502,21 @@ def get_or_bust(data_dict, keys):
return values[0]
return tuple(values)

def validate(schema_func):
def validate(schema_func, check_schema_in_context=False, can_skip_validator=False):
''' A decorator that validates an action function against a given schema
'''
def action_decorator(action):
@functools.wraps(action)
def wrapper(context, data_dict, **kwargs):
schema = schema_func()
if can_skip_validator:
if context.get('skip_validation'):
return action(context, data_dict)

if not check_schema_in_context:
schema = schema_func()
else:
schema = context.get('schema') or schema()

data_dict, errors = _validate(data_dict, schema, context)
if errors:
raise ValidationError(errors)
Expand Down

0 comments on commit 8b62a87

Please sign in to comment.