form.collection

Attributes

SubmissionHandler

Classes

FormCollection

Manages a collection of forms and form-submissions.

FormDefinitionCollection

Manages a collection of forms.

FormSubmissionCollection

Manages a collection of submissions.

FormRegistrationWindowCollection

Abstract base class for generic types.

SurveyDefinitionCollection

Manages a collection of surveys.

SurveySubmissionCollection

Manages a collection of survey submissions.

SurveySubmissionWindowCollection

Abstract base class for generic types.

SurveyCollection

Manages a collection of surveys and survey-submissions.

Module Contents

form.collection.SubmissionHandler: TypeAlias = Callable[[Query[FormSubmission]], Any][source]
class form.collection.FormCollection(session: sqlalchemy.orm.Session)[source]

Manages a collection of forms and form-submissions.

session[source]
property definitions: FormDefinitionCollection[source]
property submissions: FormSubmissionCollection[source]
property registration_windows: FormRegistrationWindowCollection[source]
scoped_submissions(name: str, ensure_existance: Literal[False]) FormSubmissionCollection[source]
scoped_submissions(name: str, ensure_existance: bool = True) FormSubmissionCollection | None
get_definitions_with_submission_count() Iterator[FormDefinition][source]

Returns all form definitions and the number of submissions belonging to those definitions, in a single query.

The number of submissions is stored on the form definition under the submissions_count attribute.

Only submissions which are ‘complete’ are considered.

class form.collection.FormDefinitionCollection(session: sqlalchemy.orm.Session)[source]

Manages a collection of forms.

session[source]
query() Query[FormDefinition][source]
add(title: str, definition: str, type: str = 'generic', meta: dict[str, Any] | None = None, content: dict[str, Any] | None = None, name: str | None = None, payment_method: onegov.pay.types.PaymentMethod = 'manual', pick_up: str | None = None) onegov.form.models.FormDefinition[source]

Add the given form to the database.

delete(name: str, with_submissions: bool = False, with_registration_windows: bool = False, handle_submissions: SubmissionHandler | None = None, handle_registration_windows: RegistrationWindowHandler | None = None) None[source]

Delete the given form. Only possible if there are no submissions associated with it, or if with_submissions is True.

Note that pending submissions are removed automatically, only complete submissions have a bearing on with_submissions.

Pass two callbacks to handle additional logic before deleting the objects.

by_name(name: str) onegov.form.models.FormDefinition | None[source]

Returns the given form by name or None.

class form.collection.FormSubmissionCollection(session: sqlalchemy.orm.Session, name: str | None = None)[source]

Manages a collection of submissions.

session[source]
name[source]
query() Query[FormSubmission][source]
add(name: str | None, form: onegov.form.Form, state: onegov.form.types.SubmissionState, id: uuid.UUID | None = None, payment_method: PaymentMethod | None = None, minimum_price_total: float | None = None, meta: dict[str, Any] | None = None, email: str | None = None, spots: int | None = None) onegov.form.models.FormSubmission[source]

Takes a filled-out form instance and stores the submission in the database. The form instance is expected to have a _source parameter, which contains the source used to build the form (as only forms with this source may be stored).

This method expects the name of the form definition stored in the database. Use add_external() to add a submissions whose definition is not stored in the form_definitions table.

add_external(form: onegov.form.Form, state: onegov.form.types.SubmissionState, id: uuid.UUID | None = None, payment_method: PaymentMethod | None = None, minimum_price_total: float | None = None, meta: dict[str, Any] | None = None, email: str | None = None) onegov.form.models.FormSubmission[source]

Takes a filled-out form instance and stores the submission in the database. The form instance is expected to have a _source parameter, which contains the source used to build the form (as only forms with this source may be stored).

In contrast to add(), this method is meant for submissions whose definition is not stored in the form_definitions table.

complete_submission(submission: onegov.form.models.FormSubmission) None[source]

Changes the state to ‘complete’, if the data is valid.

update(submission: onegov.form.models.FormSubmission, form: onegov.form.Form, exclude: Collection[str] | None = None) None[source]

Takes a submission and a form and updates the submission data as well as the files stored in a separate table.

remove_old_pending_submissions(older_than: datetime.datetime, include_external: bool = False) None[source]

Removes all pending submissions older than the given date. The date is expected to be in UTC!

by_state(state: onegov.form.types.SubmissionState) Query[FormSubmission][source]
by_name(name: str) list[onegov.form.models.FormSubmission][source]

