wuttaweb.forms.widgets

Form widgets

This module defines some custom widgets for use with WuttaWeb.

However for convenience it also makes other Deform widgets available in the namespace:

class wuttaweb.forms.widgets.BatchIdWidget(**kw)[source]

Widget for use with the id field of a batch model.

This widget is “always” read-only and renders the Batch ID as zero-padded 8-char string

class wuttaweb.forms.widgets.FileDownloadWidget(request, *args, **kwargs)[source]

Widget for use with FileDownload fields.

This only supports readonly, and shows a hyperlink to download the file. Link text is the filename plus file size.

This is a subclass of deform.widget.Widget and uses these Deform templates:

  • readonly/filedownload

Parameters:
  • request – Current request object.

  • url – Optional URL for hyperlink. If not specified, file name/size is shown with no hyperlink.

class wuttaweb.forms.widgets.GridWidget(request, grid, *args, **kwargs)[source]

Widget for fields whose data is represented by a grid.

This is a subclass of deform.widget.Widget but does not use any Deform templates.

This widget only supports “readonly” mode, is not editable. It is merely a convenience around the grid itself, which does the heavy lifting.

Instead of creating this widget directly you probably should call set_grid() on your form.

Parameters:
  • request – Current request object.

  • gridGrid instance, used to display the field data.

serialize(field, cstruct, **kw)[source]

This widget simply calls render_table_element() on the grid to serialize.

class wuttaweb.forms.widgets.NotesWidget(**kw)[source]

Widget for use with “notes” fields.

In readonly mode, this shows the notes with a background to make them stand out a bit more.

Otherwise it effectively shows a <textarea> input element.

This is a subclass of deform.widget.TextAreaWidget and uses these Deform templates:

  • textarea

  • readonly/notes

class wuttaweb.forms.widgets.ObjectRefWidget(request, url=None, *args, **kwargs)[source]

Widget for use with model “object reference” fields, e.g. foreign key UUID => TargetModel instance.

While you may create instances of this widget directly, it normally happens automatically when schema nodes of the ObjectRef (sub)type are part of the form schema; via widget_maker().

In readonly mode, this renders a <span> tag around the model_instance (converted to string).

Otherwise it renders a select (dropdown) element allowing user to choose from available records.

This is a subclass of deform.widget.SelectWidget and uses these Deform templates:

  • select

  • readonly/objectref

model_instance

Reference to the model record instance, i.e. the “far side” of the foreign key relationship.

Note

You do not need to provide the model_instance when constructing the widget. Rather, it is set automatically when the ObjectRef type instance (associated with the node) is serialized.

class wuttaweb.forms.widgets.PermissionsWidget(request, session=None, *args, **kwargs)[source]

Widget for use with Role permissions field.

This is a subclass of WuttaCheckboxChoiceWidget. It uses these Deform templates:

  • permissions

  • readonly/permissions

class wuttaweb.forms.widgets.RoleRefsWidget(request, session=None, *args, **kwargs)[source]

Widget for use with User roles field. This is the default widget for the RoleRefs type.

This is a subclass of WuttaCheckboxChoiceWidget.

class wuttaweb.forms.widgets.UserRefsWidget(request, session=None, *args, **kwargs)[source]

Widget for use with Role users field. This is the default widget for the UserRefs type.

This is a subclass of WuttaCheckboxChoiceWidget; however it only supports readonly mode and does not use a template. Rather, it generates and renders a Grid showing the users list.

class wuttaweb.forms.widgets.WuttaCheckboxChoiceWidget(request, session=None, *args, **kwargs)[source]

Custom widget for set fields.

This is a subclass of deform.widget.CheckboxChoiceWidget, but adds Wutta-related params to the constructor.

Parameters:

It uses these Deform templates:

  • checkbox_choice

  • readonly/checkbox_choice

class wuttaweb.forms.widgets.WuttaDateTimeWidget(request, *args, **kwargs)[source]

Custom widget for datetime.datetime fields.

The main purpose of this widget is to leverage render_datetime() for the readonly display.

It is automatically used for SQLAlchemy mapped classes where the field maps to a sqlalchemy.types.DateTime column. For other (non-mapped) datetime fields, you may have to use it explicitly via set_widget().

This is a subclass of deform.widget.DateTimeInputWidget and uses these Deform templates:

  • datetimeinput