form.parser.form

Attributes

_FormT

MEGABYTE

DEFAULT_UPLOAD_LIMIT

Classes

WTFormsClassBuilder

Helps dynamically build a wtforms class from parsed blocks.

Functions

parse_form(…)

Takes the given form text, parses it and returns a WTForms form

normalize_label_for_dependency(→ str)

Removes all between '(' and ')' Parentheses (inclusive)

handle_field(→ None)

Takes the given parsed field and adds it to the form.

Module Contents

form.parser.form._FormT[source]
form.parser.form.MEGABYTE[source]
form.parser.form.DEFAULT_UPLOAD_LIMIT[source]
form.parser.form.parse_form(text: str, enable_indent_check: bool, base_class: type[_FormT]) type[_FormT][source]
form.parser.form.parse_form(text: str, enable_indent_check: bool = False, *, base_class: type[_FormT]) type[_FormT]
form.parser.form.parse_form(text: str, enable_indent_check: bool = False, base_class: type[onegov.form.core.Form] = Form) type[onegov.form.core.Form]

Takes the given form text, parses it and returns a WTForms form class (not an instance of it).

Parameters:
  • enable_indent_check – bool to activate indent check while parsing.

  • base_class – Form base class

form.parser.form.normalize_label_for_dependency(label: str) str[source]

Removes all between ‘(’ and ‘)’ Parentheses (inclusive)

form.parser.form.handle_field(builder: WTFormsClassBuilder[Any], field: onegov.form.parser.core.ParsedField, dependency: onegov.form.core.FieldDependency | None = None) None[source]

Takes the given parsed field and adds it to the form.

class form.parser.form.WTFormsClassBuilder(base_class: type[_FormT])[source]

Bases: Generic[_FormT]

Helps dynamically build a wtforms class from parsed blocks.

For example:

builder = WTFormsClassBuilder(BaseClass)
builder.add_field(StringField, label='Name', required=True)

MyForm = builder.form_class
form_class: type[_FormT][source]
current_fieldset: str | None[source]
set_current_fieldset(label: str | None) None[source]
validators_extend(validators: list[Validator[Any, Any]], required: bool, dependency: onegov.form.core.FieldDependency | None) None[source]
validators_add_required(validators: list[Validator[Any, Any]]) None[source]
validators_add_dependency(validators: list[Validator[Any, Any]], dependency: onegov.form.core.FieldDependency) None[source]
validators_add_optional(validators: list[Validator[Any, Any]]) None[source]
mark_as_dependent(field_id: str, dependency: onegov.form.core.FieldDependency) None[source]
get_unique_field_id(label: str, dependency: onegov.form.core.FieldDependency | None) str[source]
add_field(field_class: type[wtforms.Field], field_id: str, label: str, required: bool, dependency: onegov.form.core.FieldDependency | None = None, pricing: PricingRules | None = None, validators: list[Validator[Any, Any]] | None = None, description: str | None = None, widget: Widget[Any] | None = None, render_kw: dict[str, Any] | None = None, **extra_field_kwargs: Any) wtforms.Field[source]