Framework Managers

One design goal of the base grid class is that it be essentially framework-agnostic. That is, the grid, by itself, should not care if it is being run in Flask, BlazeWeb, or another web app framework. As long as it has a connection to the framework that provides required items with a consistent interface, the grid should interact with the framework through that connection.

Wrapped features available through the manager:

  • SQLAlchemy connection and queries

  • Request

  • Session storage

  • Flash messages

  • File export in response

class webgrid.flask.WebGrid(db=None, jinja_loader=None, args_loaders=None, session_max_hours=None, blueprint_name=None, blueprint_class=None)[source]

Grid manager for connecting grids to Flask webapps.

Manager is a Flask extension, and may be bound to an app via init_app.

Instance should be assigned to the manager attribute of a grid class:

class MyGrid(BaseGrid):
    manager = WebGrid()
Args:

db (flask_sqlalchemy.SQLAlchemy, optional): Database instance. Defaults to None. If db is not supplied here, it can be set via init_db later.

Class Attributes:

jinja_loader (jinja.Loader): Template loader to use for HTML rendering.

args_loaders (ArgsLoader[]): Iterable of classes to use for loading grid args, in order of priority

session_max_hours (int): Hours to hold a given grid session in storage. Set to None to disable. Default 12.

blueprint_name (string): Identifier to use for the Flask blueprint on this extension. Default “webgrid”. Needs to be unique if multiple managers are initialized as flask extensions.

blueprint_class

alias of Blueprint

csrf_token()[source]

Return a CSRF token for POST.

file_as_response(data_stream, file_name, mime_type)[source]

Return response from framework for sending a file.

flash_message(category, message)[source]

Add a flash message through the framework.

init_app(app)[source]

Register a blueprint for webgrid assets, and configure jinja templates.

init_blueprint(app)[source]

Create a blueprint for webgrid assets.

init_db(db)[source]

Set the db connector.

persist_web_session()[source]

Some frameworks require an additional step to persist session data.

request()[source]

Return request.

request_form_args()[source]

Return POST request args.

request_json()[source]

Return json body of request.

request_url_args()[source]

Return GET request args.

sa_query(*args, **kwargs)[source]

Wrap SQLAlchemy query instantiation.

static_url(url_tail)[source]

Construct static URL from webgrid blueprint.

test_request_context(url='/')[source]

Get request context for tests.

web_session()[source]

Return current session.