hawat.forms module

This module contains common forms for Hawat application.

List of available forms:

hawat.forms.ItemDeleteForm

Generic item deletion confirmation form.

class hawat.forms.BaseItemForm(*args, **kwargs)[source]

Bases: flask_wtf.form.FlaskForm

Class representing generic item action (create/update/delete) form for Hawat application.

This form contains support for redirection back to original page.

static is_multivalue(field_name)[source]

Check, if given form field is a multivalue field.

Parameters

field_name (str) – Name of the form field.

Returns

True, if the field can contain multiple values, False otherwise.

Return type

bool

next = <UnboundField(HiddenField, (), {})>
class hawat.forms.BaseSearchForm(formdata=<object object>, **kwargs)[source]

Bases: flask_wtf.form.FlaskForm

Class representing generic item search form for Hawat application.

This form contains support for result limiting and paging.

static is_multivalue(field_name)[source]

Check, if given form field is a multivalue field.

Parameters

field_name (str) – Name of the form field.

Returns

True, if the field can contain multiple values, False otherwise.

Return type

bool

limit = <UnboundField(SelectField, (l'Pager limit:',), {'default': 100, 'filters': [<class 'int'>], 'validators': [<wtforms.validators.Optional object>], 'choices': [(5, 5), (10, 10), (20, 20), (30, 30), (50, 50), (100, 100), (200, 200), (500, 500), (1000, 1000), (10000, 10000)]})>
page = <UnboundField(IntegerField, (l'Page number:',), {'default': 1, 'validators': [<wtforms.validators.Optional object>, <wtforms.validators.NumberRange object>], 'filters': [<class 'int'>]})>
submit = <UnboundField(SubmitField, (l'Search',), {})>
class hawat.forms.CommaListField(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, _form=None, _name=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.core.Field

Custom widget representing list of strings as comma separated list.

process_formdata(valuelist)[source]

Process data received over the wire from a form.

This will be called during form construction with data supplied through the formdata argument.

Parameters

valuelist – A list of strings to process.

widget = <wtforms.widgets.core.TextInput object>
class hawat.forms.DateTimeLocalField(label=None, validators=None, format='%Y-%m-%d %H:%M:%S', **kwargs)[source]

Bases: wtforms.fields.core.DateTimeField

DateTimeField that assumes input is in app-configured timezone and converts to UTC for further processing/storage.

process_data(value)[source]

Process the Python data applied to this field and store the result. This will be called during form construction by the form’s kwargs or obj argument. :param value: The python object containing the value to process.

process_formdata(valuelist)[source]

Process data received over the wire from a form. This will be called during form construction with data supplied through the formdata argument. :param valuelist: A list of strings to process.

class hawat.forms.ItemActionConfirmForm(*args, **kwargs)[source]

Bases: hawat.forms.BaseItemForm

Class representing generic item action confirmation form for Hawat application.

This form contains nothing else but two buttons, one for confirmation, one for canceling the delete action. Actual item identifier is passed as part of the URL.

cancel = <UnboundField(SubmitField, (l'Cancel',), {})>
submit = <UnboundField(SubmitField, (l'Confirm',), {})>
class hawat.forms.RadioFieldWithNone(label=None, validators=None, coerce=<class 'str'>, choices=None, **kwargs)[source]

Bases: wtforms.fields.core.RadioField

RadioField that accepts None as valid choice.

pre_validate(form)[source]

Override if you need field-level validation. Runs before any other validators.

Parameters

form – The form the field belongs to.

process_formdata(valuelist)[source]

Process data received over the wire from a form.

This will be called during form construction with data supplied through the formdata argument.

Parameters

valuelist – A list of strings to process.

class hawat.forms.SelectFieldWithNone(label=None, validators=None, coerce=<class 'str'>, choices=None, **kwargs)[source]

Bases: wtforms.fields.core.SelectField

SelectField that accepts None as valid choice.

pre_validate(form)[source]

Override if you need field-level validation. Runs before any other validators.

Parameters

form – The form the field belongs to.

process_formdata(valuelist)[source]

Process data received over the wire from a form.

This will be called during form construction with data supplied through the formdata argument.

Parameters

valuelist – A list of strings to process.

class hawat.forms.SmartDateTimeField(label=None, validators=None, formats=None, **kwargs)[source]

Bases: wtforms.fields.core.Field

DateTimeField that assumes input is in app-configured timezone and converts to UTC for further processing/storage. This widget allows multiple datetime representations on input and is smart to recognize ISO formated timestamp in UTC on input, which greatly simplifies generating URLs from within the application.

process_data(value)[source]

Process the Python data applied to this field and store the result. This will be called during form construction by the form’s kwargs or obj argument. :param value: The python object containing the value to process.

process_formdata(valuelist)[source]

Process data received over the wire from a form. This will be called during form construction with data supplied through the formdata argument. :param valuelist: A list of strings to process.

utcisoformat = '%Y-%m-%dT%H:%M:%SZ'
widget = <wtforms.widgets.core.TextInput object>
hawat.forms.check_email_list(form, field)[source]

Callback for validating list of strings.

hawat.forms.check_int_list(form, field)[source]

Callback for validating list of positive integers.

hawat.forms.check_ip4_record(form, field)[source]

Callback for validating IP4 addresses.

hawat.forms.check_ip6_record(form, field)[source]

Callback for validating IP6 addresses.

hawat.forms.check_ip_record(form, field)[source]

Callback for validating IP addresses.

hawat.forms.check_login(form, field)[source]

Callback for validating user account logins (usernames).

hawat.forms.check_network_record(form, field)[source]

Callback for validating network records.

hawat.forms.check_network_record_list(form, field)[source]

Callback for validating list of network records.

hawat.forms.check_port_list(form, field)[source]

Callback for validating list of ports.

hawat.forms.default_dt_with_delta(delta=7)[source]

Create default timestamp for datetime form values with given time delta in days and adjust the result to whole hours.

hawat.forms.get_redirect_target(target_url=None, default_url=None, exclude_url=None)[source]

Get redirection target, either from GET request variable, or from referrer header.

hawat.forms.str_to_bool(value)[source]

Convert given string value to boolean.

hawat.forms.str_to_bool_with_none(value)[source]

Convert given string value to boolean or None.

hawat.forms.str_to_int_with_none(value)[source]

Convert given string value to boolean or None.