form.forms.named_file

Module Contents

Classes

NamedFileForm

Base class for handling database models using named files with forms.

class form.forms.named_file.NamedFileForm(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

Base class for handling database models using named files with forms.

Example:

class MyModel(AssociatedFiles):

pdf = NamedFile()

class MyForm(NamedFileForm):

pdf = UploadField(‘PDF’)

@MyApp.form(model=MyCollection, form=MyForm, …) def add(self, request, form):

if form.submitted(request):

self.add(**form.get_useful_data()) …

@MyApp.form(model=MyModel, form=MyForm, …) def edit(self, request, form):

if form.submitted(request):

form.populate_obj(self) …

form.process(obj=self) …

file_fields() dict[str, onegov.form.fields.UploadField][source]
get_useful_data(exclude: Collection[str] | None = None) dict[str, Any][source]

Returns the form data in a dictionary, by default excluding data that should not be stored in the db backend.

populate_obj(obj: object, exclude: Collection[str] | None = None, include: Collection[str] | None = None) 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: object) 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.