
Untitled
By: a guest on
Aug 22nd, 2012 | syntax:
None | size: 0.57 KB | hits: 6 | expires: Never
def require(parameters, status=400):
"""
View decorator that requires the wrapped view to contain each of the fields
in the `parameters` argument as part of the query string, or else aborts the
request with the HTTP error corresponding to the `status` argument.
"""
def decorator(view):
@functools.wraps(view)
def inner(*args, **kwargs):
if not all((field in request.args for field in parameters)):
abort(status)
else:
return view(*args, **kwargs)
return inner
return decorator