websauna.system.form.fields module

class websauna.system.form.fields.EnumValue(enum_class)[source]

Bases: colander.String

Allow choice of python enum.Enum in colander schemas.

Example:

class AssetClass(enum.Enum):
'''What's preferred display format for this asset.'''

    fiat = "fiat"
    cryptocurrency = "cryptocurrency"
    token = "token"
    tokenized_shares = "tokenized_shares"
    ether = "ether"

class Schema(CSRFSchema):

    asset_class = colander.SchemaNode(
        EnumValue(AssetClass),
        widget=deform.widget.SelectWidget(values=enum_values(AssetClass)))
deserialize(node, cstruct)[source]

Parse incoming form values to Python objects if needed.

serialize(node, _enum)[source]

Convert Enum object to str for widget processing.

Return type

str

class websauna.system.form.fields.JSONValue(encoding=None, allow_empty=False)[source]

Bases: colander.String

Serialize / deserialize JSON fields.

Example:

class AssetSchema(CSRFSchema):

    name = colander.SchemaNode(colander.String())

    other_data = colander.SchemaNode(
        JSONValue(),
        widget=JSONWidget(),
        description="JSON bag of attributes of the object")
deserialize(node, cstruct)[source]

Parse incoming form values to Python objects if needed.

serialize(node, data)[source]

Convert Python objects to JSON string.

Return type

str

class websauna.system.form.fields.UUID(encoding=None, allow_empty=False)[source]

Bases: colander.String

UUID field for Colander.

See also :py:class`websauna.system.form.widgets.FriendlyUUIDWidget`.

serialize(node, appstruct)[source]
websauna.system.form.fields.defer_widget_values(widget, values_callback, **kwargs)[source]

Allow select or checkbox widget values construction deferred during the execution time.

Parameters
  • widget (type) – Any Deform widget class, see deform.widget.Widget

  • value_callback – This callable(node, kw) is called deferredly by Colander

  • kwargs – Passed to the widget constructed

Return type

Widget