websauna.system.form.schema module

Various Colander schema base classes and utililties for forms.

class websauna.system.form.schema.ValidateUnique(model, mode)[source]

Bases: object

Check unique constraint.

websauna.system.form.schema.dictify(schema, obj, excludes=())[source]

Return a dictified version of obj using schema information.

The schema will be used to choose what attributes will be included in the returned dict.

Thus, the return value of this function is suitable for consumption as a Deform appstruct and can be used to pre-populate forms in this specific use case.

Arguments/Keywords

Parameters
  • obj (object) – An object instance to be converted to a dict structure. This object should conform to the given schema. For example, obj should be an instance of this schema’s mapped class, an instance of a sub-class, or something that has the same attributes.

  • exludes – List of node names not to automatically dictify

Based on colanderalchemy implemetation.

Return type

dict

websauna.system.form.schema.enum_values(source, default=('', 'Please choose'), name_transform=<method 'title' of 'str' objects>)[source]

Turn Python Enum to key-value pairs lists to be used with selection widgets.

Return type

Iterable[Tuple]

websauna.system.form.schema.objectify(schema, appstruct, context, excludes=())[source]

Store incoming appstruct data on an object like SQLAlchemy model instance

websauna.system.form.schema.validate_json(node, value, **kwargs)[source]

Make sure the string content is valid JSON.