hawat.view.mixin module

This module contains usefull view mixin classes for Hawat application views.

class hawat.view.mixin.AJAXMixin[source]

Bases: object

Mixin class enabling rendering responses as JSON documents. Use it in your custom view classess based on based on hawat.view.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, level='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.

  • level (str) – Severity level 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.

get_blocked_response_context_keys()[source]

Returns a list of reponse context keys that will be removed in the hawat.view.mixin.AJAXMixin.process_response_context()

Returns

a list of response context keys to be removed

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.

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.view.mixin.HTMLMixin[source]

Bases: object

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

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

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

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

Parameters
  • message (str) – Message text.

  • level (str) – Severity level 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.view.mixin.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.view.mixin.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.

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

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.

property search_by

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

class hawat.view.mixin.SnippetMixin[source]

Bases: AJAXMixin

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

KW_RESP_RENDER = '_render'
KW_RESP_SNIPPETS = 'snippets'
flash(message, level='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.

  • level (str) – Severity level of the flash message.

process_response_context()[source]

Reimplementation of hawat.view.mixin.AJAXMixin.process_response_context().

renders = []
snippets = []