Serializers

Serializers transform models to and from JSON representations for the ReST API.

This is where you’ll find inbound data validation.

class fleetingform.serializers.FleetingActionSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

fields = ['label']
model

alias of fleetingform.models.FleetingAction

class fleetingform.serializers.FleetingAuthSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: drf_writable_nested.serializers.WritableNestedModelSerializer

class Meta[source]

Bases: object

fields = ['type', 'title', 'content', 'form_controls', 'users']
model

alias of fleetingform.models.FleetingAuth

REQUIRED_FORM_CONTROLS = {'password', 'username'}
REQUIRED_FORM_CONTROL_DEFAULTS = {'password': {'label': 'Password', 'name': 'password', 'required': True, 'type': 'text', 'validations': [{'type': 'max-length', 'params': {'max': 32}, 'message': 'too long.'}]}, 'username': {'label': 'Username', 'name': 'username', 'required': True, 'type': 'text'}}
create(validated_data)[source]

Overridden create to add any required form controls.

to_representation(instance)[source]

Exclude empty or null keys from serialized responses.

validate(data)[source]

Validate correct user arguments have been passed given the type

class fleetingform.serializers.FleetingChoiceSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

fields = ['value', 'text']
model

alias of fleetingform.models.FleetingChoice

class fleetingform.serializers.FleetingFormControlSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: drf_writable_nested.serializers.WritableNestedModelSerializer

class Meta[source]

Bases: object

fields = ['type', 'name', 'help_text', 'label', 'validations', 'choices', 'required', 'initial', 'disabled', 'params', 'hidden']
model

alias of fleetingform.models.FleetingFormControl

to_representation(instance)[source]

Exclude empty or null keys from serialized responses.

validate(data)[source]

Validate that the control has a valid combination of options.

class fleetingform.serializers.FleetingFormSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: drf_writable_nested.serializers.WritableNestedModelSerializer

class Meta[source]

Bases: object

fields = ['id', 'code', 'template', 'app', 'auth', 'url', 'short_url', 'status', 'created_on', 'opened_on', 'completed_on', 'expires_on', 'result']
model

alias of fleetingform.models.FleetingForm

create(validated_data)[source]

We have a bit of extra checking around this in order to provide descriptive messages when something goes wrong, but this method is essentially just:

return ExampleModel.objects.create(**validated_data)

If there are many to many fields present on the instance then they cannot be set until the model is instantiated, in which case the implementation is like so:

example_relationship = validated_data.pop(‘example_relationship’) instance = ExampleModel.objects.create(**validated_data) instance.example_relationship = example_relationship return instance

The default implementation also does not handle nested relationships. If you want to support writable nested relationships you’ll need to write an explicit .create() method.

validate_app(val)[source]

Validate that the app parameters are within bounds.

validate_auth(data)[source]

Populate default auth type for new creates without type.

validate_namespace(val)[source]

Populate the namespace from the request for new creates.

class fleetingform.serializers.FleetingNamespaceSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

fields = ['id', 'user', 'subdomain', 'url_shortener', 'retention', 'usage', 'support_email', 'token', 'soft_limit', 'hard_limit', 'logo', 'style']
model

alias of fleetingform.models.FleetingNamespace

get_usage(namespace)[source]
to_representation(instance)[source]

Exclude token unless user is authenticated.

class fleetingform.serializers.FleetingTemplateSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: drf_writable_nested.serializers.WritableNestedModelSerializer

class Meta[source]

Bases: object

fields = ['type', 'title', 'content', 'content_type', 'form_controls', 'params', 'actions']
model

alias of fleetingform.models.FleetingTemplate

validate(data)[source]

Validate that the template has a valid combination of options.

validate_actions(actions)[source]

Validate the template actions.

validate_content(content)[source]

Bleach any inbound HTML in the form content.

validate_title(title)[source]

Bleach any inbound HTML in the form title.

class fleetingform.serializers.FleetingUserSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

fields = ['username', 'password', 'email', 'phone', 'opened_on']
model

alias of fleetingform.models.FleetingUser

to_representation(instance)[source]

Exclude empty or null keys and hide password hashes.

validate_password(data)[source]

Validate an inbound password.

Passwords may only come in two formats: - a string prefixed with plain: - PHC string format (https://github.com/P-H-C/phc-string-format/blob/

master/phc-sf-spec.md)

Plain text passwords are immediately hashed before being stored. PHC strings are checked for formatting and valid hashing type.

validate_phone(data)[source]

If enabled, use the twilio lookup API to validate a phone number.

class fleetingform.serializers.FleetingValidationSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

fields = ['type', 'params', 'message']
model

alias of fleetingform.models.FleetingValidation

class fleetingform.serializers.FleetingWebhookSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)[source]

Bases: rest_framework.serializers.ModelSerializer

class Meta[source]

Bases: object

fields = ['id', 'namespace', 'url', 'token', 'name', 'event']
model

alias of fleetingform.models.FleetingWebhook