onadata.libs.serializers package

Subpackages

Submodules

onadata.libs.serializers.attachment_serializer module

Attachments serializer.

class onadata.libs.serializers.attachment_serializer.AttachmentSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

Attachments serializer

class Meta

Bases: object

fields = ('url', 'filename', 'mimetype', 'field_xpath', 'id', 'xform', 'instance', 'download_url', 'small_download_url', 'medium_download_url')
model

alias of Attachment

get_download_url(obj)

Return attachment download url.

get_field_xpath(obj)

Return question xpath

get_medium_download_url(obj)

Return attachment download url for resized medium image.

get_small_download_url(obj)

Return attachment download url for resized small image.

onadata.libs.serializers.attachment_serializer.dict_key_for_value(_dict, value)

This function is used to get key by value in a dictionary

onadata.libs.serializers.attachment_serializer.get_path(data, question_name, path_list)

A recursive function that returns the xpath of a media file :param json data: JSON representation of xform :param string question_name: Name of media file being searched for :param list path_list: Contains the names that make up the xpath :return: an xpath which is a string or None if name cannot be found :rtype: string or None

onadata.libs.serializers.chart_serializer module

Chart serializer.

class onadata.libs.serializers.chart_serializer.ChartSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

Chart serializer

class Meta

Bases: object

fields = ('id', 'id_string', 'url')
model

alias of XForm

class onadata.libs.serializers.chart_serializer.FieldsChartSerializer(*args, **kwargs)

Bases: ModelSerializer

Generate chart data for the field.

class Meta

Bases: object

model

alias of XForm

to_representation(instance)

Generate chart data for a given field in the request query params.

onadata.libs.serializers.clone_xform_serializer module

Clone an XForm serializer.

class onadata.libs.serializers.clone_xform_serializer.CloneXFormSerializer(*args, **kwargs)

Bases: Serializer

Clone an xform serializer class

create(validated_data)

Uses the CloneXForm class to clone/copy an XForm.

Returns the CloneXForm instance.

update(instance, validated_data)
validate_username(value)

Check that the username exists

onadata.libs.serializers.data_serializer module

Submission data serializers module.

class onadata.libs.serializers.data_serializer.BaseRapidProSubmissionSerializer(*args, **kwargs)

Bases: SubmissionSuccessMixin, Serializer

Base Rapidpro SubmissionSerializer - Implements the basic functionalities of a Rapidpro webhook serializer

create(validated_data)
update(instance, validated_data)
validate(attrs)

Validate that the XForm ID is passed in view kwargs

class onadata.libs.serializers.data_serializer.DataInstanceSerializer(*args, **kwargs)

Bases: ModelSerializer

DataInstanceSerializer class - for json field data representation on the Instance (submission) model.

class Meta

Bases: object

fields = ('json',)
model

alias of Instance

to_representation(instance)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.data_serializer.DataInstanceXMLSerializer(*args, **kwargs)

Bases: ModelSerializer

DataInstanceXMLSerializer class - for XML field data representation on the Instance model.

class Meta

Bases: object

fields = ('xml',)
model

alias of Instance

to_representation(instance)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.data_serializer.DataSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

DataSerializer class - used for the list view to show id, id_string, title and description.

class Meta

Bases: object

fields = ('id', 'id_string', 'title', 'description', 'url')
model

alias of XForm

class onadata.libs.serializers.data_serializer.FLOIPListSerializer(*args, **kwargs)

Bases: ListSerializer

Custom ListSerializer for a FLOIP submission.

create(*args)
update(instance, validated_data)
class onadata.libs.serializers.data_serializer.FLOIPSubmissionSerializer(*args, **kwargs)

Bases: SubmissionSuccessMixin, Serializer

FLOIP SubmmissionSerializer - Handles a row of FLOIP specification format.

class Meta

Bases: object

Call the list serializer class to create an instance.

list_serializer_class

alias of FLOIPListSerializer

create(validated_data)
run_validators(value)

Add read_only fields with defaults to value before running validators.

to_internal_value(data)

Overrides validating rows in list data.

update(instance, validated_data)
validate(attrs)

Custom list data validator.

class onadata.libs.serializers.data_serializer.InstanceHistorySerializer(*args, **kwargs)

Bases: ModelSerializer

InstanceHistorySerializer class - for the json field data representation.

class Meta

Bases: object

fields = ('json',)
model

alias of InstanceHistory

to_representation(instance)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.data_serializer.JSONSubmissionSerializer(*args, **kwargs)

Bases: SubmissionSuccessMixin, Serializer

JSON SubmissionSerializer - handles JSON submission data.

create(*args)
update(instance, validated_data)
validate(attrs)

Custom submission validator in request data.

class onadata.libs.serializers.data_serializer.JsonDataSerializer(*args, **kwargs)

Bases: Serializer

JSON DataSerializer class - for json field data representation.

create(validated_data)
to_representation(instance)

Object instance -> Dict of primitive datatypes.

update(instance, validated_data)
class onadata.libs.serializers.data_serializer.OSMSerializer(*args, **kwargs)

Bases: Serializer

OSM Serializer - represents OSM data.

create(validated_data)
property data

Returns the serialized data on the serializer.

to_representation(instance)

Return a list of osm file objects from attachments.

update(instance, validated_data)
class onadata.libs.serializers.data_serializer.OSMSiteMapSerializer(*args, **kwargs)

Bases: Serializer

OSM SiteMap Serializer.

create(validated_data)
to_representation(instance)

Return a list of osm file objects from attachments.

update(instance, validated_data)
class onadata.libs.serializers.data_serializer.RapidProJSONSubmissionSerializer(*args, **kwargs)

Bases: BaseRapidProSubmissionSerializer

Rapidpro SubmissionSerializer - handles RapidPro JSON webhook posts

create(*args)
update(instance, validated_data)
class onadata.libs.serializers.data_serializer.RapidProSubmissionSerializer(*args, **kwargs)

Bases: BaseRapidProSubmissionSerializer

Rapidpro SubmissionSerializer - handles Rapidpro webhook post.

create(*args)
update(instance, validated_data)
class onadata.libs.serializers.data_serializer.SubmissionSerializer(*args, **kwargs)

Bases: SubmissionSuccessMixin, Serializer

XML SubmissionSerializer - handles creating a submission from XML.

create(*args)
update(instance, validated_data)
validate(attrs)
class onadata.libs.serializers.data_serializer.SubmissionSuccessMixin

Bases: object

SubmissionSuccessMixin - prepares submission success data/message.

to_representation(instance)

Returns a dict with a successful submission message.

class onadata.libs.serializers.data_serializer.TableauDataSerializer(*args, **kwargs)

Bases: ModelSerializer

TableauDataSerializer class - cleans out instance fields.

class Meta

Bases: object

fields = ('json',)
model

alias of Instance

to_representation(instance)

Object instance -> Dict of primitive datatypes.

onadata.libs.serializers.data_serializer.create_submission(request, username, data_dict, xform_id, gen_uuid: bool = False)

Returns validated data object instances

onadata.libs.serializers.data_serializer.get_request_and_username(context)

Returns request object and username

onadata.libs.serializers.dataview_serializer module

The DataViewSerializer - manage DataView objects.

class onadata.libs.serializers.dataview_serializer.DataViewMinimalSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

The DataViewMinimalSerializer - manage DataView objects.

class Meta

Bases: object

fields = ('dataviewid', 'name', 'url', 'xform', 'project', 'columns', 'query', 'matches_parent', 'date_created', 'instances_with_geopoints', 'date_modified')
model

alias of DataView

class onadata.libs.serializers.dataview_serializer.DataViewSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

The DataViewSerializer - manage DataView objects.

class Meta

Bases: object

fields = ('dataviewid', 'name', 'xform', 'project', 'columns', 'query', 'matches_parent', 'count', 'instances_with_geopoints', 'last_submission_time', 'has_hxl_support', 'url', 'date_created', 'deleted_at', 'deleted_by')
model

alias of DataView

validators
create(validated_data)

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.

get_count(obj)

Returns the submission count for the data view,

get_has_hxl_support(obj)

Returns true if a DataView has columns with HXL tags.

get_instances_with_geopoints(obj)

Returns True if a DataView has submissions with geopoints.

get_last_submission_time(obj)

Returns the last submission timestamp.

update(instance, validated_data)
validate(attrs)
validate_columns(value)

Checks the value is a list.

validate_query(value)

Checks if the query filters in value are known.

onadata.libs.serializers.dataview_serializer.match_columns(data, instance=None)

Checks if the fields in two forms are a match.

onadata.libs.serializers.dataview_serializer.validate_date(value)

Returns True if the value is a date string.

onadata.libs.serializers.dataview_serializer.validate_datetime(value)

Returns True if the value is a datetime string.

onadata.libs.serializers.export_serializer module

The ExportSerializer class - create, list exports.

class onadata.libs.serializers.export_serializer.ExportSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

The ExportSerializer class - create, list exports.

class Meta

Bases: object

fields = ('id', 'job_status', 'type', 'task_id', 'xform', 'date_created', 'filename', 'options', 'export_url', 'error_message')
model

alias of Export

get_export_url(obj)

Returns the export download URL.

get_job_status(obj)

Returns export async status text.

get_type(obj)

Returns export type - CSV,XLS,…

onadata.libs.serializers.geojson_serializer module

The GeoJsonSerializer class - uses the GeoJSON structure for submission data.

class onadata.libs.serializers.geojson_serializer.GeoJsonListSerializer(*args, **kwargs)

Bases: GeoJsonSerializer

Creates a FeatureCollections

to_representation(instance)

Serialize objects -> primitives.

class onadata.libs.serializers.geojson_serializer.GeoJsonSerializer(*args, **kwargs)

Bases: GeoFeatureModelSerializer

The GeoJsonSerializer class - uses the GeoJSON structure for submission data.

class Meta

Bases: object

fields = ('id', 'xform')
geo_field = 'geom'
id_field = False
lookup_field = 'pk'
model

alias of Instance

to_representation(instance)

Serialize objects -> primitives.

class onadata.libs.serializers.geojson_serializer.GeometryField(*args, **kwargs)

Bases: GeometryField

The GeometryField class - representation for single GeometryField.

to_representation(value)

Transform the outgoing native value into primitive data.

onadata.libs.serializers.geojson_serializer.create_feature(instance, geo_field, fields)

Create a geojson feature from a single instance

onadata.libs.serializers.geojson_serializer.geometry_from_string(points, simple_style)

Takes a string, returns a geometry object. simple_style param allows building geojson that adheres to the simplestyle-spec

onadata.libs.serializers.geojson_serializer.is_polygon(point_list)

Takes a list of tuples and determines if it is a polygon

onadata.libs.serializers.metadata_serializer module

MetaData Serializer

class onadata.libs.serializers.metadata_serializer.MetaDataSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

MetaData HyperlinkedModelSerializer

class Meta

Bases: object

fields = ('id', 'xform', 'project', 'instance', 'data_value', 'data_type', 'data_file', 'extra_data', 'data_file_type', 'media_url', 'file_hash', 'url', 'date_created')
model

alias of MetaData

create(validated_data)

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.

get_content_object(validated_data)

Returns the validated ‘xform’ or ‘project’ or ‘instance’ ids being linked to the metadata.

get_media_url(obj)

Returns media URL for given metadata

update(instance, validated_data)
validate(attrs)

Validate url if we are adding a media uri instead of a media file

onadata.libs.serializers.metadata_serializer.get_linked_object(parts)

Returns an XForm or DataView object

Raises 404 Exception if object is not found. Raises serializers.ValidationError if the format of the linked object is not valid.

onadata.libs.serializers.note_serializer module

Note Serializers Module

class onadata.libs.serializers.note_serializer.NoteSerializer(*args, **kwargs)

Bases: ModelSerializer

NoteSerializer class

class Meta

Bases: object

Meta Options for NoteSerializer

fields = ('id', 'note', 'instance', 'instance_field', 'created_by', 'date_created', 'date_modified', 'owner')
model

alias of Note

create(validated_data)

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.

get_owner(obj)

Custom method return the username of Note creator

validate(attrs)

onadata.libs.serializers.organization_member_serializer module

The OrganizationMemberSerializer - manages a users access in an organization

class onadata.libs.serializers.organization_member_serializer.OrganizationMemberSerializer(*args, **kwargs)

Bases: Serializer

The OrganizationMemberSerializer - manages a users access in an organization

create(validated_data)
property data
update(instance, validated_data)
validate(attrs)
validate_role(value)

check that the role exists

validate_username(value)

Check that the username exists

onadata.libs.serializers.organization_serializer module

Organization Serializer

class onadata.libs.serializers.organization_serializer.OrganizationSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

Organization profile serializer

class Meta

Bases: object

exclude = ('created_by', 'is_organization', 'organization')
model

alias of OrganizationProfile

owner_only_fields = ('metadata',)
create(validated_data)

Create an organization profile.

get_users(obj)

Return organization members.

update(instance, validated_data)

Update organization profile properties.

validate_org(value)

Validate organization name.

onadata.libs.serializers.password_reset_serializer module

Password reset serializer.

class onadata.libs.serializers.password_reset_serializer.CustomPasswordResetTokenGenerator

Bases: PasswordResetTokenGenerator

Custom Password Token Generator Class.

class onadata.libs.serializers.password_reset_serializer.PasswordReset(email, reset_url, email_subject=None)

Bases: object

Class resets the password and sends the reset email.

Class imitates a model functionality for use with PasswordResetSerializer

save(subject_template_name='registration/password_reset_subject.txt', email_template_name='api_password_reset_email.html', token_generator=<onadata.libs.serializers.password_reset_serializer.CustomPasswordResetTokenGenerator object>, from_email=None)

Generates a one-use only link for resetting password and sends to the user.

class onadata.libs.serializers.password_reset_serializer.PasswordResetChange(uid, new_password, token)

Bases: object

Class resets and changes the password.

Class imitates a model functionality for use with PasswordResetSerializer

save()

Set a new user password and invalidate/regenerate tokens.

class onadata.libs.serializers.password_reset_serializer.PasswordResetChangeSerializer(*args, **kwargs)

Bases: Serializer

Reset and change password serializer.

create(validated_data, instance=None)

Set a new user password and invalidate/regenerate tokens.

validate(attrs)

Validates the generated user token.

validate_uid(value)

Validate the user uid.

class onadata.libs.serializers.password_reset_serializer.PasswordResetSerializer(*args, **kwargs)

Bases: Serializer

Password reset serializer.

create(validated_data)

Reset a user password.

validate_email(value)

Validates the email.

validate_email_subject(value)

Validate the email subject is not empty.

onadata.libs.serializers.password_reset_serializer.get_password_reset_email(user, reset_url, subject_template_name='registration/password_reset_subject.txt', email_template_name='api_password_reset_email.html', token_generator=<onadata.libs.serializers.password_reset_serializer.CustomPasswordResetTokenGenerator object>, email_subject=None)

Creates the subject and email body for password reset email.

onadata.libs.serializers.password_reset_serializer.get_user_from_uid(uid)

Return user from base64 encoded uid.

onadata.libs.serializers.project_serializer module

Project Serializer module.

class onadata.libs.serializers.project_serializer.BaseProjectSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

BaseProjectSerializer class.

class Meta

Bases: object

fields = ['url', 'projectid', 'owner', 'created_by', 'metadata', 'starred', 'users', 'forms', 'public', 'tags', 'num_datasets', 'last_submission_date', 'teams', 'name', 'date_created', 'date_modified', 'deleted_at']
model

alias of Project

get_forms(obj)

Return list of xforms in the project.

get_last_submission_date(obj)

Return the most recent submission date to any of the projects datasets.

get_num_datasets(obj)

Return the number of datasets attached to the project.

get_starred(obj)

Return True if request user has starred this project.

get_teams(obj)

Return the teams with access to the project.

get_users(obj)

Return a list of users and organizations that have access to the project.

class onadata.libs.serializers.project_serializer.BaseProjectXFormSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

BaseProjectXFormSerializer class.

class Meta

Bases: object

fields = ('name', 'formid', 'id_string', 'is_merged_dataset')
model

alias of XForm

class onadata.libs.serializers.project_serializer.ProjectSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

ProjectSerializer class - creates and updates a project.

class Meta

Bases: object

exclude = ('shared', 'user_stars', 'deleted_by', 'organization')
model

alias of Project

create(*args)

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.

get_data_views(obj)

Return a list of filtered datasets.

get_forms(obj)

Return list of xforms in the project.

get_last_submission_date(obj)

Return the most recent submission date to any of the projects datasets.

get_num_datasets(obj)

Return the number of datasets attached to the project.

get_starred(obj)

Return True if request user has starred this project.

get_teams(obj)

Return the teams with access to the project.

get_users(obj)

Return a list of users and organizations that have access to the project.

update(instance, validated_data)

Update project properties.

validate(attrs)

Validate the project name does not exist and the user has the permissions to create a project in the organization.

validate_metadata(value)

Validate metadaata is a valid JSON value.

validate_public(value)

Validate the public field

class onadata.libs.serializers.project_serializer.ProjectXFormSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

ProjectXFormSerializer class - to return project xform info.

class Meta

Bases: object

fields = ('name', 'formid', 'id_string', 'num_of_submissions', 'downloadable', 'encrypted', 'published_by_formbuilder', 'last_submission_time', 'date_created', 'url', 'last_updated_at', 'is_merged_dataset')
model

alias of XForm

get_published_by_formbuilder(obj)

Returns true if the form was published by formbuilder.

onadata.libs.serializers.project_serializer.can_add_project_to_profile(user, organization)

Check if user has permission to add a project to a profile.

onadata.libs.serializers.project_serializer.get_last_submission_date(project)

Return the most recent submission date to any of the projects datasets.

Parameters:

project – The project to find the last submission date for.

onadata.libs.serializers.project_serializer.get_num_datasets(project)

Return the number of datasets attached to the project.

Parameters:

project – The project to find datasets for.

onadata.libs.serializers.project_serializer.get_project_xforms(project)

Returns an XForm queryset from project. The prefetched xforms_prefetch or xform_set.filter() queryset.

onadata.libs.serializers.project_serializer.get_team_permissions(team, project)

Return team permissions.

onadata.libs.serializers.project_serializer.get_teams(project)

Return the teams with access to the project.

onadata.libs.serializers.project_serializer.get_users(project, context, all_perms=True)

Return a list of users and organizations that have access to the project.

onadata.libs.serializers.project_serializer.is_starred(project, request)

Return True if the request.user has starred this project.

onadata.libs.serializers.project_serializer.set_owners_permission(user, project)

Give the user owner permission

onadata.libs.serializers.restservices_serializer module

The RestServiceSerializer class - create, list a rest service.

class onadata.libs.serializers.restservices_serializer.RestServiceSerializer(*args, **kwargs)

Bases: ModelSerializer

The RestServiceSerializer class - create, list a rest service.

class Meta

Bases: object

fields = ('id', 'xform', 'name', 'service_url', 'date_created', 'date_modified', 'active', 'inactive_reason')
model

alias of RestService

onadata.libs.serializers.share_project_serializer module

The ShareProjectSerializer class - support sharing a project.

class onadata.libs.serializers.share_project_serializer.RemoveUserFromProjectSerializer(*args, **kwargs)

Bases: ShareProjectSerializer

RemoveUserFromProjectSerializer class - removes a user’s access to a project.

create(validated_data)
update(instance, validated_data)
validate(attrs)

Check and confirm that the project will be left with at least one owner. Raises a validation error if only one owner found

class onadata.libs.serializers.share_project_serializer.ShareProjectSerializer(*args, **kwargs)

Bases: Serializer

The ShareProjectSerializer class - support sharing a project.

create(validated_data)
update(instance, validated_data)
validate(attrs)
validate_role(value)

check that the role exists

validate_username(value)

Check that the username exists

onadata.libs.serializers.share_project_serializer.attrs_to_instance(attrs, instance)

Apply attributes into a class object from a dict.

onadata.libs.serializers.share_team_project_serializer module

Share projects to team functions.

class onadata.libs.serializers.share_team_project_serializer.RemoveTeamFromProjectSerializer(*args, **kwargs)

Bases: ShareTeamProjectSerializer

Remove a team from a project.

create(validated_data)

Remove a team from a project

update(instance, validated_data)

Remove a team from a project

class onadata.libs.serializers.share_team_project_serializer.ShareTeamProjectSerializer(*args, **kwargs)

Bases: Serializer

Shares a project with a team.

create(validated_data)

Shares a project to a team.

update(instance, validated_data)

Update project sharing properties.

validate_role(value)

check that the role exists

onadata.libs.serializers.share_xform_serializer module

Share XForm serializer.

class onadata.libs.serializers.share_xform_serializer.ShareXFormSerializer(*args, **kwargs)

Bases: Serializer

Share xform to a user.

create(validated_data)

Assign role permission for a form to a user.

update(instance, validated_data)

Make changes to form share to a user.

validate_role(value)

check that the role exists

validate_username(value)

Check that the username exists

onadata.libs.serializers.stats_serializer module

Stats API endpoint serializer.

class onadata.libs.serializers.stats_serializer.StatsInstanceSerializer(*args, **kwargs)

Bases: Serializer

The stats instance serializer - calls the relevant statistical functions and returns the results against form data submissions.

to_representation(instance)

Returns the result of the selected stats function.

class onadata.libs.serializers.stats_serializer.StatsSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

Stats serializer for use with the list API endpoint, summary of the stats endpoints.

class Meta

Bases: object

fields = ('id', 'id_string', 'url')
model

alias of XForm

class onadata.libs.serializers.stats_serializer.SubmissionStatsInstanceSerializer(*args, **kwargs)

Bases: Serializer

Submissions stats instance serializer - provides submission summary stats.

property data

Return the data as a list with ReturnList instead of a python object.

to_representation(instance)

Returns submissions stats grouped by a specified field.

class onadata.libs.serializers.stats_serializer.SubmissionStatsSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

Submission stats serializer for use with the list API endpoint, summary of the submission stats endpoints.

class Meta

Bases: object

fields = ('id', 'id_string', 'url')
model

alias of XForm

onadata.libs.serializers.tag_list_serializer module

Tags list serializer module.

class onadata.libs.serializers.tag_list_serializer.TagListSerializer(*args, **kwargs)

Bases: Field

Tags serializer - represents tags as a list of strings.

to_internal_value(data)

Validates the data is a list.

to_representation(value)

Returns all tags linked to the object value as a list.

onadata.libs.serializers.team_serializer module

The TeamSerializer class - access and update Team model objects.

class onadata.libs.serializers.team_serializer.TeamSerializer(*args, **kwargs)

Bases: Serializer

The TeamSerializer class - access and update Team model objects.

create(validated_data)
get_projects(obj)

Organization Projects with default role

get_users(obj)

Returns a users in a team.

update(instance, validated_data)

onadata.libs.serializers.textit_serializer module

The TextItSerializer - supports creating TextIt integration service.

class onadata.libs.serializers.textit_serializer.TextItSerializer(*args, **kwargs)

Bases: Serializer

The TextItSerializer - supports creating TextIt integration service.

create(validated_data)
to_representation(instance)

Object instance -> Dict of primitive datatypes.

update(instance, validated_data)

onadata.libs.serializers.user_profile_serializer module

UserProfile Serializers.

class onadata.libs.serializers.user_profile_serializer.UserProfileSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

UserProfile serializer.

class Meta

Bases: object

fields = ('id', 'is_org', 'url', 'username', 'password', 'first_name', 'last_name', 'email', 'city', 'country', 'organization', 'website', 'twitter', 'gravatar', 'require_auth', 'user', 'metadata', 'joined_on', 'name')
model

alias of UserProfile

owner_only_fields = ('metadata',)
create(*args)

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.

get_is_org(obj)

Returns True if it is an organization profile.

to_representation(instance)

Serialize objects -> primitives.

update(instance, validated_data)

Update user properties.

validate(attrs)
validate_email(value)

Checks if user with the same email has already been registered.

validate_twitter(value)

Checks if the twitter handle is valid.

validate_username(value)

Validate username.

class onadata.libs.serializers.user_profile_serializer.UserProfileWithTokenSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

User Profile Serializer that includes the users API Tokens.

class Meta

Bases: object

fields = ('url', 'username', 'name', 'email', 'city', 'country', 'organization', 'website', 'twitter', 'gravatar', 'require_auth', 'user', 'api_token', 'temp_token')
model

alias of UserProfile

get_api_token(obj)

Returns user’s API Token.

get_temp_token(obj)

This should return a valid temp token for this user profile.

onadata.libs.serializers.user_serializer module

The UserSerializer class - Users serializer

class onadata.libs.serializers.user_serializer.UserSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

The UserSerializer class - Users serializer

class Meta

Bases: object

fields = ('id', 'username', 'first_name', 'last_name')
model

alias of User

onadata.libs.serializers.widget_serializer module

Widget serializer

class onadata.libs.serializers.widget_serializer.GenericRelatedField(*args, **kwargs)

Bases: HyperlinkedRelatedField

GenericRelatedField - handle related field relations for XForm and DataView

default_error_messages = {'incorrect_match': '`{input}` is not a valid relation.'}
to_internal_value(data)

Verifies that data is a valid URL.

to_representation(value)

Set’s the self.view_name based on the type of value.

class onadata.libs.serializers.widget_serializer.WidgetSerializer(*args, **kwargs)

Bases: HyperlinkedModelSerializer

class Meta

Bases: object

Meta model - specifies the fields in the Model Widget for the serializer

fields = ('id', 'url', 'key', 'title', 'description', 'widget_type', 'order', 'view_type', 'column', 'group_by', 'content_object', 'data', 'aggregation', 'metadata')
model

alias of Widget

get_data(obj)

Return the Widget.query_data(obj)

validate(attrs)

Validates that column exists in the XForm.

validate_content_object(value)

Validate if a user is the owner f the organization.

onadata.libs.serializers.xform_serializer module

XForm model serialization.

class onadata.libs.serializers.xform_serializer.MultiLookupIdentityField(*args, **kwargs)

Bases: HyperlinkedIdentityField

Custom HyperlinkedIdentityField that supports multiple lookup fields.

Credits: https://stackoverflow.com/a/31161585

get_url(obj, view_name, request, format)

Returns URL to the given object.

lookup_fields = (('pk', 'pk'),)
class onadata.libs.serializers.xform_serializer.XFormBaseSerializer(*args, **kwargs)

Bases: XFormMixin, HyperlinkedModelSerializer

XForm base serializer.

class Meta

Bases: object

exclude = ('json', 'xml', 'xls', 'user', 'has_start_time', 'shared', 'shared_data', 'deleted_at', 'deleted_by')
model

alias of XForm

read_only_fields = ('json', 'xml', 'date_created', 'date_modified', 'encrypted', 'bamboo_dataset', 'last_submission_time', 'is_merged_dataset', 'xls_available')
class onadata.libs.serializers.xform_serializer.XFormCreateSerializer(*args, **kwargs)

Bases: XFormSerializer

XForm serializer that is only relevant during the XForm publishing process.

get_has_id_string_changed(obj)

Returns the value of obj.has_id_string_changed

class onadata.libs.serializers.xform_serializer.XFormListSerializer(*args, **kwargs)

Bases: Serializer

XForm serializer for OpenRosa form list API.

get_manifest_url(obj)

Return manifest URL.

get_url(obj)

Returns XForm download URL.

class onadata.libs.serializers.xform_serializer.XFormManifestSerializer(*args, **kwargs)

Bases: Serializer

XForm Manifest serializer class.

get_filename(obj)

Returns media filename.

get_hash(obj)

Returns MD5 hash based on last_submission_time for a media linked form.

get_url(obj)

Return media download URL.

class onadata.libs.serializers.xform_serializer.XFormMixin

Bases: object

XForm mixins

get_data_views(obj)

Returns a list of filtered datasets linked to the form.

get_enketo_preview_url(obj)

Returns preview Enketo URL for given obj.

get_enketo_single_submit_url(obj)

Returns single submit Enketo URL for given obj.

get_enketo_url(obj)

Returns Enketo URL for given obj.

get_last_submission_time(obj)

Return datetime of last submission

If a form is a merged dataset then it is picked from the list of forms attached to that merged dataset.

get_num_of_submissions(obj)

Returns number of submissions.

get_users(obj)

Returns a list of users based on XForm permissions.

get_xls_available(obj)

Returns True if obj.xls.url is not None, indicates XLS is present.

class onadata.libs.serializers.xform_serializer.XFormSerializer(*args, **kwargs)

Bases: XFormMixin, HyperlinkedModelSerializer

XForm model serializer

class Meta

Bases: object

exclude = ('json', 'xml', 'xls', 'user', 'has_start_time', 'shared', 'shared_data', 'deleted_at', 'deleted_by')
model

alias of XForm

read_only_fields = ('json', 'xml', 'date_created', 'date_modified', 'encrypted', 'bamboo_dataset', 'last_submission_time', 'is_merged_dataset', 'xls_available')
get_form_versions(obj)

Returns all form versions.

get_metadata(obj)

Returns XForn obj metadata.

validate_public(value)

Validate the public field

validate_public_data(value)

Validate the public_data field

validate_public_key(value)

Checks that the given RSA public key is a valid key by trying to use the key data to create an RSA key object using the cryptography package

class onadata.libs.serializers.xform_serializer.XFormVersionListSerializer(*args, **kwargs)

Bases: ModelSerializer

XFormVersion list API serializer

class Meta

Bases: object

exclude = ('json', 'xls', 'id')
model

alias of XFormVersion

onadata.libs.serializers.xform_serializer.clean_public_key(value)

Strips public key comments and spaces from a public key value.

onadata.libs.serializers.xform_serializer.user_to_username(item)

Replaces the item[“user”] user object with the to user.username.

Module contents