form.parser.core

onegov.form includes it’s own markdownish form syntax, inspired by https://github.com/maleldil/wmd

The goal of this syntax is to enable the creation of forms through the web, without having to use javascript, html or python code.

Also, just like Markdown, we want this syntax to be readable by humans.

How it works

Internally, the form syntax is converted into a YAML file, which is in turn parsed and turned into a WTForms class. We decided to go for the intermediate YAML file because it’s easy to define a Syntax which correctly supports indentation. Our pyparsing approach was flimsy at best.

Parser Errors

There’s currently no sophisticated error check. It’s possible that the parser misunderstand something you defined without warning. So be careful to check that what you wanted was actually what you got.

Syntax

Fields

Every field is identified by a label, an optional ‘required’ indicator and a field definition. The Label can be any kind of text, not including * and =. The * indicates that a field is required. The = separates the identifier from the definition.

A required field starts like this:

My required field * =

An optional field starts like this:

My optional field =

Following the identifier is the field definition. For example, this defines a textfield:

My textfield = ___

Comments can be added beneath a field, using the same indentation:

My textfield = ___
<< Explanation for my field >>

All characters are allowed except ‘’>’’.

Complex example:

Delivery * =
    (x) I want it delivered
        Alternate Address =
            (x) No
            ( ) Yes
                Street = ___
                << street >>
                Town = ___
        << Alt >>
    ( ) I want to pick it up
<< delivery >>

Kommentar = ...
<< kommentar >>

All possible fields are documented further below.

Fieldsets

Fields are grouped into fieldsets. The fieldset of a field is the fieldset that was last defined:

# Fieldset 1
I belong to Fieldset 1 = ___

# Fieldset 2
I belong to Fieldset 2 = ___

If no fieldset is defined, the fields don’t belong to a fieldset. To stop putting fields in a fieldset, define an empty fieldeset:

# Fieldset 1
I belong to Fieldset 1 = ___

# ...
I don't belong to a Fieldset = ___

Available Fields

Textfield

A textfield consists of exactly three underscores:

I'm a textfield = ___

If the textfield is limited in length, the length can be given:

I'm a limited textfield = ___[50]

The length of such textfields is validated.

Additionally, textfields may use regexes to validate their contents:

I'm a numbers-only textfield = ___/^[0-9]+$

You can combine the length with a regex, though you probably don’t want to:

I'm a length-limited numbers-only textfield = ___[4]/^[0-9]+$

This could be simplified as follows:

I’m a length-limited numbers-only textfield = ___/^[0-9]{0,4}$

Note that you don’t need to specify the beginning (^) and the end ($) of the string, but not doing so might result in unexpected results. For example, while ‘123abc’ is invalid for ___/^[0-9]+$, it is perfectly valid for ___/[0-9]+. The latter only demands that the text starts with a number, not that it only consists of numbers!

Textarea

A textarea has no limit and consists of exactly three dots:

I'm a textarea = ...

Optionally, the number of rows can be passed to the field. This changes the way the textarea looks, not the way it acts:

I'm a textarea with 10 rows = ...[10]

Password

A password field consists of exactly three stars:

I'm a password = ***

E-Mail

An e-mail field consists of exactly three @:

I'm an e-mail field = @@@

URL

An url field consists of the http/https prefix:

I'm an url field = http://
I'm the exact same = https://

Whether or not you enter http or https has no bearing on the validation.

Date

A date (without time) is defined by this exact string: YYYY.MM.DD:

I'm a date field = YYYY.MM.DD

Note that this doesn’t mean that the date format can be influenced.

A date field optionally can be limited to a relative or absolute date range. Note that the edges of the interval are inclusive. The list of possible grains for relative dates are years, months, weeks and days as well as the special value today.

I’m a future date field = YYYY.MM.DD (+1 days..) I’m on today or in the future = YYYY.MM.DD (today..) At least two weeks ago = YYYY.MM.DD (..-2 weeks) Between 2010 and 2020 = YYYY.MM.DD (2010.01.01..2020.12.31)

Datetime

A date (with time) is defined by this exact string: YYYY.MM.DD HH:MM:

I'm a datetime field = YYYY.MM.DD HH:MM
I'm a futue datetime field = YYYY.MM.DD HH:MM (today..)

Again, this doesn’t mean that the datetime format can be influenced.

The same range validation that can be applied to date fields can also be applied to datetime. Note however that the Validation will be applied to to the date portion. The time portion is ignored completely.

Time

A Time is defined by this exact string: HH:MM:

I'm a time field = HH:MM

One more time, this doesn’t mean that the datetime format can be influenced.

Numbers

There are two types of number fields. An integer and a float field:

I'm an integer field = 0..99
I'm an integer field of a different range = -100..100

I'm a float field = 0.00..99.00
I'm an float field of a different range = -100.00..100.00

Integer fields optionally can have a price attached to them which will be multiplied by the supplied integer.

Number of stamps to include = 0..30 (0.85 CHF)

Code

To write code in a certain syntax, use the following:

Description = <markdown>

Currently, only markdown is supported.

Files

A file upload is defined like this:

I'm a file upload field = *.*

This particular example would allow any file. To allow only certain files do something like this:

I'm a image filed = *.png|*.jpg|*.gif
I'm a document = *.doc
I'm any document = *.doc|*.pdf

The files are checked against their file extension. Onegov.form also checks that uploaded files have the mimetype they claim to have and it won’t accept obviously dangerous uploads like binaries (unless you really want to).

Standard Numbers

onegov.form uses python-stdnum to offer a wide range of standard formats that are guaranteed to be validated.

To use, simply use a #, followed by the stdnum format to use:

I'm a valid IBAN (or empty) = # iban
I'm a valid IBAN (required) * = # iban

The format string after the # must be importable from stdnum. In other words, this must work, if you are using ch.ssn (to use an example):

$ python
>>> from stdnum.ch import ssn

This is a bit of an advanced feature and since it delegates most work to an external library there’s no guarantee that a format once used may be reused in the future.

Still, the library should be somewhat stable and the benefit is huge.

To see the available format, have a look at the docs: https://arthurdejong.org/python-stdnum/doc/1.1/index.html#available-formats

Radio Buttons

Radio button fields consist of x radio buttons, out of which one may be preselected. Radio buttons need to be indented on the lines after the definition:

Gender =
    ( ) Female
    ( ) Male
    (x) I don't want to say

Radio buttons also have the ability to define optional form parts. Those parts are only shown if a question was answered a certain way.

Form parts are properly nested if they lign up with the label above them.

For example:

Delivery Method =
    ( ) Pickup
        Pickup Time * = ___
    (x) Address
        Street * = ___
        Town * = ___

Here, the street and the town only need to be provided, if the delivery method is ‘Address’. If the user selects a different option, the fields are not shown and they will not be required.

On the other hand, if ‘Pickup’ is selected, the ‘Pickup Time’ needs to be filled out and the address options are hidden.

This kind of nesting may continue ad infinitum. Meaning you can nest radio buttons as deeply as you like. Note however, that this is discouraged and that your users will not be too happy if you present them with a deeply nested form.

More than one level of nesting is a clear indicator that your form is too complex.

Checkboxes

Checkboxes work exactly like radio buttons, just that you can select multiple fields:

Extras =
    [x] Phone insurance
    [ ] Phone case
    [x] Extra battery

Just like radiobuttons, checkboxes may be nested to created dependencies:

Additional toppings =
    [ ] Salami
    [ ] Olives
    [ ] Other
        Description = ___

Pricing Information

Radio buttons and checkboxes may be priced. For example, the following order form can be modeled:

Node Size =
    ( ) Small (20 USD)
    (x) Medium (30 USD)
    ( ) Large (40 USD)

Extras =
    [x] Second IP Address (20 CHF)
    [x] Backup (20 CHF)

Delivery =
    (x) Pickup (0 CHF)
    ( ) Delivery (5 CHF!)

The additional pricing metadata can be used to provide simple order forms. As in any other form, dependencies are taken into account.

The optional ! at the end of the price indicates that credit card payment will become mandatory if this option is selected. It is possible to achieve this without a price increase too: (0 CHF!)

Attributes

BasicParsedField

_FieldT

ELEMENTS

Classes

LazyElements

CustomLoader

Extends the default yaml loader with customized constructors.

constructor

Adds decorated functions to as constructors to the CustomLoader.

Fieldset

Represents a parsed fieldset.

Choice

Represents a parsed choice.

Field

Represents a parsed field.

PasswordField

Represents a parsed field.

EmailField

Represents a parsed field.

UrlField

Represents a parsed field.

VideoURLField

Represents a parsed field.

DateField

Represents a parsed field.

DatetimeField

Represents a parsed field.

TimeField

Represents a parsed field.

StringField

Represents a parsed field.

TextAreaField

Represents a parsed field.

CodeField

Represents a parsed field.

StdnumField

Represents a parsed field.

IntegerRangeField

Represents a parsed field.

DecimalRangeField

Represents a parsed field.

FileinputBase

FileinputField

Represents a parsed field.

MultipleFileinputField

Represents a parsed field.

OptionsField

RadioField

Represents a parsed field.

CheckboxField

Represents a parsed field.

Functions

create_parser_elements(→ onegov.core.utils.Bunch)

construct_textfield(→ pyparsing.ParseResults)

construct_textarea(→ pyparsing.ParseResults)

construct_syntax(→ pyparsing.ParseResults)

construct_email(→ pyparsing.ParseResults)

construct_url(→ pyparsing.ParseResults)

construct_video_url(→ pyparsing.ParseResults)

construct_stdnum(→ pyparsing.ParseResults)

construct_date(→ pyparsing.ParseResults)

construct_datetime(→ pyparsing.ParseResults)

construct_time(→ pyparsing.ParseResults)

construct_radio(→ pyparsing.ParseResults)

construct_checkbox(→ pyparsing.ParseResults)

construct_fileinput(→ pyparsing.ParseResults)

construct_multiplefileinput(→ pyparsing.ParseResults)

construct_password(→ pyparsing.ParseResults)

construct_decimal_range(→ pyparsing.ParseResults)

construct_integer_range(→ pyparsing.ParseResults)

flatten_fieldsets(→ Iterator[ParsedField])

flatten_fields(→ Iterator[ParsedField])

find_field(→ Fieldset | ParsedField | None)

parse_formcode(→ list[Fieldset])

Takes the given formcode and returns an intermediate representation

parse_field_block(→ ParsedField)

Takes the given parsed field block and yields the fields from it

format_pricing(→ str)

match(→ bool)

Returns true if the given parser expression matches the given text.

try_parse(→ pyparsing.ParseResults | None)

Returns the result of the given parser expression and text, or None.

prepare(→ Iterator[tuple[int, str]])

Takes the raw form source and prepares it for the translation into

ensure_a_fieldset(→ Iterator[tuple[int, str]])

Makes sure that the given lines all belong to a fieldset. That means

validate_indent(→ bool)

Returns False if indent is other than a multiple of 4, else True

translate_to_yaml(→ Iterator[str])

Takes the given form text and constructs an easier to parse yaml

Module Contents

form.parser.core.BasicParsedField: TypeAlias = 'PasswordField | EmailField | UrlField | VideoURLField | DateField | DatetimeField | TimeField |...[source]
form.parser.core._FieldT[source]
form.parser.core.create_parser_elements() onegov.core.utils.Bunch[source]
class form.parser.core.LazyElements[source]
loaded = False[source]
__getattr__(name: str) pyparsing.ParserElement[source]
form.parser.core.ELEMENTS[source]
class form.parser.core.CustomLoader(stream)[source]

Bases: yaml.SafeLoader

Extends the default yaml loader with customized constructors.

class form.parser.core.constructor(tag: str)[source]

Adds decorated functions to as constructors to the CustomLoader.

tag[source]
__call__(fn: Callable[[CustomLoader, ScalarNode], pp.ParseResults]) Callable[[CustomLoader, ScalarNode], pp.ParseResults][source]
form.parser.core.construct_textfield(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_textarea(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_syntax(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_email(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_url(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_video_url(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_stdnum(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_date(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_datetime(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_time(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_radio(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_checkbox(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_fileinput(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_multiplefileinput(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_password(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_decimal_range(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.construct_integer_range(loader: CustomLoader, node: yaml.nodes.ScalarNode) pyparsing.ParseResults[source]
form.parser.core.flatten_fieldsets(fieldsets: Iterable[Fieldset]) Iterator[ParsedField][source]
form.parser.core.flatten_fields(fields: Sequence[ParsedField] | None) Iterator[ParsedField][source]
form.parser.core.find_field(fieldsets: Iterable[Fieldset], id: str | None) Fieldset | ParsedField | None[source]
class form.parser.core.Fieldset(label: str, fields: Sequence[ParsedField] | None = None)[source]

Represents a parsed fieldset.

label[source]
fields = [][source]
property id: str[source]
property human_id: str[source]
find_field(id: str | None = None) Fieldset | ParsedField | None[source]
class form.parser.core.Choice(key: str, label: str, selected: bool = False, fields: Sequence[ParsedField] | None = None)[source]

Represents a parsed choice.

Note: Choices may have child-fields which are meant to be shown to the user if the given choice was selected.

key[source]
label[source]
selected = False[source]
fields = None[source]
class form.parser.core.Field(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Represents a parsed field.

label[source]
_human_id[source]
required[source]
parent = None[source]
fieldset = None[source]
field_help = None[source]
property id: str[source]
property human_id: str[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) _FieldT[source]
parse(value: Any) object[source]
class form.parser.core.PasswordField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['password']] = 'password'[source]
class form.parser.core.EmailField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['email']] = 'email'[source]
class form.parser.core.UrlField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['url']] = 'url'[source]
class form.parser.core.VideoURLField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['video_url']] = 'video_url'[source]
class form.parser.core.DateField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['date']] = 'date'[source]
valid_date_range: pyparsing.ParseResults[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) DateField[source]
parse(value: Any) object[source]
class form.parser.core.DatetimeField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['datetime']] = 'datetime'[source]
valid_date_range: pyparsing.ParseResults[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) DatetimeField[source]
parse(value: Any) object[source]
class form.parser.core.TimeField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['time']] = 'time'[source]
parse(value: Any) object[source]
class form.parser.core.StringField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['text']] = 'text'[source]
maxlength: int | None[source]
regex: Pattern[str] | None[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) StringField[source]
class form.parser.core.TextAreaField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['textarea']] = 'textarea'[source]
rows: int | None[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) TextAreaField[source]
class form.parser.core.CodeField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['code']] = 'code'[source]
syntax: str[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) CodeField[source]
class form.parser.core.StdnumField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['stdnum']] = 'stdnum'[source]
format: str[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) Self[source]
class form.parser.core.IntegerRangeField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['integer_range']] = 'integer_range'[source]
pricing: onegov.form.types.PricingRules[source]
range: IntegerRangeField.range[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) IntegerRangeField[source]
parse(value: Any) object[source]
class form.parser.core.DecimalRangeField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: Field

Represents a parsed field.

type: ClassVar[Literal['decimal_range']] = 'decimal_range'[source]
range: onegov.form.utils.decimal_range[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) DecimalRangeField[source]
parse(value: Any) object[source]
class form.parser.core.FileinputBase[source]
extensions: list[str][source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) _FieldT[source]
class form.parser.core.FileinputField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: FileinputBase, Field

Represents a parsed field.

type: ClassVar[Literal['fileinput']] = 'fileinput'[source]
class form.parser.core.MultipleFileinputField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: FileinputBase, Field

Represents a parsed field.

type: ClassVar[Literal['multiplefileinput']] = 'multiplefileinput'[source]
class form.parser.core.OptionsField[source]
choices: list[Choice][source]
pricing: onegov.form.types.PricingRules[source]
classmethod create(field: pyparsing.ParseResults, identifier: pyparsing.ParseResults, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None) _FieldT[source]
parse(value: Any) Any[source]
class form.parser.core.RadioField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: OptionsField, Field

Represents a parsed field.

type: ClassVar[Literal['radio']] = 'radio'[source]
parse(value: Any) object[source]
class form.parser.core.CheckboxField(label: str, required: bool, parent: ParsedField | None = None, fieldset: Fieldset | None = None, field_help: str | None = None, human_id: str | None = None, **extra_attributes: Any)[source]

Bases: OptionsField, Field

Represents a parsed field.

type: ClassVar[Literal['checkbox']] = 'checkbox'[source]
form.parser.core.parse_formcode(formcode: str, enable_edit_checks: bool = False) list[Fieldset][source]

Takes the given formcode and returns an intermediate representation that can be used to generate forms or do other things.

Parameters:
  • formcode – string representing formcode to be parsed

  • enable_edit_checks – bool to activate additional check after

editing the form. Should only be active originating from forms.validators.py

form.parser.core.parse_field_block(field_block: dict[str, Any], field_classes: dict[str, type[ParsedField]], used_ids: set[str], fieldset: Fieldset, parent: ParsedField | None = None) ParsedField[source]

Takes the given parsed field block and yields the fields from it

form.parser.core.format_pricing(pricing: RawPricing | None) str[source]
form.parser.core.match(expr: pyparsing.ParserElement, text: str) bool[source]

Returns true if the given parser expression matches the given text.

form.parser.core.try_parse(expr: pyparsing.ParserElement, text: str) pyparsing.ParseResults | None[source]

Returns the result of the given parser expression and text, or None.

form.parser.core.prepare(text: str) Iterator[tuple[int, str]][source]

Takes the raw form source and prepares it for the translation into yaml.

form.parser.core.ensure_a_fieldset(lines: Iterable[tuple[int, str]]) Iterator[tuple[int, str]][source]

Makes sure that the given lines all belong to a fieldset. That means adding an empty fieldset before all lines, if none is found first.

form.parser.core.validate_indent(indent: str) bool[source]

Returns False if indent is other than a multiple of 4, else True

form.parser.core.translate_to_yaml(text: str, enable_edit_checks: bool = False) Iterator[str][source]

Takes the given form text and constructs an easier to parse yaml string.

Parameters:
  • text – string to be parsed

  • enable_edit_checks – bool to activate additional checks after

editing a form. Should only be active originating from forms.validators.py