org.forms.directory

Classes

DirectoryBaseForm

Form for directories.

DirectoryForm

Form for directories.

DirectoryImportForm

Extends wtforms.Form with useful methods and integrations needed in

DirectoryUrlForm

For changing the URL of a directory independent of the title.

DirectoryRecipientForm

Form for adding recipients of entry updates to the directory.

Module Contents

class org.forms.directory.DirectoryBaseForm(formdata: MultiDict[str, Any] | None = None, obj: object | None = None, prefix: str = '', data: dict[str, Any] | None = None, meta: dict[str, Any] | None = None, *, extra_filters: Mapping[str, Sequence[Any]] | None = None, **kwargs: Any)[source]

Bases: onegov.form.Form

Form for directories.

request: onegov.org.request.OrgRequest[source]
title[source]
lead[source]
title_further_information[source]
text[source]
position[source]
structure[source]
enable_map[source]
title_format[source]
lead_format[source]
empty_notice[source]
numbering[source]
numbers[source]
content_fields[source]
content_hide_labels[source]
contact_fields[source]
keyword_fields[source]
thumbnail[source]
show_as_thumbnails[source]
overview_two_columns[source]
address_block_title_type[source]
address_block_title[source]
marker_icon[source]
marker_color_type[source]
marker_color_value[source]
order[source]
order_format[source]
order_direction[source]
enable_submissions[source]
submissions_guideline[source]
price[source]
price_per_submission[source]
currency[source]
enable_change_requests[source]
change_requests_guideline[source]
enable_publication[source]
enable_update_notifications[source]
required_publication[source]
submitter_meta_fields[source]
layout[source]
property known_field_ids: set[str] | None[source]
property known_fields: list[onegov.form.parser.core.ParsedField] | None[source]
property missing_fields: dict[str, list[str]] | None[source]
extract_field_ids(field: wtforms.Field) Iterator[str][source]
validate_title_format(field: wtforms.Field) None[source]
validate_lead_format(field: wtforms.Field) None[source]
validate_thumbnail(field: wtforms.Field) None[source]
validate_numbers(field: wtforms.Field) None[source]
ensure_public_fields_for_submissions() bool | None[source]

Force directories to show all fields (no hidden fields) if the user may send in new entries or update exsting ones.

Otherwise we would have to filter out private fields which presents all kinds of edge-cases that we should probably not solve - directories are not meant to be private repositories.

first_hidden_field(configuration: onegov.directory.DirectoryConfiguration) ParsedField | None[source]

Returns the first hidden field, or None.

is_public(fid: str, configuration: onegov.directory.DirectoryConfiguration) bool[source]

Returns true if the given field id is public.

A field is public, if none of these are true:

  • It is part of the title/lead

  • It is part of the display

  • It is part of the keywords

  • It is used as the thumbnail

Though we might also glean other fields if they are simply searchable or if they are part of the link pattern, we do not count those as public, because we are interested in obviously public fields clearly visible to the user.

property default_marker_color: str[source]
property marker_color: str | None[source]
property configuration: onegov.directory.DirectoryConfiguration[source]
populate_obj(obj: onegov.org.models.ExtendedDirectory) None[source]

A reimplementation of wtforms populate_obj function with the addage of optional include/exclude filters.

If neither exclude nor include is passed, the function works like it does in wtforms. Otherwise fields are considered which are included but not excluded.

process_obj(obj: onegov.org.models.ExtendedDirectory) None[source]

Called by process() if an object was passed.

Do not use this function directly. To process an object, you should call form.process(obj=obj) instead.

class org.forms.directory.DirectoryForm(formdata: MultiDict[str, Any] | None = None, obj: object | None = None, prefix: str = '', data: dict[str, Any] | None = None, meta: dict[str, Any] | None = None, *, extra_filters: Mapping[str, Sequence[Any]] | None = None, **kwargs: Any)[source]

Bases: DirectoryBaseForm, onegov.org.forms.generic.PaymentForm

Form for directories.

class org.forms.directory.DirectoryImportForm(formdata: MultiDict[str, Any] | None = None, obj: object | None = None, prefix: str = '', data: dict[str, Any] | None = None, meta: dict[str, Any] | None = None, *, extra_filters: Mapping[str, Sequence[Any]] | None = None, **kwargs: Any)[source]

