wuttaweb.forms.schema

Form schema types

class wuttaweb.forms.schema.FileDownload(request, *args, **kwargs)[source]

Custom schema type for a file download field.

This field is only meant for readonly use, it does not handle file uploads.

It expects the incoming appstruct to be the path to a file on disk (or null).

Uses the FileDownloadWidget by default.

Parameters:
  • request – Current request object.

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

class wuttaweb.forms.schema.ObjectNode(*args, **kw)[source]

Custom schema node class which adds methods for compatibility with ColanderAlchemy. This is a direct subclass of colander.SchemaNode.

ColanderAlchemy will call certain methods on any node found in the schema. However these methods are not “standard” and only exist for ColanderAlchemy nodes.

So we must add nodes using this class, to ensure the node has all methods needed by ColanderAlchemy.

dictify(obj)[source]

This method is called by ColanderAlchemy when translating the in-app Python object to a value suitable for use in the form data dict.

The logic here will look for a dictify() method on the node’s “type” instance (self.typ; see also colander.SchemaNode) and invoke it if found.

For an example type which is supported in this way, see ObjectRef.

If the node’s type does not have a dictify() method, this will just convert the object to a string and return that.

objectify(value)[source]

This method is called by ColanderAlchemy when translating form data to the final Python representation.

The logic here will look for an objectify() method on the node’s “type” instance (self.typ; see also colander.SchemaNode) and invoke it if found.

For an example type which is supported in this way, see ObjectRef.

If the node’s type does not have an objectify() method, this will raise NotImplementeError.

class wuttaweb.forms.schema.ObjectRef(request, empty_option=None, session=None, *args, **kwargs)[source]

Custom schema type for a model class reference field.

This expects the incoming appstruct to be either a model record instance, or None.

Serializes to the instance UUID as string, or colander.null; form data should be of the same nature.

This schema type is not useful directly, but various other types will subclass it. Each should define (at least) the model_class attribute or property.

Parameters:
  • request – Current request object.

  • empty_option

    If a select widget is used, this determines whether an empty option is included for the dropdown. Set this to one of the following to add an empty option:

    • True to add the default empty option

    • label text for the empty option

    • tuple of (value, label) for the empty option

    Note that in the latter, value must be a string.

get_object_url(obj)[source]

Returns the “view” URL for the given object, if applicable.

This is used when rendering the field readonly. If this method returns a URL then the field text will be wrapped with a hyperlink, otherwise it will be shown as-is.

Default logic always returns None; subclass should override as needed.

get_query()[source]

Returns the main SQLAlchemy query responsible for locating the dropdown choices for the select widget.

This is called by widget_maker().

property model_class

Should be a reference to the model class to which this schema type applies (e.g. Person).

objectify(value)[source]

For the given UUID value, returns the object it represents (based on model_class).

If the value is empty, returns None.

If the value is not empty but object cannot be found, raises colander.Invalid.

sort_query(query)[source]

TODO

widget_maker(**kwargs)[source]

This method is responsible for producing the default widget for the schema node.

Deform calls this method automatically when constructing the default widget for a field.

Returns:

Instance of ObjectRefWidget.

class wuttaweb.forms.schema.Permissions(request, permissions, *args, **kwargs)[source]

Form schema type for the Role permissions association proxy field.

This is a subclass of WuttaSet. It uses a set of permission values for underlying data format.

Parameters:

permissions – Dict with all possible permissions. Should be in the same format as returned by get_available_permissions().

widget_maker(**kwargs)[source]

Constructs a default widget for the field.

Returns:

Instance of PermissionsWidget.

class wuttaweb.forms.schema.PersonRef(request, empty_option=None, session=None, *args, **kwargs)[source]

Custom schema type for a Person reference field.

This is a subclass of ObjectRef.

class wuttaweb.forms.schema.RoleRefs(request, session=None)[source]

Form schema type for the User roles association proxy field.

This is a subclass of WuttaSet. It uses a set of Role uuid values for underlying data format.

widget_maker(**kwargs)[source]

Constructs a default widget for the field.

Returns:

Instance of RoleRefsWidget.

class wuttaweb.forms.schema.UserRef(request, empty_option=None, session=None, *args, **kwargs)[source]

Custom schema type for a User reference field.

This is a subclass of ObjectRef.

class wuttaweb.forms.schema.UserRefs(request, session=None)[source]

Form schema type for the Role users association proxy field.

This is a subclass of WuttaSet. It uses a set of User uuid values for underlying data format.

widget_maker(**kwargs)[source]

Constructs a default widget for the field.

Returns:

Instance of UserRefsWidget.

class wuttaweb.forms.schema.WuttaEnum(request, *args, **kwargs)[source]

Custom schema type for enum fields.

This is a subclass of colander.Enum, but adds a default widget (SelectWidget) with enum choices.

Parameters:

request – Current request object.

class wuttaweb.forms.schema.WuttaSet(request, session=None)[source]

Custom schema type for set fields.

This is a subclass of colander.Set, but adds Wutta-related params to the constructor.

Parameters: