Skip to content

Commit

Permalink
Add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
benjreinhart committed May 6, 2021
1 parent 11e5da2 commit eeb338c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
8 changes: 7 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AppBuilder

.. autoclass:: AppBuilder
:members:

.. automethod:: __init__

flask_appbuilder.security.decorators
Expand All @@ -31,6 +31,12 @@ flask_appbuilder.models.decorators

.. autofunction:: renders

flask_appbuilder.hooks
======================
.. automodule:: flask_appbuilder.hooks

.. autofunction:: before_request

flask_appbuilder.api
==============================

Expand Down
58 changes: 35 additions & 23 deletions flask_appbuilder/hooks.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
def before_request(*args, **kwargs):
"""
Use this decorator to add a before_request lifecycle
hook to be executed before each handler in the view.
If invoked with the `only` kwarg, the hook will only
be invoked for the given list of handler methods.
Examples:
@before_request
def ensure_feature_is_enabled(self):
if self.feature_is_disabled:
return self.response_404()
return None
@before_request(only=["create", "update", "delete"])
def ensure_write_mode_enabled(self):
if self.read_only:
return self.response_400()
return None
:param only:
Only kwarg scopes this hook to run only for
the given list of handler methods. If absent,
the hook will be invoked before all handlers.
Use this decorator to enqueue methods to be invoked
before each handler in the view. If method returns
a value other than :code:`None`, then that value
will be returned to the client. If invoked with the
:code:`only` kwarg, the hook will only be invoked for
the given list of handler methods.
Examples::
class MyFeature(ModelView)
@before_request
def ensure_feature_is_enabled(self):
if self.feature_is_disabled:
return self.response_404()
return None
# etc...
class MyView(ModelRestAPI):
@before_request(only=["create", "update", "delete"])
def ensure_write_mode_enabled(self):
if self.read_only:
return self.response_400()
return None
# etc...
:param kwargs:
The :code:`only` kwarg scopes the method being decorated
to run only for the given list of handler methods. If
abset, the method will be invoked before all handlers.
"""
only = kwargs.get("only", None)

Expand Down

0 comments on commit eeb338c

Please sign in to comment.