vial.app module

This module contains extended flask.Flask and flask.Blueprint classes that form the new base of Vial application.

class vial.app.Vial(import_name, **kwargs)[source]

Bases: flask.app.Flask

Custom implementation of flask.Flask class. This class extends the capabilities of the base class with following additional features:

Configuration based blueprint registration

The application configuration file contains a directive describing list of requested blueprints/modules, that should be registered into the application. This enables administrator to very easily fine tune the application setup for each installation. See the vial.app.Vial.register_blueprints() for more information on the topic.

Application main menu management

The application provides three distinct menus, that are at a disposal for blueprint/module designer.

add_url_rule(rule, endpoint=None, view_func=None, provide_automatic_options=None, **options)[source]

Reimplementation of flask.Flask.add_url_rule() method. This method is capable of disabling selected application endpoints. Keep in mind, that some URL rules (like application global ‘static’ endpoint) are created during the flask.app.Flask.__init__() method and cannot be disabled, because at that point the configuration of the application is not yet loaded.

can_access_endpoint(endpoint, **kwargs)[source]

Check, that the current user can access given endpoint/view.

Parameters
  • endpoint (str) – Application routing endpoint.

  • kwargs (dict) – Optional endpoint parameters.

Returns

True in case user can access the endpoint, False otherwise.

Return type

bool

get_endpoint_class(endpoint, quiet=False)[source]

Get reference to view class registered to given routing endpoint.

Parameters
  • endpoint (str) – Application routing endpoint.

  • quiet (bool) – Suppress the exception in case given endpoint does not exist.

Returns

Reference to view class.

Return type

class

get_endpoints(filter_func=None)[source]

Get all currently registered application endpoints.

get_model(name)[source]

Return reference to class of given model.

Parameters

name (str) – Name of the model.

get_modules(filter_func=None)[source]

Get all currently registered application modules.

get_resource(name)[source]

Return reference to given registered resource.

Parameters

name (str) – Name of the resource.

has_endpoint(endpoint)[source]

Check if given routing endpoint is available.

Parameters

endpoint (str) – Application routing endpoint.

Returns

True in case endpoint exists, False otherwise.

Return type

bool

property icons

Application icon registry.

log_exception(exc_info)[source]

Reimplementation of flask.Flask.log_exception() method.

log_exception_with_label(tbexc, label='')[source]

Log given exception traceback into application logger.

register_blueprint(blueprint, **options)[source]

Reimplementation of flask.Flask.register_blueprint() method. This method will perform standart blueprint registration and on top of that will perform following additional tasks:

  • Register blueprint into custom internal registry. The registry lies within application`s config under key vial.const.CFGKEY_ENABLED_BLUEPRINTS.

  • Call blueprint`s register_app method, if available, with self as only argument.

Parameters
  • blueprint (vial.app.VialBlueprint) – Blueprint to be registered.

  • options (dict) – Additional options, will be passed down to flask.Flask.register_blueprint().

register_blueprints()[source]

Register all configured application blueprints. The configuration comes from vial.const.CFGKEY_ENABLED_BLUEPRINTS configuration subkey, which must contain list of string names of required blueprints. The blueprint module must provide get_blueprint factory method, that must return valid instance of vial.app.VialBlueprint. This method will call the vial.app.Vial.register_blueprint() for each blueprint, that is being registered into the application.

Raises

vial.app.VialException – In case the factory method get_blueprint is not provided by loaded module.

send_infomail(name, **kwargs)[source]

Send emails through all registered infomailer handles.

Parameters
  • name (str) – Name of the informailer.

  • **kwargs

    Additional mailer arguments.

set_infomailer(name, mailer)[source]

Register mailer handle to be usable by different web interface components.

Parameters
  • name (str) – Name of the informailer.

  • mailer (callable) – Mailer handle.

set_resource(name, resource)[source]

Store reference to given resource.

Parameters
  • name (str) – Name of the resource.

  • resource – Resource to be registered.

setup_app()[source]

Perform setup of the whole application.

class vial.app.VialBlueprint(name, import_name, **kwargs)[source]

Bases: flask.blueprints.Blueprint

Custom implementation of flask.Blueprint class. This class extends the capabilities of the base class with additional features:

  • Support for better integration into application and registration of view classes.

  • Support for custom tweaking of application object.

  • Support for custom style of authentication and authorization decorators

get_module_icon()[source]

Return icon name for the module. Given name will be used as index to built-in icon registry.

Returns

Icon for the module.

Return type

str

classmethod get_module_title()[source]

Get human readable name for this blueprint/module.

Returns

Name (short summary) of the blueprint/module.

Return type

str

register_app(app)[source]

Hook method: Custom callback, which will be called from vial.app.Vial.register_blueprint() method and which can perform additional tweaking of Vial application object.

Parameters

app (vial.app.Vial) – Application object.

register_view_class(view_class, route_spec)[source]

Register given view class into the internal blueprint registry.

Parameters
  • view_class (vial.view.BaseView) – View class (not instance!)

  • route_spec (str) – Routing information for the view.

exception vial.app.VialException[source]

Bases: Exception

Custom class for vial.app.Vial application exceptions.