onadata.libs.serializers package

Submodules

onadata.libs.serializers.attachment_serializer module

class onadata.libs.serializers.attachment_serializer.AttachmentSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.attachment.Attachment

get_download_url(obj)
get_field_xpath(obj)
get_medium_download_url(obj)
get_small_download_url(obj)
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

class onadata.libs.serializers.chart_serializer.ChartSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.xform.XForm

class onadata.libs.serializers.chart_serializer.FieldsChartSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

class Meta

Bases: object

model

alias of onadata.apps.logger.models.xform.XForm

to_representation(obj)

Object instance -> Dict of primitive datatypes.

onadata.libs.serializers.clone_xform_serializer module

class onadata.libs.serializers.clone_xform_serializer.CloneXFormSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

create(validated_data)
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.DataInstanceSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

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

class Meta

Bases: object

fields = ('json',)
model

alias of onadata.apps.logger.models.instance.Instance

to_representation(instance)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.data_serializer.DataSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.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 onadata.apps.logger.models.xform.XForm

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

Bases: rest_framework.serializers.ListSerializer

Custom ListSerializer for a FLOIP submission.

create(validated_data)

Returns object instances based on the validated data.

class onadata.libs.serializers.data_serializer.FLOIPSubmissionSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.data_serializer.SubmissionSuccessMixin, rest_framework.serializers.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

run_validators(value)

Add read_only fields with defaults to value before running validators.

to_internal_value(data)

Overrides validating rows in list data.

validate(attrs)

Custom list data validator.

class onadata.libs.serializers.data_serializer.InstanceHistorySerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

InstanceHistorySerializer class - for the json field data representation.

class Meta

Bases: object

fields = ('json',)
model

alias of onadata.apps.logger.models.instance.InstanceHistory

to_representation(instance)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.data_serializer.JSONSubmissionSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.data_serializer.SubmissionSuccessMixin, rest_framework.serializers.Serializer

JSON SubmissionSerializer - handles JSON submission data.

create(validated_data)

Returns object instances based on the validated data

validate(attrs)

Custom submission validator in request data.

class onadata.libs.serializers.data_serializer.JsonDataSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

JSON DataSerializer class - for json field data representation.

to_representation(instance)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.data_serializer.OSMSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

OSM Serializer - represents OSM data.

data

Returns the serialized data on the serializer.

to_representation(instance)

Return a list of osm file objects from attachments.

class onadata.libs.serializers.data_serializer.OSMSiteMapSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

OSM SiteMap Serializer.

to_representation(instance)

Return a list of osm file objects from attachments.

class onadata.libs.serializers.data_serializer.RapidProSubmissionSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.data_serializer.SubmissionSuccessMixin, rest_framework.serializers.Serializer

Rapidpro SubmissionSerializer - handles Rapidpro webhook post.

create(validated_data)

Returns object instances based on the validated data.

validate(attrs)

Custom xform id validator in views kwargs.

class onadata.libs.serializers.data_serializer.SubmissionSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.data_serializer.SubmissionSuccessMixin, rest_framework.serializers.Serializer

XML SubmissionSerializer - handles creating a submission from XML.

create(validated_data)

Returns object instances based on the 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.

onadata.libs.serializers.data_serializer.create_submission(request, username, data_dict, xform_id)

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

class onadata.libs.serializers.dataview_serializer.DataViewMinimalSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.data_view.DataView

class onadata.libs.serializers.dataview_serializer.DataViewSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

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 onadata.apps.logger.models.data_view.DataView

validators = [<UniqueTogetherValidator(queryset=<QuerySet [<DataView: 13/10/2015>, <DataView: 15/10/2015>, <DataView: datav>, <DataView: datav>, <DataView: datav>, <DataView: datav>, <DataView: datav>, <DataView: Enumerator 10>, <DataView: Test mc>, <DataView: Filtered Detail dataview>, <DataView: personal_life>, <DataView: Male household heads>, <DataView: attednance>, <DataView: BRCiS Monitoring>, <DataView: KM_Filtered_View_Details>, <DataView: 13.2/10/2015>, <DataView: No responses>, <DataView: qa>, <DataView: Enumerator 11>, <DataView: Enumerator 14>, '...(remaining elements truncated)...']>, fields=('name', 'xform'))>]
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)
get_has_hxl_support(obj)
get_instances_with_geopoints(obj)
get_last_submission_time(obj)
update(instance, validated_data)
validate(attrs)
validate_columns(value)
validate_query(value)
onadata.libs.serializers.dataview_serializer.match_columns(data, instance=None)
onadata.libs.serializers.dataview_serializer.validate_date(value)
onadata.libs.serializers.dataview_serializer.validate_datetime(value)

onadata.libs.serializers.export_serializer module

class onadata.libs.serializers.export_serializer.ExportSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.viewer.models.export.Export

get_export_url(obj)
get_job_status(obj)
get_type(obj)

onadata.libs.serializers.geojson_serializer module

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

Bases: onadata.libs.serializers.geojson_serializer.GeoJsonSerializer

Creates a FeatureCollections

to_representation(obj)

Serialize objects -> primitives.

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

Bases: rest_framework_gis.serializers.GeoFeatureModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.instance.Instance

to_representation(obj)

Serialize objects -> primitives.

class onadata.libs.serializers.geojson_serializer.GeometryField(precision=None, remove_duplicates=False, **kwargs)

Bases: rest_framework_gis.fields.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)

Takes a string, returns a geometry object

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(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

MetaData HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.main.models.meta_data.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(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.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 onadata.apps.logger.models.note.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

class onadata.libs.serializers.organization_member_serializer.OrganizationMemberSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

create(validated_data)
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: rest_framework.serializers.HyperlinkedModelSerializer

Organization profile serializer

class Meta

Bases: object

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

alias of onadata.apps.api.models.organization_profile.OrganizationProfile

owner_only_fields = ('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_users(obj)

Return organization members.

update(instance, validated_data)
validate_org(value)

Validate organization name.

onadata.libs.serializers.password_reset_serializer module

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

Bases: object

save(subject_template_name='registration/password_reset_subject.txt', email_template_name='api_password_reset_email.html', token_generator=<django.contrib.auth.tokens.PasswordResetTokenGenerator 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

save()
class onadata.libs.serializers.password_reset_serializer.PasswordResetChangeSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

create(validated_data, instance=None)
validate(attrs)
validate_uid(value)
class onadata.libs.serializers.password_reset_serializer.PasswordResetSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

create(validated_data)
validate_email(value)
validate_email_subject(value)
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=<django.contrib.auth.tokens.PasswordResetTokenGenerator 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)

onadata.libs.serializers.project_serializer module

Project Serializer module.

class onadata.libs.serializers.project_serializer.BaseProjectSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.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 onadata.apps.logger.models.project.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(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

BaseProjectXFormSerializer class.

class Meta

Bases: object

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

alias of onadata.apps.logger.models.xform.XForm

class onadata.libs.serializers.project_serializer.ProjectSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

ProjectSerializer class - creates and updates a project.

class Meta

Bases: object

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

alias of onadata.apps.logger.models.project.Project

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_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)
validate(attrs)
validate_metadata(value)

Validate metadaata is a valid JSON value.

class onadata.libs.serializers.project_serializer.ProjectXFormSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.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 onadata.apps.logger.models.xform.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

class onadata.libs.serializers.restservices_serializer.RestServiceSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.restservice.models.RestService

onadata.libs.serializers.share_project_serializer module

class onadata.libs.serializers.share_project_serializer.RemoveUserFromProjectSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.share_project_serializer.ShareProjectSerializer

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(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

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)

onadata.libs.serializers.share_team_project_serializer module

class onadata.libs.serializers.share_team_project_serializer.RemoveTeamFromProjectSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.share_team_project_serializer.ShareTeamProjectSerializer

create(validated_data)
update(instance, validated_data)
class onadata.libs.serializers.share_team_project_serializer.ShareTeamProjectSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

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

check that the role exists

onadata.libs.serializers.share_xform_serializer module

class onadata.libs.serializers.share_xform_serializer.ShareXFormSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

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

check that the role exists

validate_username(value)

Check that the username exists

onadata.libs.serializers.stats_serializer module

class onadata.libs.serializers.stats_serializer.StatsInstanceSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

to_representation(obj)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.stats_serializer.StatsSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.xform.XForm

class onadata.libs.serializers.stats_serializer.SubmissionStatsInstanceSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

data
to_representation(obj)

Object instance -> Dict of primitive datatypes.

class onadata.libs.serializers.stats_serializer.SubmissionStatsSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.xform.XForm

onadata.libs.serializers.tag_list_serializer module

class onadata.libs.serializers.tag_list_serializer.TagListSerializer(read_only=False, write_only=False, required=None, default=<class 'rest_framework.fields.empty'>, initial=<class 'rest_framework.fields.empty'>, source=None, label=None, help_text=None, style=None, error_messages=None, validators=None, allow_null=False)

Bases: rest_framework.fields.Field

to_internal_value(data)

Transform the incoming primitive data into a native value.

to_representation(obj)

Transform the outgoing native value into primitive data.

onadata.libs.serializers.team_serializer module

class onadata.libs.serializers.team_serializer.TeamSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

create(validated_data)
get_projects(obj)

Organization Projects with default role

get_users(obj)
update(instance, validated_data)

onadata.libs.serializers.textit_serializer module

class onadata.libs.serializers.textit_serializer.TextItSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

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: rest_framework.serializers.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 onadata.apps.main.models.user_profile.UserProfile

owner_only_fields = ('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_is_org(obj)

Returns True if it is an organization profile.

to_representation(instance)

Serialize objects -> primitives.

update(instance, validated_data)
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(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.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 onadata.apps.main.models.user_profile.UserProfile

get_api_token(object)

Returns user’s API Token.

get_temp_token(object)

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

onadata.libs.serializers.user_serializer module

class onadata.libs.serializers.user_serializer.UserSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of django.contrib.auth.models.User

onadata.libs.serializers.widget_serializer module

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

Bases: rest_framework.relations.HyperlinkedRelatedField

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

Transform the incoming primitive data into a native value.

to_representation(value)

Transform the outgoing native value into primitive data.

class onadata.libs.serializers.widget_serializer.WidgetSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.widget.Widget

get_data(obj)
validate(attrs)
validate_content_object(value)

onadata.libs.serializers.xform_serializer module

class onadata.libs.serializers.xform_serializer.XFormBaseSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.xform_serializer.XFormMixin, rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.xform.XForm

read_only_fields = ('json', 'xml', 'date_created', 'date_modified', 'encrypted', 'bamboo_dataset', 'last_submission_time', 'is_merged_dataset')
class onadata.libs.serializers.xform_serializer.XFormCreateSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.xform_serializer.XFormSerializer

get_has_id_string_changed(obj)
class onadata.libs.serializers.xform_serializer.XFormListSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

get_manifest_url(obj)
get_url(obj)
get_version(obj)
class onadata.libs.serializers.xform_serializer.XFormManifestSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: rest_framework.serializers.Serializer

get_filename(obj)
get_hash(obj)
get_url(obj)
class onadata.libs.serializers.xform_serializer.XFormMixin

Bases: object

get_data_views(obj)
get_enketo_preview_url(obj)
get_enketo_url(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)
get_users(obj)
class onadata.libs.serializers.xform_serializer.XFormSerializer(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

Bases: onadata.libs.serializers.xform_serializer.XFormMixin, rest_framework.serializers.HyperlinkedModelSerializer

class Meta

Bases: object

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

alias of onadata.apps.logger.models.xform.XForm

read_only_fields = ('json', 'xml', 'date_created', 'date_modified', 'encrypted', 'bamboo_dataset', 'last_submission_time', 'is_merged_dataset')
get_form_versions(obj)
get_metadata(obj)
onadata.libs.serializers.xform_serializer.user_to_username(item)

Module contents