Bases: onegov.form.Form

Extends wtforms.Form with useful methods and integrations needed in OneGov applications.

Fieldsets

This form supports fieldsets (which WTForms doesn’t recognize). To put fields into a fieldset, add a fieldset attribute to the field during class definition:

class MyForm(Form):
    first_name = StringField('First Name', fieldset='Name')
    last_name = StringField('Last Name', fieldset='Name')
    comment = StringField('Comment')

A form created like this will have two fieldsets, one visible fieldset with the legend set to ‘Name’ and one invisible fieldset containing ‘comment’.

Fieldsets with the same name are not automatically grouped together. Instead, fields are taken in the order they are defined and put into the same fieldset, if the previous fieldset has the same name.

That is to say, in this example, we get three fieldsets:

class MyForm(Form):
    a = StringField('A', fieldset='1')
    b = StringField('B', fieldset='2')
    c = StringField('C', fieldset='1')

The first fieldset has the label ‘1’ and it contains ‘a’. The second fieldset has the label ‘2’ and it contains ‘b’. The third fieldset has the label ‘3’ and it contains ‘c’.

This ensures that all fields are in either a visible or an invisible fieldset (see Fieldset.is_visible()).

Dependencies

This form also supports dependencies. So field b may depend on field a, if field a has a certain value, field b is shown on the form (with some javascript) and its validators are actually executed. If field a does not have the required value, field b is hidden with javascript and its validators are not executed.

The validators which are skipped are only the validators passed with the field, the validators on the field itself are still invoked (we can’t skip them). However, only if the optional field is not empty. That is we prevent invalid values no matter what, but we allow for empty values if the dependent field does not have the required value.

This sounds a lot more complicated than it is:

class MyForm(Form):

    option = RadioField('Option', choices=[
        ('yes', 'Yes'),
        ('no', 'No'),
    ])
    only_if_no = StringField(
        label='Only Shown When No',
        validators=[InputRequired()],
        depends_on=('option', 'no')
    )

Pricing

Pricing is a way to attach prices to certain form fields. A total price is calcualted depending on the selections the user makes:

class MyForm(Form):

    ticket_insurance = RadioField('Option', choices=[
        ('yes', 'Yes'),
        ('no', 'No')
    ], pricing={
        'yes': (10.0, 'CHF')
    })

    stamps = IntegerRangeField(
    'No. Stamps',
    range=range(0, 30),
    pricing={range(0, 30): (0.85, 'CHF')}
)

    delivery = RadioField('Delivery', choices=[
        ('pick_up', 'Pick up'),
        ('post', 'Post')
    ], pricing={
        'post': (5.0, 'CHF', True)
    })

    discount_code = StringField('Discount Code', pricing={
        'CAMPAIGN2017': (-5.0, 'CHF')
    })

Note that the pricing has no implicit meaning. This is simply a way to attach prices and to get the total through the prices() and total() calls. What you do with these prices is up to you.

Pricing can optionally take a third boolean value indicating that this option will make credit card payments mandatory.

import_config[source]
mode[source]
zip_file[source]
static clear_entries(session: sqlalchemy.orm.Session, target: onegov.org.models.ExtendedDirectory) None[source]
run_import(target: onegov.org.models.ExtendedDirectory) int[source]
class org.forms.directory.DirectoryUrlForm(formdata: MultiDict[str, Any] | None = None, obj: object | None = None, prefix: str = '', data: dict[str, Any] | None = None, meta: dict[str, Any] | None = None, *, extra_filters: Mapping[str, Sequence[Any]] | None = None, **kwargs: Any)[source]

Bases: onegov.org.forms.generic.ChangeAdjacencyListUrlForm

For changing the URL of a directory independent of the title.

validate_name(field: wtforms.fields.StringField) None[source]
class org.forms.directory.DirectoryRecipientForm(formdata: MultiDict[str, Any] | None = None, obj: object | None = None, prefix: str = '', data: dict[str, Any] | None = None, meta: dict[str, Any] | None = None, *, extra_filters: Mapping[str, Sequence[Any]] | None = None, **kwargs: Any)[source]

Bases: onegov.form.Form

Form for adding recipients of entry updates to the directory.

address[source]