hawat.base module

This module contains implementations of base classes for Hawat application pluggable modules. Since the Hawat application is based on excelent Flask microframework, the modularity and extendability of the application is already built-in as blueprint feature. However this module provides customized classes for application, blueprint and view, that provide some additional features that are out of the scope of bare Flask microframework.

Module contents

class hawat.base.AJAXMixin[source]

Bases: object

Mixin class enabling rendering responses as JSON documents. Use it in your custom view classess based on based on hawat.base.RenderableView to provide the ability to generate JSON responses.

KW_RESP_FLASH_MESSAGES = 'flash_messages'
KW_RESP_VIEW_ICON = 'view_icon'
KW_RESP_VIEW_TITLE = 'view_title'
static abort(status_code, message=None)[source]

Abort request processing with flask.abort function and custom status code and optional additional message. Return response as JSON document.

flash(message, category='info')[source]

Display a one time message to the user. This implementation uses the flash_messages subkey in returned JSON document to store the messages.

Parameters
  • message (str) – Message text.

  • category (str) – Category of the flash message.

generate_response(view_template=None)[source]

Generate the response appropriate for this view class, in this case JSON document.

Parameters

view_template (str) – Override internally preconfigured page template.

process_response_context()[source]

Perform additional mangling with the response context before generating the response. This method can be useful to delete some context keys, that should not leave the server.

Parameters

response_context (dict) – Response context.

Returns

Possibly updated response context.

Return type

dict

redirect(target_url=None, default_url=None, exclude_url=None)[source]

Redirect user to different page. This implementation stores the redirection target to the JSON response.

Parameters
  • target_url (str) – Explicit redirection target, if possible.

  • default_url (str) – Default redirection URL to use in case it cannot be autodetected from the response.

  • exclude_url (str) – URL to which to never redirect (for example never redirect back to the item detail after the item deletion).

class hawat.base.BaseSearchView[source]

Bases: hawat.base.RenderableView, hawat.base.HawatUtils

Base class for search views.

