Skip to content

Instantly share code, notes, and snippets.

@Fedjmike
Last active November 30, 2016 17:11
Show Gist options
  • Save Fedjmike/fccf9940e2c661b7941c96dd5c297cf0 to your computer and use it in GitHub Desktop.
Save Fedjmike/fccf9940e2c661b7941c96dd5c297cf0 to your computer and use it in GitHub Desktop.
with_request_values_positionally
@decorator_with_args
def with_request_values_positionally(view, keys=[], optional_keys=[],
error_view=request_by_json_missing_value):
try:
values = [request.values[key] for key in keys]
#Only catch a KeyError from that particular lookup, not the whole view function
except KeyError:
return error_view()
#None if not present
optional_values = dict_values(request.values, keys)
return view(*values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment