form.fields

Attributes

FIELDS_NO_RENDERED_PLACEHOLDER

Classes

FileDict

dict() -> new empty dictionary

TimeField

Fixes the case for MS Edge Browser that returns the 'valuelist'

TranslatedSelectField

A select field which translates the option labels.

MultiCheckboxField

No different from a normal select field, except this one can take (and

OrderedMultiCheckboxField

No different from a normal select field, except this one can take (and

UploadField

A custom file field that turns the uploaded file into a compressed

UploadFileWithORMSupport

Extends the upload field with onegov.file support.

UploadMultipleField

A custom file field that turns the uploaded files into a list of

_DummyFile

UploadMultipleFilesWithORMSupport

Extends the upload multiple field with onegov.file support.

TextAreaFieldWithTextModules

A textfield with text module selection/insertion.

VideoURLField

Represents an <input type="url">.

HtmlField

A textfield with html with integrated sanitation.

CssField

A textfield with css validation.

MarkupField

A textfield with markup with no sanitation.

TagsField

A tags field for use in conjunction with this library:

IconField

Selects an icon out of a number of icons.

PhoneNumberField

A string field with support for phone numbers.

ChosenSelectField

A select field with chosen.js support.

ChosenSelectMultipleField

A multiple select field with chosen.js support.

ChosenSelectMultipleEmailField

No different from a normal select field, except this one can take (and

PreviewField

Field base class

PanelField

Shows a panel as part of the form (no input, no label).

DateTimeLocalField

A custom implementation of the DateTimeLocalField to fix issues with

TimezoneDateTimeField

A datetime field data returns the date with the given timezone

HoneyPotField

A field to identify bots.

ColorField

A string field that renders a html5 color picker and coerces

TypeAheadField

A string field with typeahead.

Module Contents

class form.fields.FileDict[source]

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

data: str[source]
filename: str | None[source]
mimetype: str[source]
size: int[source]
form.fields.FIELDS_NO_RENDERED_PLACEHOLDER = ('MultiCheckboxField', 'RadioField', 'OrderedMultiCheckboxField', 'UploadField',...[source]
class form.fields.TimeField(label=None, validators=None, format='%H:%M', **kwargs)[source]

Bases: wtforms.fields.TimeField

Fixes the case for MS Edge Browser that returns the ‘valuelist’ as [08:00:000] instead of [08:00:00]. This is only the case of the time is set with the js popup, not when switching the time e.g. with the arrow keys on the form.

process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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 form.fields.TranslatedSelectField(label=None, validators=None, coerce=str, choices=None, validate_choice=True, **kwargs)[source]

Bases: wtforms.fields.SelectField

A select field which translates the option labels.

iter_choices() Iterator[tuple[Any, str, bool, dict[str, Any]]][source]

Provides data for choice widget rendering. Must return a sequence or iterable of (value, label, selected, render_kw) tuples.

class form.fields.MultiCheckboxField(label=None, validators=None, coerce=str, choices=None, validate_choice=True, **kwargs)[source]

Bases: wtforms.fields.SelectMultipleField

No different from a normal select field, except this one can take (and validate) multiple choices. You’ll need to specify the HTML size attribute to the select field when rendering.

widget[source]
option_widget[source]

Base class for fields which can be iterated to produce options.

This isn’t a field, but an abstract base class for fields which want to provide this functionality.

contains_labels = True[source]
class form.fields.OrderedMultiCheckboxField(label=None, validators=None, coerce=str, choices=None, validate_choice=True, **kwargs)[source]

Bases: MultiCheckboxField

No different from a normal select field, except this one can take (and validate) multiple choices. You’ll need to specify the HTML size attribute to the select field when rendering.

widget[source]
class form.fields.UploadField(label: str | None = None, validators: Validators[FormT, Self] | None = None, filters: Sequence[Filter] = (), description: str = '', id: str | None = None, default: Sequence[StrictFileDict] = (), widget: Widget[Self] | None = None, render_kw: dict[str, Any] | None = None, name: str | None = None, _form: BaseForm | None = None, _prefix: str = '', _translations: _SupportsGettextAndNgettext | None = None, _meta: DefaultMeta | None = None, *, fieldset: str | None = None, depends_on: collections.abc.Sequence[Any] | None = None, pricing: onegov.form.types.PricingRules | None = None)[source]

Bases: wtforms.fields.FileField

A custom file field that turns the uploaded file into a compressed base64 string together with the filename, size and mimetype.

widget[source]
action: Literal['keep', 'replace', 'delete'][source]
file: IO[bytes] | None[source]
filename: str | None[source]
property data: StrictFileDict | FileDict | None[source]
property is_image: bool[source]
process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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.

process_fieldstorage(fs: onegov.form.types.RawFormValue) StrictFileDict | FileDict[source]
class form.fields.UploadFileWithORMSupport(*args: Any, **kwargs: Any)[source]

Bases: UploadField

Extends the upload field with onegov.file support.

file_class: type[onegov.file.File][source]
create() File | None[source]
populate_obj(obj: object, name: str) None[source]

Populates obj.<name> with the field’s data.

Note:

This is a destructive operation. If obj.<name> already exists, it will be overridden. Use with caution.

process_data(value: File | None) None[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.

Parameters:

value – The python object containing the value to process.

class form.fields.UploadMultipleField(label: str | None = None, validators: Validators[FormT, UploadField] | None = None, filters: Sequence[Filter] = (), description: str = '', id: str | None = None, default: Sequence[FileDict] = (), widget: Widget[Self] | None = None, render_kw: dict[str, Any] | None = None, name: str | None = None, upload_widget: Widget[UploadField] | None = None, _form: BaseForm | None = None, _prefix: str = '', _translations: _SupportsGettextAndNgettext | None = None, _meta: DefaultMeta | None = None, *, fieldset: str | None = None, depends_on: Sequence[Any] | None = None, pricing: PricingRules | None = None, **extra_arguments: Any)[source]

Bases: UploadMultipleBase, wtforms.fields.FileField

A custom file field that turns the uploaded files into a list of compressed base64 strings together with the filename, size and mimetype.

This acts both like a single file field with multiple and like a list of onegov.form.fields.UploadFile for uploaded files. This way we get the best of both worlds.

widget[source]
raw_data: list[onegov.form.types.RawFormValue][source]
_separator: str[source]
upload_field_class: type[UploadField][source]
upload_widget: Widget[UploadField][source]
__bool__() Literal[True][source]
process(formdata: _MultiDictLikeWithGetlist | None, data: object = unset_value, extra_filters: Sequence[Filter] | None = None) None[source]

Process incoming data, calling process_data, process_formdata as needed, and run filters.

If data is not provided, process_data will be called on the field’s default.

Field subclasses usually won’t override this, instead overriding the process_formdata and process_data methods. Only override this for special advanced processing, such as when a field encapsulates many inputs.

Parameters:

extra_filters – A sequence of extra filters to run.

append_entry_from_field_storage(fs: webob.request._FieldStorageWithFile) UploadField[source]
process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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 form.fields._DummyFile[source]
file: File | None[source]
class form.fields.UploadMultipleFilesWithORMSupport(*args: Any, **kwargs: Any)[source]

Bases: UploadMultipleField

Extends the upload multiple field with onegov.file support.

file_class: type[onegov.file.File][source]
added_files: list[onegov.file.File][source]
upload_field_class[source]
populate_obj(obj: object, name: str) None[source]

Populates obj.<name> with the field’s data.

Note:

This is a destructive operation. If obj.<name> already exists, it will be overridden. Use with caution.

class form.fields.TextAreaFieldWithTextModules(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, name=None, _form=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.TextAreaField

A textfield with text module selection/insertion.

widget[source]
class form.fields.VideoURLField(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, name=None, _form=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.simple.URLField

Represents an <input type="url">.

class form.fields.HtmlField(*args: Any, **kwargs: Any)[source]

Bases: wtforms.fields.TextAreaField

A textfield with html with integrated sanitation.

data: markupsafe.Markup | None[source]
form[source]
pre_validate(form: wtforms.form.BaseForm) None[source]

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

Parameters:

form – The form the field belongs to.

class form.fields.CssField(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, name=None, _form=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.TextAreaField

A textfield with css validation.

post_validate(form: wtforms.form.BaseForm, validation_stopped: bool) None[source]

Override if you need to run any field-level validation tasks after normal validation. This shouldn’t be needed in most cases.

Parameters:
  • form – The form the field belongs to.

  • validation_stoppedTrue if any validator raised StopValidation.

class form.fields.MarkupField(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, name=None, _form=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.TextAreaField

A textfield with markup with no sanitation.

This field is inherently unsafe and should be avoided, use with care!

data: markupsafe.Markup | None[source]
process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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.

process_data(value: str | None) None[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.

Parameters:

value – The python object containing the value to process.

class form.fields.TagsField(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, name=None, _form=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.StringField

A tags field for use in conjunction with this library:

https://github.com/developit/tags-input

widget[source]
data: str | list[str][source]
process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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.

process_data(value: list[str] | None) None[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.

Parameters:

value – The python object containing the value to process.

class form.fields.IconField(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, name=None, _form=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.StringField

Selects an icon out of a number of icons.

widget[source]
class form.fields.PhoneNumberField(*args: Any, country: str = 'CH', **kwargs: Any)[source]

Bases: wtforms.fields.TelField

A string field with support for phone numbers.

country = 'CH'[source]
property formatted_data: str | None[source]
class form.fields.ChosenSelectField(label=None, validators=None, coerce=str, choices=None, validate_choice=True, **kwargs)[source]

Bases: wtforms.fields.SelectField

A select field with chosen.js support.

widget[source]
class form.fields.ChosenSelectMultipleField(label=None, validators=None, coerce=str, choices=None, validate_choice=True, **kwargs)[source]

Bases: wtforms.fields.SelectMultipleField

A multiple select field with chosen.js support.

widget[source]
class form.fields.ChosenSelectMultipleEmailField(label=None, validators=None, coerce=str, choices=None, validate_choice=True, **kwargs)[source]

Bases: wtforms.fields.SelectMultipleField

No different from a normal select field, except this one can take (and validate) multiple choices. You’ll need to specify the HTML size attribute to the select field when rendering.

widget[source]
pre_validate(form: wtforms.form.BaseForm) None[source]

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

Parameters:

form – The form the field belongs to.

class form.fields.PreviewField(*args: Any, fields: Sequence[str] = (), url: Callable[[DefaultMeta], str | None] | str | None = None, events: Sequence[str] = (), display: str = 'inline', **kwargs: Any)[source]

Bases: wtforms.fields.Field

Field base class

fields: Sequence[str][source]
events: Sequence[str][source]
url: Callable[[DefaultMeta], str | None] | str | None[source]
display: str[source]
widget[source]
populate_obj(obj: object, name: str) None[source]

Populates obj.<name> with the field’s data.

Note:

This is a destructive operation. If obj.<name> already exists, it will be overridden. Use with caution.

class form.fields.PanelField(*args: Any, text: str, kind: str, hide_label: bool = True, **kwargs: Any)[source]

Bases: wtforms.fields.Field

Shows a panel as part of the form (no input, no label).

widget[source]
text[source]
kind[source]
hide_label = True[source]
populate_obj(obj: object, name: str) None[source]

Populates obj.<name> with the field’s data.

Note:

This is a destructive operation. If obj.<name> already exists, it will be overridden. Use with caution.

class form.fields.DateTimeLocalField(label: str | None = None, validators: Validators[FormT, Self] | None = None, format: str = '%Y-%m-%dT%H:%M', **kwargs: Any)[source]

Bases: wtforms.fields.DateTimeLocalField

A custom implementation of the DateTimeLocalField to fix issues with the format and the datetimepicker plugin.

process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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 form.fields.TimezoneDateTimeField(*args: Any, timezone: str, **kwargs: Any)[source]

Bases: DateTimeLocalField

A datetime field data returns the date with the given timezone and expects dateime values with a timezone.

Used together with onegov.core.orm.types.UTCDateTime.

data: datetime | None[source]
timezone[source]
process_data(value: datetime | None) None[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.

Parameters:

value – The python object containing the value to process.

process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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 form.fields.HoneyPotField(*args: Any, **kwargs: Any)[source]

Bases: wtforms.fields.StringField

A field to identify bots.

A honey pot field is hidden using CSS and therefore not visible for users but bots (probably). We therefore expect this field to be empty at any time and throw an error if provided as well as adding a log message to optionally ban the IP.

To add honey pot fields to your (public) forms, give it a reasonable name, but not one that might be autofilled by browsers, e.g.:

delay = HoneyPotField()

widget[source]
type = 'LazyWolvesField'[source]
post_validate(form: onegov.form.Form, validation_stopped: bool) None[source]

Override if you need to run any field-level validation tasks after normal validation. This shouldn’t be needed in most cases.

Parameters:
  • form – The form the field belongs to.

  • validation_stoppedTrue if any validator raised StopValidation.

class form.fields.ColorField(label=None, validators=None, filters=(), description='', id=None, default=None, widget=None, render_kw=None, name=None, _form=None, _prefix='', _translations=None, _meta=None)[source]

Bases: wtforms.fields.StringField

A string field that renders a html5 color picker and coerces to a normalized six digit hex string.

It will result in a process_error for invalid colors.

widget[source]
coerce(value: object) str | None[source]
process_data(value: object) None[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.

Parameters:

value – The python object containing the value to process.

process_formdata(valuelist: list[onegov.form.types.RawFormValue]) None[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 form.fields.TypeAheadField(*args: Any, url: Callable[[DefaultMeta], str | None] | str | None = None, **kwargs: Any)[source]

Bases: wtforms.fields.StringField

A string field with typeahead.

Requires an url with the placeholder %QUERY for the search term.

url: Callable[[DefaultMeta], str | None] | str | None[source]
widget[source]