Return all submissions for the given form-name.

by_id(id: uuid.UUID, state: SubmissionState | None = None, current_only: bool = False) onegov.form.models.FormSubmission | None[source]

Return the submission by id.

State:

Only if the submission matches the given state.

Current_only:

Only if the submission is not older than one hour.

delete(submission: onegov.form.models.FormSubmission) None[source]

Deletes the given submission and all the files belonging to it.

class form.collection.FormRegistrationWindowCollection(session: sqlalchemy.orm.Session, name: str | None = None)[source]

Bases: onegov.core.collection.GenericCollection[onegov.form.models.FormRegistrationWindow]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
name[source]
property model_class: type[onegov.form.models.FormRegistrationWindow][source]
query() Query[FormRegistrationWindow][source]
class form.collection.SurveyDefinitionCollection(session: sqlalchemy.orm.Session)[source]

Manages a collection of surveys.

session[source]
query() Query[SurveyDefinition][source]
add(title: str, definition: str, type: str = 'generic', meta: dict[str, Any] | None = None, content: dict[str, Any] | None = None, name: str | None = None) onegov.form.models.definition.SurveyDefinition[source]

Add the given survey to the database.

delete(name: str, with_submission_windows: bool = False, handle_submissions: SurveySubmissionHandler | None = None, handle_submission_windows: SubmissionWindowHandler | None = None) None[source]

Delete the given form. Only possible if there are no submissions associated with it, or if with_submissions is True.

Note that pending submissions are removed automatically, only complete submissions have a bearing on with_submissions.

Pass two callbacks to handle additional logic before deleting the objects.

by_name(name: str) onegov.form.models.definition.SurveyDefinition | None[source]

Returns the given form by name or None.

class form.collection.SurveySubmissionCollection(session: sqlalchemy.orm.Session, name: str | None = None)[source]

Manages a collection of survey submissions.

session[source]
name[source]
query() Query[SurveySubmission][source]
add(name: str | None, form: onegov.form.Form, submission_window: onegov.form.models.survey_window.SurveySubmissionWindow | None = None, id: uuid.UUID | None = None, meta: dict[str, Any] | None = None) onegov.form.models.submission.SurveySubmission[source]

Takes a filled-out survey instance and stores the submission in the database. The survey instance is expected to have a _source parameter, which contains the source used to build the szrvey (as only surveys with this source may be stored).

This method expects the name of the survey definition stored in the database. Use add_external() to add a submissions whose definition is not stored in the form_definitions table.

update(submission: onegov.form.models.submission.SurveySubmission, form: onegov.form.Form, exclude: Collection[str] | None = None) None[source]

Takes a submission and a survey and updates the submission data as well as the files stored in a separate table.

by_name(name: str) list[onegov.form.models.submission.SurveySubmission][source]

Return all submissions for the given form-name.

by_id(id: uuid.UUID, current_only: bool = False) onegov.form.models.submission.SurveySubmission | None[source]

Return the submission by id.

State:

Only if the submission matches the given state.

Current_only:

Only if the submission is not older than one hour.

delete(submission: onegov.form.models.submission.SurveySubmission) None[source]

Deletes the given submission and all the files belonging to it.

class form.collection.SurveySubmissionWindowCollection(session: sqlalchemy.orm.Session, name: str | None = None)[source]

Bases: onegov.core.collection.GenericCollection[onegov.form.models.survey_window.SurveySubmissionWindow]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
name[source]
property model_class: type[onegov.form.models.survey_window.SurveySubmissionWindow][source]
query() Query[SurveySubmissionWindow][source]
class form.collection.SurveyCollection(session: sqlalchemy.orm.Session)[source]

Manages a collection of surveys and survey-submissions.

session[source]
property definitions: SurveyDefinitionCollection[source]
property submissions: SurveySubmissionCollection[source]
property submission_windows: SurveySubmissionWindowCollection[source]
scoped_submissions(name: str, ensure_existance: Literal[False]) SurveySubmissionCollection[source]
scoped_submissions(name: str, ensure_existance: bool = True) SurveySubmissionCollection | None
get_definitions_with_submission_count() Iterator[FormDefinition][source]

Returns all form definitions and the number of submissions belonging to those definitions, in a single query.

The number of submissions is stored on the form definition under the submissions_count attribute.

Only submissions which are ‘complete’ are considered.