hawat.base module

class hawat.base.HawatApp(import_name, **kwargs)[source]

Bases: 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 hawat.base.HawatApp.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.

Mentat config access

The application provides access to Mentat`s core configurations.

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_csag(group_name)[source]

Return list of all registered context search actions for given group name (CSAG: Context Search Action Group).

Parameters

group_name (str) – Name of the group.

Returns

List of all registered context search actions.

Return type

list

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_oads(group_name)[source]

Return list of all registered object additional data services for given object group name (OADS: Additional Object Data Service).

Parameters

group_name (str) – Name of the group.

Returns

List of all object additional data services.

Return type

list

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.

property mconfig

Return Mentat specific configuration sub-dictionary.

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 hawat.const.CFGKEY_ENABLED_BLUEPRINTS.

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

Parameters
  • blueprint (hawat.app.HawatBlueprint) – 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 hawat.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 hawat.app.HawatBlueprint. This method will call the hawat.app.Hawat.register_blueprint() for each blueprint, that is being registered into the application.

Raises

hawat.app.HawatException – 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_csag(group_name, title, view_class, params_builder)[source]

Store new context search action for given group name (CSAG: Context Search Action Group).

Parameters
  • group_name (str) – Name of the group.

  • title (str) – Title for the search action.

  • view_class (class) – Associated view class.

  • params_builder (URLParamsBuilder) – URL parameter builder for this action.

set_csag_url(group_name, title, icon, url_builder)[source]

Store new URL based context search action for given group name (CSAG: Context Search Action Group).

Parameters
  • group_name (str) – Name of the group.

  • title (str) – Title for the search action.

  • icon (str) – Icon for the search action.

  • url_builder (func) – URL builder for this action.

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_oads(group_name, view_class, params_builder)[source]

Store new object additional data services for given object group name (OADS: Additional Object Data Service).

Parameters
  • group_name (str) – Name of the group.

  • view_class (class) – Associated view class.

  • params_builder (URLParamsBuilder) – URL parameter builder for this action.

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 hawat.base.HawatBlueprint(name, import_name, **kwargs)[source]

Bases: 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 hawat.app.Hawat.register_blueprint() method and which can perform additional tweaking of Hawat application object.

Parameters

app (hawat.app.Hawat) – Application object.

register_view_class(view_class, route_spec)[source]

Register given view class into the internal blueprint registry.

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

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

exception hawat.base.HawatException[source]

Bases: Exception

Custom class for hawat.app.Hawat application exceptions.

class hawat.base.PsycopgMixin[source]

Bases: object

Mixin class providing generic interface for interacting with SQL database backend through SQLAlchemy library.

SEARCH_QUERY_QUOTA_CHECK = True
fetch(item_id)[source]

Fetch item with given primary identifier from the database.

static get_db()[source]

Get database connection service.

Returns

database connection service.

Return type

mentat.services.eventstorage.EventStorageService

static get_qname()[source]

Get unique name for the event select query.

static get_qtype()[source]

Get type of the event select query.

static parse_qname(qname)[source]

Get unique name for the event select query.

search(form_args)[source]

Perform actual search of IDEA events using provided query arguments.

Parameters

form_args (dict) – Search query arguments.

Returns

Tuple containing number of items as integer and list of searched items.

Return type

tuple