From d888bbdd3dc8d5e448aaa131ec14746bb1af9279 Mon Sep 17 00:00:00 2001 From: Alexander Darby Date: Mon, 23 May 2022 15:39:17 +0100 Subject: [PATCH] Docs - add detail to custom backend and pagination --- docs/custom_backend.rst | 16 ++++++++++++---- docs/index.rst | 1 + docs/page_size.rst | 30 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 docs/page_size.rst diff --git a/docs/custom_backend.rst b/docs/custom_backend.rst index f0c4dd61..384e7fa4 100644 --- a/docs/custom_backend.rst +++ b/docs/custom_backend.rst @@ -90,7 +90,7 @@ Another way to provide a custom backend using flask proxy could be: import MyCustomBackend from flask import current_app - from medallion import application_instance, set_config + from medallion import application_instance, set_config, register_blueprints MyCustomBackend.init() # Do some setup before attaching to application... (Imagine other steps happening here) @@ -98,7 +98,13 @@ Another way to provide a custom backend using flask proxy could be: current_app.medallion_backend = MyCustomBackend # Do some other stuff... - set_config(application_instance, {...}) + set_config(application_instance, "backend", { + "backend": { + "module": "mypackage.with_backends", + "module_class": "MyCustomBackend", + } + }) + register_blueprints(application_instance) application_instance.run() How to use a different authentication library @@ -109,7 +115,7 @@ If you need or prefer a library different from ``Flask-HTTPAuth``, you can overr .. code-block:: python from flask import current_app - from medallion import application_instance, auth, set_config, init_backend + from medallion import application_instance, auth, set_config, init_backend, register_blueprints # This is a dummy implementation of Flask Auth that always returns false dummy_auth = class DummyAuth(object): @@ -128,6 +134,7 @@ If you need or prefer a library different from ``Flask-HTTPAuth``, you can overr set_config(application_instance, {...}) init_backend(application_instance, {...}) + register_blueprints(application_instance) application_instance.run() How to use a different backend to control users @@ -139,7 +146,7 @@ Our implementation of a users authentication system is not suitable for a produc import MyCustomDBforUsers from flask import current_app - from medallion import application_instance, set_config + from medallion import application_instance, set_config, register_blueprints # This is a dummy implementation of Flask Auth that always returns false dummy_auth = class DummyAuth(object): @@ -163,4 +170,5 @@ Our implementation of a users authentication system is not suitable for a produc current_app.users_config = db # This will make it available inside the Flask instance in case you decide to perform changes to the internal blueprints. init_backend(application_instance, {...}) + register_blueprints(application_instance) application_instance.run() diff --git a/docs/index.rst b/docs/index.rst index fa075a6c..a080f4b8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,6 +14,7 @@ Welcome to medallion's documentation! compatibility custom_backend + page_size mongodb_schema contributing diff --git a/docs/page_size.rst b/docs/page_size.rst new file mode 100644 index 00000000..1b70673f --- /dev/null +++ b/docs/page_size.rst @@ -0,0 +1,30 @@ +Custom Page Size +========================= + +How to set pagination limits +--------------------------------- + +To specify a pagination limit with medallion you should call ``set_config`` +when creating your application. + +.. code-block:: python + + from medallion import application_instance, set_config + + set_config(application_instance, "taxii", {"taxii": {"max_page_size": 100}}) + + +How to access the pagination limit +------------------------------- + +From within your application, you can then access the configured pagination limit +through the ``current_app`` object. + +.. code-block:: python + + from medallion import current_app + + page_size = current_app.taxii_config["max_page_size"] + + +