cdh.rest.client.fields module

class cdh.rest.client.fields.BasicTypeField(*args, **kwargs)[source]

Bases: _BaseField

Abstract class used by simple types like bool, str and int.

__init__(*args, **kwargs)[source]

A field contains data within a REST resources.

Parameters
  • verbose_name – A code friendly name for this field, defaults to the variable name

  • default – A default value to be used when no value is given

  • choices – Optional, used to restrict the values in this field

  • name – A human friendly name for this field, defaults to the variable name

  • null – If this field can be null

  • blank – If this field can be left blank

  • error_messages – Any custom error messages

  • validators – Any custom validators

basic_type = None
to_api(value: object) None[source]

Cleans and validates values before casting them to the right API type

class cdh.rest.client.fields.BoolField(*args, **kwargs)[source]

Bases: BasicTypeField

Field containing a boolean

basic_type

alias of bool

class cdh.rest.client.fields.CollectionField(collection, **kwargs)[source]

Bases: _BaseField

Field referencing a collection

__init__(collection, **kwargs)[source]
Parameters
  • collection – The collection to use

  • kwargs – See ::class:BaseField for other options

to_api(value: Union[ResourceCollection, _TypeCollection])[source]

Transforms the collection into a list, and chains the call to it’s children.

to_python(value: list)[source]

Creates a collection object from the supplied list

class cdh.rest.client.fields.DateField(verbose_name: str = None, default: object = None, choices: object = None, name: str = None, null: bool = False, blank: bool = False, error_messages: dict = None, validators: tuple = ())[source]

Bases: DateTimeField

Field that parses a ISO-formatted date-string

type

alias of date

class cdh.rest.client.fields.DateTimeField(verbose_name: str = None, default: object = None, choices: object = None, name: str = None, null: bool = False, blank: bool = False, error_messages: dict = None, validators: tuple = ())[source]

Bases: _BaseField

Field that parses a ISO-formatted datetime-string

to_api(value: datetime) str[source]

This method should return a python datatype that can be deserialized properly primarily by the json module.

to_python(value: str) datetime[source]

Returns the python version of the supplied value. By default, it’s the same as the value supplied, but this can be overridden by fields to provide a conversion to a different datatype

type

alias of datetime

class cdh.rest.client.fields.FloatField(*args, **kwargs)[source]

Bases: BasicTypeField

Field containing a float

basic_type

alias of float

class cdh.rest.client.fields.IntegerField(*args, **kwargs)[source]

Bases: BasicTypeField

Field containing an int

basic_type

alias of int

class cdh.rest.client.fields.ResourceField(resource, **kwargs)[source]

Bases: _BaseField

Field referencing a resources

__init__(resource, **kwargs)[source]
Parameters
  • resource – The resources to use

  • kwargs – See ::class:BaseField for other options

to_api(value: Resource)[source]

Transforms the resources into a dict, and chains the call to it’s children.

to_python(value: dict)[source]

Creates a resources object from the supplied dict

class cdh.rest.client.fields.TextField(*args, **kwargs)[source]

Bases: BasicTypeField

Field containing a string

basic_type

alias of str

class cdh.rest.client.fields.TimeField(verbose_name: str = None, default: object = None, choices: object = None, name: str = None, null: bool = False, blank: bool = False, error_messages: dict = None, validators: tuple = ())[source]

Bases: DateTimeField

Field that parses a ISO-formatted date-string

type

alias of time