hawat.base module¶
-
class
hawat.base.
HawatApp
(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
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 theflask.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_model
(name)[source]¶ Return reference to class of given model.
- Parameters
name (str) – Name of the model.
-
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_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 keyhawat.const.CFGKEY_ENABLED_BLUEPRINTS
.Call blueprint`s
register_app
method, if available, withself
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 provideget_blueprint
factory method, that must return valid instance ofhawat.app.HawatBlueprint
. This method will call thehawat.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.
-
class
hawat.base.
HawatBlueprint
(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
-
name
= None¶
-
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¶
-