hawat.forms module

This module contains usefull form related classes for Hawat application views.

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

Bases: 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(*args, **kwargs)[source]

Bases: 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:',), {'validators': [<wtforms.validators.Optional object>], 'filters': [<class 'int'>], 'choices': [(5, 5), (10, 10), (20, 20), (25, 25), (50, 50), (100, 100), (200, 200), (250, 250), (500, 500), (1000, 1000), (2500, 2500), (5000, 5000), (10000, 10000), (25000, 25000), (50000, 50000), (100000, 100000)], 'default': 100})>
page = <UnboundField(IntegerField, (l'Page number:',), {'validators': [<wtforms.validators.Optional object>, <wtforms.validators.NumberRange object>], 'filters': [<class 'int'>], 'default': 1})>
submit = <UnboundField(SubmitField, (l'Search',), {})>
class hawat.forms.CommaListField(*args, **kwargs)[source]

Bases: 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(*args, **kwargs)[source]

Bases: 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: 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(*args, **kwargs)[source]

Bases: 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(*args, **kwargs)[source]

Bases: 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(*args, **kwargs)[source]

Bases: 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(_form, field)[source]

Callback for validating user emails or account logins (usernames).

hawat.forms.check_email_list(_form, field)[source]

Callback for validating list of strings.

hawat.forms.check_group_name(_form, field)[source]

Callback for validating group name.

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_null_character(_form, field)[source]

Callback for validating string fields which should not contain 0x00.

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

Callback for validating list of ports.

hawat.forms.check_unique_group(_form, field)[source]

Callback for validating of uniqueness of group name.

hawat.forms.check_unique_login(_form, field)[source]

Callback for validating of uniqueness of user login.

hawat.forms.default_dt()[source]

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

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

Query the database for list of network record sources.

hawat.forms.get_available_groups()[source]

Query the database for list of all available groups.

hawat.forms.get_available_users()[source]

Query the database for list of users.

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.