Colander Converters

inverter provide several converters to colander based schema:

  • dc2colander - converts dataclass to standard colander schema.

  • dc2colanderjson - converts dataclass to a colander schema that serialize to JSON

    • date is serialized as number days from epoch

    • datetime is serialized as number of miliseconds from epoch

  • dc2colanderavro - converts dataclass to a colander schema that serialize to avro compatible data

    • date is serialized as number days from epoch

    • datetime is serialized as number of miliseconds from epoch

    • dictionary (JSON field) is serialized as JSON string

  • dc2colanderESjson - converts dataclass to a colander schema that serialize to ES compatible JSON

    • date is serialized as YYYY-MM-DD string

    • datetime is serialized as iso8601 string

inverter.dc2colander.convert(schema: type, *, request: Any = None, mode='default', include_fields: List[str] = None, exclude_fields: List[str] = None, hidden_fields: List[str] = None, readonly_fields: List[str] = None, include_schema_validators: bool = True, colander_schema_type: Type[colander.Schema] = <class 'colander.Schema'>, oid_prefix: str = 'deformField', default_tzinfo=<UTC>, field_metadata=None, dataclass_field_to_colander_schemanode=<function dataclass_field_to_colander_schemanode>) → Type[colander.Schema]

Converts dataclass to colander.Schema

Parameters
  • schemadataclass class to be used as schema

  • request – a request object. This is mainly be passed down to downstream factories, accepts anything.

  • mode – this flag is used to affect the decision on how validators validate data. accepts one of the following: - 'default' - 'edit' - flag used when generating edit form - 'edit-process' - flag used when generating edit processing form

  • include_fields (typing.List[str]) – List of field names to include

  • exclude_fields (typing.List[str]) – List of field names to exclude

  • hidden_fields (typing.List[str]) – List of field names to hide

  • readonly_fields (typing.List[str]) – List of field names to made readonly

  • include_schema_validators (bool) – Set whether to include __validators__ from dataclass during convertion

  • colander_schema_type – base class to use as created output, defaults to colander.MappingSchema.

  • oid_prefix – string to use as deform OID prefix

  • default_tzinfo – default timezone for datetime handling, defaults to pytz.UTC

  • field_metadata – a dictionary for overriding field metadata. Structure: {'<fieldname>': {'metadatakey': 'metadataval'}}

  • dataclass_field_to_colander_schemanodecolander.SchemaNode factory function.

Returns

colander.Schema class

Field metadata handling

This function will read several metadata from fields and use it to derive the parameters.

  • required: bool - flag field as required

  • title: str - field title

  • description: str - field description

  • validators: typing.List[typing.Callable] - a list of validator callables

  • preparers: typing.List[typing.Callable] - a list of preparer callables

  • deform.widget: deform.widget.Widget - deform.widget.Widget object to use as widget.

  • deform.widget_factory: typing.Callable - a callable with that accept request and returns a deform.widget.Widget object.

  • colander.field_factory: typing.Callable - a callable that accept request and returns a colander.SchemaType object.

inverter.dc2colanderjson.convert(schema, *, include_fields: List[str] = None, exclude_fields: List[str] = None, hidden_fields: List[str] = None, readonly_fields: List[str] = None, include_schema_validators: bool = True, colander_schema_type: Type[colander.Schema] = <class 'colander.Schema'>, oid_prefix: str = 'deformField', request=None, mode='default', default_tzinfo=<UTC>, field_metadata=None) → Type[colander.Schema]

Converts dataclass to colander.Schema that serializes to JSON.

  • date is serialized as number days from epoch

  • datetime is serialized as number of miliseconds from epoch

Accepted parameters are the same as inverter.dc2colander.convert.

inverter.dc2colanderavro.convert(schema, *, include_fields: List[str] = None, exclude_fields: List[str] = None, hidden_fields: List[str] = None, readonly_fields: List[str] = None, include_schema_validators: bool = True, colander_schema_type: Type[colander.Schema] = <class 'colander.Schema'>, oid_prefix: str = 'deformField', request=None, mode='default', default_tzinfo=None, field_metadata=None) → Type[colander.Schema]

Converts dataclass to colander.Schema that serializes to Avro compatible dictionary.

  • date is serialized as number days from epoch

  • datetime is serialized as number of miliseconds from epoch

  • dictionary (JSON field) is serialized as JSON string

Accepted parameters are the same as inverter.dc2colander.convert.

inverter.dc2colanderESjson.convert(schema, *, include_fields: List[str] = None, exclude_fields: List[str] = None, hidden_fields: List[str] = None, readonly_fields: List[str] = None, include_schema_validators: bool = True, colander_schema_type: Type[colander.Schema] = <class 'colander.Schema'>, oid_prefix: str = 'deformField', request=None, default_tzinfo=<UTC>, mode='default', field_metadata=None) → Type[colander.Schema]

Converts dataclass to colander.Schema that serializes to ElasticSearch compatible dictionary.

  • date is serialized as YYYY-MM-DD string

  • datetime is serialized as iso8601 string

Accepted parameters are the same as inverter.dc2colander.convert.