Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 22nd, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def require(parameters, status=400):
  2.     """
  3.     View decorator that requires the wrapped view to contain each of the fields
  4.     in the `parameters` argument as part of the query string, or else aborts the
  5.     request with the HTTP error corresponding to the `status` argument.
  6.     """
  7.     def decorator(view):
  8.         @functools.wraps(view)
  9.         def inner(*args, **kwargs):
  10.             if not all((field in request.args for field in parameters)):
  11.                 abort(status)
  12.             else:
  13.                 return view(*args, **kwargs)
  14.         return inner
  15.     return decorator