App Docs

Configuration

These classes can be found in the backend/config.py file, and should be customized to your needs.

class backend.config.BaseConfig[source]

Configuration options common to all environments.

class backend.config.DevConfig[source]

Configuration options for running in the development environment.

class backend.config.ProdConfig[source]

Configuration options for running in the production environment.

class backend.config.TestConfig[source]

Configuration options for running in the test environment.

App Factory

backend.app.create_app()[source]

Creates a pre-configured Flask application.

Defaults to using backend.config.ProdConfig, unless the FLASK_DEBUG environment variable is explicitly set to “true”, in which case it uses backend.config.DevConfig. Also configures paths for the templates folder and static files.

backend.app._create_app(config_object: backend.config.BaseConfig, **kwargs)[source]

Creates a Flask application.

Parameters:
  • config_object (object) – The config class to use.
  • kwargs (dict) – Extra kwargs to pass to the Flask constructor.

The following methods are all automatically called by backend.app._create_app():

backend.app.configure_app(app, config_object)[source]

General application configuration:

  • register the app’s config
  • register Jinja extensions
  • register functions to run on before/after request
backend.app.register_extensions(app, extensions)[source]

Register and initialize extensions.

backend.app.register_blueprints(app)[source]

Register bundle views.

backend.app.register_models(app)[source]

Register bundle models.

backend.app.register_serializers(app)[source]

Register bundle serializers.

backend.app.register_cli_commands(app)[source]

Register all the Click commands declared in backend/commands and each bundle’s commands

backend.app.register_shell_context(app, extensions)[source]

Register variables to automatically import when running python manage.py shell.

Bundles

class backend.magic.Bundle(module_name, admin_category_name=None, admin_icon_class=None, admins_module_name=<object object>, commands_module_name=<object object>, command_group_names=<object object>, models_module_name=<object object>, serializers_module_name=<object object>, views_module_name=<object object>, blueprint_names=<object object>)[source]

A helper class for auto-registering a group of commands, views, models, serializers and admins with the app.

Bundles are organized just as standard Python modules. If you want to customize any of the default names, you can do so in the constructor.

Each bundle’s modules are auto-detected if they exist, and will be registered if so. All are optional.

Simple bundle example:

$ tree
backend/
└── simple/
    ├── __init__.py
    ├── admins.py
    ├── commands.py
    ├── models.py
    ├── serializers.py
    └── views.py

Big bundle example:

$ tree
backend/
└── big/
    ├── __init__.py
    ├── admins
    │   ├── __init__.py  # must import all ModelAdmin(s)
    │   ├── one_admin.py
    │   └── two_admin.py
    ├── commands
    │   ├── __init__.py  # must import the click group from .group and
    │   │                # all commands
    │   ├── group.py     # the group should have the same name as the
    │   │                # bundle's folder, or to change it, pass
    │   │                # the command_group_names kwarg to Bundle
    │   ├── one.py
    │   └── two.py
    ├── models
    │   ├── __init__.py  # must import all Model(s)
    │   ├── one.py
    │   └── two.py
    ├── serializers
    │   ├── __init__.py  # must import all ModelSerializer(s)
    │   ├── one_serializer.py
    │   └── two_serializer.py
    └── views
        ├── __init__.py  # must import the Blueprint(s) from .blueprint
        │                # and all ModelResource(s)
        ├── blueprint.py # the blueprint should have the same name as the
        │                # bundle's folder, or to change it, pass the
        │                # blueprint_names kwarg to Bundle
        ├── one_resource.py
        └── two_resource.py

In both cases, backend/<bundle_folder_name>/__init__.py is the same:

$ cat backend/<bundle_folder_name>/__init__.py
from backend.magic import Bundle

bundle = Bundle(__name__)

Finally, the bundle modules must be registered in backend/config.py:

BUNDLES = [
    'backend.simple',
    'backend.big',
]
Parameters:
  • module_name (str) – Top-level module name of the bundle (dot notation)
  • admin_category_name (str) – Label to use for the bundle in the admin
  • admin_icon_class (str) – Icon class to use for the bundle in the admin
  • admins_module_name (str) – Folder or module name of the admins in the bundle
  • commands_module_name (str) – Folder or module name of the commands in the bundle
  • command_group_names (Iterable[str]) – List of the bundle’s command group names. Defaults to [<bundle_folder_name>]
  • models_module_name (str) – Folder or module name of the models in the bundle
  • serializers_module_name (str) – Folder or module name of the serializers in the bundle
  • views_module_name (str) – Folder or module name of the views in the bundle
  • blueprint_names (Iterable[str]) – List of Blueprint name(s) to register. Defaults to [<bundle_folder_name>] (NOTE: names of the instance variables, not the Blueprints’ endpoint names.)