dispatch_request()[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

This hook method will be called after successfull search.

This hook method will be called before search attempt.

classmethod get_action_menu()[source]

Get action menu for all items.

classmethod get_breadcrumbs_menu()[source]

Get breadcrumbs menu.

classmethod get_context_action_menu()[source]

Implementation of hawat.base.ItemListView.get_context_action_menu().

static get_query_parameters(form, request_args)[source]

Get query parameters by comparing contents of processed form data and original request arguments. Result of this method can be used for generating modified URLs back to current request. One of the use cases is the result pager/paginator.

classmethod get_quicksearch_by_time()[source]

Get default list of ‘by time’ quickseach items.

static get_search_form(request_args)[source]

Hook method. Must return instance of flask_wtf.FlaskForm appropriate for given search type.

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

search(form_args)[source]

Perform actual search with given query.

class hawat.base.BaseView[source]

Bases: flask.views.View

Base class for all custom Hawat application views.

authentication = False

Similar to the decorators mechanism in Flask pluggable views, you may use this class variable to specify, that the view is protected by authentication. During the process of registering the view into the blueprint in hawat.base.HawatBlueprint.register_view_class() the view will be automatically decorated with flask_login.login_required() decorator.

The advantage of using this in favor of decorators is that the application menu can automatically hide/show items inaccessible to current user.

This is a scalar variable that must contain boolean True or False.

authorization = ()

Similar to the decorators mechanism in Flask pluggable views, you may use this class variable to specify, that the view is protected by authorization. During the process of registering the view into the blueprint in hawat.base.HawatBlueprint.register_view_class() the view will be automatically decorated with given authorization decorators.

The advantage of using this in favor of decorators is that the application menu can automatically hide/show items inaccessible to current user.

This is a list variable that must contain list of desired decorators.

static 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

static get_endpoint_class(endpoint)[source]

Get reference to view class registered to given routing endpoint.

Parameters

endpoint (str) – Application routing endpoint.

Returns

Reference to view class.

Return type

class

classmethod get_menu_legend(**kwargs)[source]

Return menu entry legend for the view (menu entry hover tooltip).

Default implementation returns the return value of mydojo.base.BaseView.get_menu_title() method by default.

Parameters

kwargs (dict) – Optional parameters.

Returns

Menu entry legend for the view.

Return type

str

classmethod get_menu_title(**kwargs)[source]

Return menu entry title for the view.

Default implementation returns the return value of mydojo.base.BaseView.get_view_title() method by default.

Parameters

kwargs (dict) – Optional parameters.

Returns

Menu entry title for the view.

Return type

str

classmethod get_view_endpoint()[source]

Return name of the routing endpoint for the view within the whole application.

Default implementation generates the endpoint name by concatenating the module name and view name.

Returns

Routing endpoint for the view within the whole application.

Return type

str

classmethod get_view_icon()[source]

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

Default implementation generates the icon name by concatenating the prefix module- with module name.

Returns

Menu entry icon for the view.

Return type

str

classmethod get_view_name()[source]

Return unique name for the view. Name must be unique in the namespace of parent blueprint/module and should contain only characters [a-z0-9]. It will be used for generating endpoint name for the view.

This method does not have any default implementation and must be overridden by a subclass.

Returns

Name for the view.

Return type

str

classmethod get_view_title(**kwargs)[source]

Return title for the view, that will be displayed in the title tag of HTML head element and also as the content of page header in h2 tag.

Default implementation returns the return value of mydojo.base.BaseView.get_menu_title() method by default.

Parameters

kwargs (dict) – Optional parameters.

Returns

Title for the view.

Return type

str

classmethod get_view_url(**kwargs)[source]

Return view URL.

Parameters

kwargs (dict) – Optional parameters.

Returns

URL for the view.

Return type

str

static has_endpoint(endpoint)[source]

Check if given routing endpoint is available within the application.

Parameters

endpoint (str) – Application routing endpoint.

Returns

True in case endpoint exists, False otherwise.

Return type

bool

logger

Return current application`s logger object.

module_name = None

Name of the parent module (blueprint). Will be set up during the process of registering the view into the blueprint in hawat.base.HawatBlueprint.register_view_class().

module_ref = None

Weak reference to parent module of this view.

class hawat.base.FileIdView[source]

Bases: hawat.base.BaseView

Base class for indirrect file access views. These views can be used to access and serve files from arbitrary filesystem directories (that are accessible to application process). This can be very usefull for serving files like charts, that are periodically generated into configurable and changeable location. The difference between this view class and FileNameView is, that is this case some kind of identifier is used to access the file and provided class method is responsible for translating this identifier into real file name.

dispatch_request(fileid, filetype)[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

classmethod get_directory_path(fileid, filetype)[source]

This method must return absolute path to the directory, that will be used as a base path for serving files. Parameter fileid may be used internally to further customize the base directory, for example when serving some files places into subdirectories based on some part of the file name (for example to reduce total number of files in base directory).

This method does not have any default implementation and must be overridden by a subclass.

Parameters
  • fileid (str) – Identifier of the requested file.

  • filetype (str) – Type of the requested file.

Returns

Absolute path to the directory for serving files.

Return type

str

classmethod get_filename(fileid, filetype)[source]

This method must return actual name of the file based on given identifier and type.

This method does not have any default implementation and must be overridden by a subclass.

Parameters
  • fileid (str) – Identifier of the requested file.

  • filetype (str) – Type of the requested file.

Returns

Translated name of the file.

Return type

str

classmethod get_view_icon()[source]

Implementation of hawat.base.BaseView.get_view_icon().

class hawat.base.FileNameView[source]

Bases: hawat.base.BaseView

Base class for direct file access views. These views can be used to access and serve files from arbitrary filesystem directories (that are accessible to application process). This can be very usefull for serving files like charts, that are periodically generated into configurable and changeable location.

dispatch_request(filename)[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

classmethod get_directory_path()[source]

Return absolute path to the directory, that will be used as a base path for serving files.

This method does not have any default implementation and must be overridden by a subclass.

Returns

Absolute path to the directory for serving files.

Return type

str

classmethod get_view_icon()[source]

Implementation of hawat.base.BaseView.get_view_icon().

classmethod validate_filename(filename)[source]

Validate given file name to prevent user from accessing restricted files.

In default implementation all files pass the validation.

Parameters

filename (str) – Name of the file to be validated/filtered.

Returns

True in case file name is allowed, False otherwise.

Return type

bool

class hawat.base.HTMLMixin[source]

Bases: object

Mixin class enabling rendering responses as HTML. Use it in your custom view classess based on hawat.base.RenderableView to provide the ability to render Jinja2 template files into HTML responses.

static abort(status_code, message=None)[source]

Abort request processing with flask.abort function and custom status code and optional additional message. Return response as HTML error page.

flash(message, category='info')[source]

Display a one time message to the user. This implementation uses the flask.flash() method.

Parameters
  • message (str) – Message text.

  • category (str) – Category of the flash message.

generate_response(view_template=None)[source]

Generate the response appropriate for this view class, in this case HTML page.

Parameters

view_template (str) – Override internally preconfigured page template.

redirect(target_url=None, default_url=None, exclude_url=None)[source]

Redirect user to different page. This implementation uses the flask.redirect() method to return valid HTTP redirection response.

Parameters
  • target_url (str) – Explicit redirection target, if possible.

  • default_url (str) – Default redirection URL to use in case it cannot be autodetected from the response.

  • exclude_url (str) – URL to which to never redirect (for example never redirect back to the item detail after the item deletion).

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 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.

Returns

Reference to view class.

Return type

class

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

icons

Application icon registry.

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

Log given exception traceback into application logger.

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_HAWAT_BLUEPRINTS.

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

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

Raises

hawat.base.HawatAppException – In case the factory method get_blueprint is not provided by loaded module.

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_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.

exception hawat.base.HawatAppException[source]

Bases: Exception

Custom class for Hawat application exceptions.

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

register_app(app)[source]

Hook method: Custom callback, which will be called from hawat.base.HawatApp.register_blueprint() method and which can perform additional tweaking of Hawat application object.

Parameters

app (hawat.base.HawatApp) – Application object.

register_view_class(view_class, route_spec)[source]

Register given view class into the internal blueprint registry.

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

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

class hawat.base.HawatItemCreateForView[source]

Bases: hawat.base.ItemActionView

Base class for item createfor action views. These views differ a little bit from create action views. They are used to create new items within database, but only for particular defined parent item. One example use case is creating network records for particular abuse group.

static add_parent_to_item(item, parent)[source]

Hook method. Use given parent object for given item object. The actual operation to realize this relationship is highly dependent on current circumstance. It is up to the developer to perform correct set of actions to implement parent - child relationship for particular object types.

dbmodel_par

Hook property. This property must be implemented in each subclass to return reference to appropriate model class for parent objects and that is based on SQLAlchemy declarative base.

dbquery_par

This property contains the reference to SQLAlchemy query object appropriate for particular dbmodel_par property.

dispatch_request(parent_id)[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

This method will attempt to validate the submitted form and create new instance of appropriate item from form data and finally store the item into the database.

static get_item_form()[source]

Hook method. Must return instance of flask_wtf.FlaskForm appropriate for given item class.

classmethod get_view_icon()[source]

Implementation of hawat.base.BaseView.get_view_icon().

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

classmethod get_view_template()[source]

Return Jinja2 template file that should be used for rendering the view content. This default implementation works only in case the view class was properly registered into the parent blueprint/module with hawat.base.HawatBlueprint.register_view_class() method.

Returns

Title for the view.

Return type

str

class hawat.base.HawatUtils[source]

Bases: object

Small utility method class to enable use of those methods both in the view classes and in the Jinja2 templates.

static get_datetime_window(tiid, wtype, moment=None)[source]

Get timestamp of given type (‘current’, ‘previous’, ‘next’) for given time window and optional time moment.

class hawat.base.ItemActionView[source]

Bases: hawat.base.RenderableView

Base class for item action views. These views perform various actions (create/update/delete) with given item class.

classmethod authorize_item_action(item=None)[source]

Perform access authorization for current user to particular item.

changelog_log(item, json_state_before='', json_state_after='')[source]

Log item action into changelog. One of the method arguments is permitted to be left out. This enables logging create and delete actions.

Parameters
  • item (mentat.datatype.sqldb.MODEL) – Item that is being changed.

  • json_state_before (str) – JSON representation of item state before action.

  • json_state_after (str) – JSON representation of item state after action.

check_action_cancel(form, **kwargs)[source]

Check the form for cancel button press and cancel the action.

dbmodel

This property must be implemented in each subclass to return reference to appropriate model class based on SQLAlchemy declarative base.

dbsession

This property contains the reference to current SQLAlchemy database session.

do_after_action(item)[source]

Hook method. Will be called after successfull action handling tasks.

do_before_action(item)[source]

Hook method. Will be called before any action handling tasks.

fetch(item_id)[source]

Perform actual search with given query.

static get_message_cancel(**kwargs)[source]

Hook method. Must return text for flash message in case of action cancel. The text may contain HTML characters and will be passed to flask.Markup before being used, so to certain extend you may emphasize and customize the output.

static get_message_failure(**kwargs)[source]

Hook method. Must return text for flash message in case of action failure. The text may contain HTML characters and will be passed to flask.Markup before being used, so to certain extend you may emphasize and customize the output.

static get_message_success(**kwargs)[source]

Hook method. Must return text for flash message in case of action success. The text may contain HTML characters and will be passed to flask.Markup before being used, so to certain extend you may emphasize and customize the output.

get_url_next()[source]

Hook method. Must return URL for redirection after action success. In most cases there should be call for flask.url_for() function somewhere in this method.

classmethod get_view_icon()[source]

Implementation of hawat.base.BaseView.get_view_icon().

classmethod get_view_template()[source]

Implementation of hawat.base.RenderableView.get_view_template().

classmethod get_view_url(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_url().

class hawat.base.ItemChangeView[source]

Bases: hawat.base.ItemActionView

Base class for single item change views, that are doing some simple modification of item attribute, like enable/disable item, etc.

classmethod change_item(item)[source]

Hook method: Change given item in any desired way.

Parameters

item – Item to be changed/modified.

dispatch_request(item_id)[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

This method will attempt to validate the submitted form, then perform arbitrary mangling action with the item and submit the changes to the database.

classmethod validate_item_change(item)[source]

Perform validation of particular change to given item.

class hawat.base.ItemCreateView[source]

Bases: hawat.base.ItemActionView

Base class for item create action views. These views create new items in database.

dispatch_request()[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

This method will attempt to validate the submitted form and create new instance of appropriate item from form data and finally store the item into the database.

static get_item_form()[source]

Hook method. Must return instance of flask_wtf.FlaskForm appropriate for given item class.

classmethod get_menu_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_menu_title().

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

classmethod get_view_template()[source]

Return Jinja2 template file that should be used for rendering the view content. This default implementation works only in case the view class was properly registered into the parent blueprint/module with hawat.base.HawatBlueprint.register_view_class() method.

Returns

Title for the view.

Return type

str

classmethod get_view_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_title().

classmethod get_view_url(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_url().

class hawat.base.ItemDeleteView[source]

Bases: hawat.base.ItemActionView

Base class for item delete action views. These views delete existing items from database.

dispatch_request(item_id)[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

This method will attempt to validate the submitted form and delete the instance of appropriate item from database in case user agreed to the item removal action.

classmethod get_menu_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_menu_title().

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

classmethod get_view_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_title().

class hawat.base.ItemDisableView[source]

Bases: hawat.base.ItemChangeView

Base class for item disabling views.

classmethod change_item(item)[source]

Interface implementation of hawat.base.ItemChangeView.change_item().

classmethod get_menu_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_menu_title().

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

classmethod get_view_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_title().

classmethod validate_item_change(item)[source]

Perform validation of particular change to given item.

class hawat.base.ItemEnableView[source]

Bases: hawat.base.ItemChangeView

Base class for item enabling views.

classmethod change_item(item)[source]

Interface implementation of hawat.base.ItemChangeView.change_item().

classmethod get_menu_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_menu_title().

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

classmethod get_view_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_title().

classmethod validate_item_change(item)[source]

Perform validation of particular change to given item.

class hawat.base.ItemListView[source]

Bases: hawat.base.RenderableView

Base class for item list views. These views provide quick and simple access to lists of all objects.

dispatch_request()[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

List of all items will be retrieved from database and injected into template to be displayed to the user.

classmethod get_action_menu()[source]

Get action menu for all items.

classmethod get_breadcrumbs_menu()[source]

Get breadcrumbs menu.

classmethod get_context_action_menu()[source]

Get context action menu for particular item.

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

search(form_args)[source]

Perform actual search with given query.

class hawat.base.ItemShowView[source]

Bases: hawat.base.RenderableView

Base class for item show views. These views expect unique item identifier as parameter and are supposed to display specific information about single item.

classmethod authorize_item_action(item)[source]

Perform access authorization for current user to particular item.

dispatch_request(item_id)[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

Single item with given unique identifier will be retrieved from database and injected into template to be displayed to the user.

fetch(item_id)[source]

Perform actual search with given query.

classmethod get_action_menu()[source]

Get action menu for particular item.

classmethod get_breadcrumbs_menu()[source]

Get breadcrumbs menu.

classmethod get_menu_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_menu_title().

classmethod get_view_icon()[source]

Implementation of hawat.base.BaseView.get_view_icon().

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

classmethod get_view_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_title().

classmethod get_view_url(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_url().

class hawat.base.ItemUpdateView[source]

Bases: hawat.base.ItemActionView

Base class for item update action views. These views update existing items in database.

dispatch_request(item_id)[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

This method will attempt to validate the submitted form and update the instance of appropriate item from form data and finally store the item back into the database.

static get_item_form(item)[source]

Hook method. Must return instance of flask_wtf.FlaskForm appropriate for given item class.

classmethod get_menu_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_menu_title().

classmethod get_view_name()[source]

Implementation of hawat.base.BaseView.get_view_name().

classmethod get_view_template()[source]

Return Jinja2 template file that should be used for rendering the view content. This default implementation works only in case the view class was properly registered into the parent blueprint/module with hawat.base.HawatBlueprint.register_view_class() method.

Returns

Title for the view.

Return type

str

classmethod get_view_title(**kwargs)[source]

Implementation of hawat.base.BaseView.get_view_title().

class hawat.base.PsycopgMixin[source]

Bases: object

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

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

Get list of event database table column names.

static get_event_factory()[source]

Get reference to a item factory for converting database records into objects.

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

class hawat.base.RenderableView[source]

Bases: hawat.base.BaseView

Base class for all views, that are rendering content based on Jinja2 templates or returning JSON/XML data.

static abort(status_code, message=None)[source]

Abort request processing with HTTP status code.

do_before_response(**kwargs)[source]

This method will be called just before generating the response. By providing some meaningfull implementation you can use it for some simple item and response context mangling tasks.

Parameters

kwargs – Custom additional arguments.

flash(message, category='info')[source]

Flash information to the user.

generate_response()[source]

Generate the appropriate response from given response context.

Parameters

response_context (dict) – Response context as a dictionary

classmethod get_view_template()[source]

Return Jinja2 template file that should be used for rendering the view content. This default implementation works only in case the view class was properly registered into the parent blueprint/module with hawat.base.HawatBlueprint.register_view_class() method.

Returns

Jinja2 template file to use to render the view.

Return type

str

mark_time(ident, tag='default', label='Time mark', log=False)[source]

Mark current time with given identifier and label for further analysis. This method can be usefull for measuring durations of various operations.

redirect(default_url=None, exclude_url=None)[source]

Redirect user to different location.

class hawat.base.SQLAlchemyMixin[source]

Bases: object

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

static build_query(query, model, form_args)[source]

Hook method. Modify given query according to the given arguments.

dbcolumn_max(dbcolumn)[source]

Find and return the maximal value for given table column.

dbcolumn_min(dbcolumn)[source]

Find and return the minimal value for given table column.

dbmodel

This property must be implemented in each subclass to return reference to appropriate model class based on SQLAlchemy declarative base.

dbquery(dbmodel=None)[source]

This property contains the reference to SQLAlchemy query object appropriate for particular dbmodel property.

dbsession

This property contains the reference to current SQLAlchemy database session.

fetch(item_id)[source]

Fetch item with given primary identifier from the database.

search(form_args)[source]

Perform actual search with given query.

search_by

Return model`s attribute (column) according to which to search for the item.

class hawat.base.SimpleView[source]

Bases: hawat.base.RenderableView

Base class for simple views. These are the most, well, simple views, that are rendering single template file or directly returning some JSON/XML data without any user parameters.

In most use cases, it should be enough to just enhance the default implementation of hawat.base.RenderableView.get_response_context() to inject some additional variables into the template.

dispatch_request()[source]

Mandatory interface required by the flask.views.View.dispatch_request(). Will be called by the Flask framework to service the request.

class hawat.base.SnippetMixin[source]

Bases: hawat.base.AJAXMixin

Mixin class enabling rendering responses as JSON documents. Use it in your custom view classess based on based on hawat.base.RenderableView to provide the ability to generate JSON responses.

KW_RESP_RENDER = '_render'
KW_RESP_SNIPPETS = 'snippets'
flash(message, category='info')[source]

Display a one time message to the user. This implementation uses the flash_messages subkey in returned JSON document to store the messages.

Parameters
  • message (str) – Message text.

  • category (str) – Category of the flash message.

generate_response(view_template=None)[source]

Generate the response appropriate for this view class, in this case JSON document containing ready to use HTML snippets.

Parameters

view_template (str) – Override internally preconfigured page template.

renders = []
snippets = []
class hawat.base.URLParamsBuilder(skeleton=None)[source]

Bases: object

Small utility class for building URL parameter dictionaries for various view endpoints.

Note

This class is still proof of concept and work in progress.

add_kwrule(key, as_list=False, optional=False)[source]

Add new keyword rule to URL parameter builder.

Parameters
  • key (str) – Name of the rule key.

  • as_list (bool) – Indication that the rule parameter is a list of multiple values.

  • optional (bool) – Indication that the rule parameter is optional.

add_rule(key, as_list=False, optional=False)[source]

Add new rule to URL parameter builder.

Parameters
  • key (str) – Name of the rule key.

  • as_list (bool) – Indication that the rule parameter is a list of multiple values.

  • optional (bool) – Indication that the rule parameter is optional.

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

Get URL parameters as dictionary with filled-in values.