websauna.system.form.fieldmapper module

Map SQLAlchemy columns and other class attributes to Colander schema.

Also encapsulate colanderalchemy so that we don’t need to directly expose it in the case we want to get rid of it later.

class websauna.system.form.fieldmapper.ColumnToFieldMapper[source]

Bases: abc.ABC

A helper class to map a SQLAlchemy model to Colander/Deform form.

abstract map(mode, request, context, model, includes)[source]

Map a model to a Colander form schema.

  • mode (EditMode) – IS this add, edit or show form. For example, some relationship fields do not make sense on add form.

  • context (Resource) – Resource with get_object() to get the actual SQLAlchemy object

  • model (type) – SQLAlchemy model class

  • includes (List) – List of [column name | SchemaNode] we need to map

Return type



colander.SchemaNode which presents the automatically generated form

class websauna.system.form.fieldmapper.DefaultSQLAlchemyFieldMapper[source]

Bases: websauna.system.form.fieldmapper.ColumnToFieldMapper

The default SQLAlchemy to form field and widget mapping implementation.

We support

  • The default colanderalchemy mappings

  • UUID

  • JSONProperty declarations

  • IP addresses (INET)

  • ForeignKey references where it holds a reference to one another SQLAlchemy object

See colanderalchemy.schema.SQLAlchemySchemaNode for more information.

map(mode, request, context, model, includes, nested=None)[source]
  • mode (EditMode) – What kind of form is this - show, add, edit

  • request (Request) – HTTP request

  • context (Optional[Resource]) – Current traversing context or None

  • model (type) – The SQLAlchemy model class for which we generate schema

  • includes (List) – List of column, relationship and property names or colander.SchemaNode(name=name) instances to be included on the form.

  • nested – Legacy. Going away.

Return type


map_column(mode, request, node, model, name, column, column_type)[source]

Map non-relationship SQLAlchemy column to Colander SchemaNode.

Return type

Tuple[SchemaType, dict]


Tuple(constructed colander.SchemaType, dict of addtional colander.SchemaNode construction arguments)

map_relationship(mode, request, node, model, name, rel, mapper)[source]
map_standard_relationship(mode, request, node, model, name, rel)[source]

Build a widget for choosing a relationship with target.

The relationship must be foreign_key and the remote must offer uuid attribute which we use as a vocabulary key..

Return type