Colander Converters¶
inverter provide several converters to colander based schema:
dc2colander- convertsdataclassto standardcolanderschema.dc2colanderjson- convertsdataclassto acolanderschema that serialize to JSONdate is serialized as number days from epoch
datetime is serialized as number of miliseconds from epoch
dc2colanderavro- convertsdataclassto acolanderschema that serialize toavrocompatible datadate 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- convertsdataclassto acolanderschema that serialize to ES compatible JSONdate 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
dataclasstocolander.Schema- Parameters
schema –
dataclassclass to be used as schemarequest – 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 forminclude_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__fromdataclassduring convertioncolander_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
datetimehandling, defaults topytz.UTCfield_metadata – a dictionary for overriding field metadata. Structure:
{'<fieldname>': {'metadatakey': 'metadataval'}}dataclass_field_to_colander_schemanode –
colander.SchemaNodefactory function.
- Returns
colander.Schemaclass
Field metadata handling
This function will read several metadata from fields and use it to derive the parameters.
required: bool- flag field as requiredtitle: str- field titledescription: str- field descriptionvalidators: typing.List[typing.Callable]- a list of validator callablespreparers: typing.List[typing.Callable]- a list of preparer callablesdeform.widget: deform.widget.Widget-deform.widget.Widgetobject to use as widget.deform.widget_factory: typing.Callable- a callable with that acceptrequestand returns adeform.widget.Widgetobject.colander.field_factory: typing.Callable- a callable that acceptrequestand returns acolander.SchemaTypeobject.
-
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
dataclasstocolander.Schemathat 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
dataclasstocolander.Schemathat 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
dataclasstocolander.Schemathat 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.