onadata.apps.main.models package

Submodules

onadata.apps.main.models.audit module

Audit model

class onadata.apps.main.models.audit.Audit(*args, **kwargs)

Bases: Model

Audit model - persists audit logs.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

json

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
class onadata.apps.main.models.audit.AuditLog(data)

Bases: object

AuditLog - creates and provide access to the Audit model records.

ACCOUNT = 'account'
CREATED_ON = 'created_on'
DEFAULT_BATCHSIZE = 1000
classmethod query_data(username, query=None, fields=None, sort=None, start=0, limit=1000, count=False)

Queries the Audit model and returns an iterator of the records.

classmethod query_iterator(sql, fields=None, params=None, count=False)

Returns an iterator of all records.

save()

Persists an audit to the DB

onadata.apps.main.models.google_oath module

Google auth token storage model class

class onadata.apps.main.models.google_oath.CredentialsField(*args, **kwargs)

Bases: Field

Django ORM field for storing OAuth2 Credentials. Modified version of https://github.com/onaio/oauth2client/blob/master/oauth2client/contrib/django_util/models.py

from_db_value(value, expression, connection, context=None)

Overrides models.Field method. This converts the value returned from the database to an instance of this class.

get_internal_type()
get_prep_value(value)

Overrides models.Field method. This is used to convert the value from an instances of this class to bytes that can be inserted into the database.

to_python(value)

Overrides models.Field method. This is used to convert bytes (from serialization etc) to an instance of this class

value_to_string(obj)

Convert the field value from the provided model to a string. Used during model serialization. Args:

obj: db.Model, model object

Returns:

string, the serialized field value

class onadata.apps.main.models.google_oath.TokenStorageModel(*args, **kwargs)

Bases: Model

Google Auth Token storage model

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

credential

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

id_id
objects = <django.db.models.manager.Manager object>

onadata.apps.main.models.meta_data module

MetaData model

class onadata.apps.main.models.meta_data.MetaData(*args, **kwargs)

Bases: Model

MetaData class model.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

content_object

Provide a generic many-to-one relation through the content_type and object_id fields.

This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.

content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

content_type_id
data_file

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world') as f:
...     instance.file = File(f)
data_file_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

static data_license(content_object, data_value=None)

Returns the metadata object where data_type is ‘data_license’

data_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

data_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_created

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

date_modified

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

deleted_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

static enketo_preview_url(content_object, data_value=None)

Returns the metadata object where data_type is ‘enketo_preview_url’

static enketo_single_submit_url(content_object, data_value=None)

Returns the metadata object where data_type is ‘enketo_single_submit_url’

static enketo_url(content_object, data_value=None)

Returns the metadata object where data_type is ‘enket_url’

static external_export(content_object, data_value=None)

Returns the metadata object where data_type is ‘external_export’

property external_export_name

Returns the external export name

property external_export_template

Returns the exxernal export, “XLS report”, template

property external_export_url

Returns the external export URL

extra_data

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

file_hash

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

static form_license(content_object, data_value=None)

Returns the metadata object where data_type is ‘form_license’

static get_google_sheet_details(obj)

Converts a metadata google sheet value, which contains data that is pipe separated, to a dictionary e.g ‘valueA a | valueB b’ to { ‘valueA’: ‘a’, ‘valueB’: ‘b’} :param content_object_pk: xform primary key :return dictionary containing google sheet details

property hash

Returns the md5 hash of the metadata file.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

static instance_csv_imported_by(content_object, data_value=None)

Returns the metadata object where data_type is ‘imported_via_csv_by’

property is_linked_dataset

Returns True if the metadata object is a linked dataset.

static mapbox_layer_upload(content_object, data=None)

Returns the metadata object where data_type is ‘mapbox_layer’

static media_add_uri(content_object, uri)

Add a uri as a media resource

static media_upload(content_object, data_file=None, download=False)

Returns the metadata object where data_type is ‘media’

object_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>

Returns the public link metadata.

static published_by_formbuilder(content_object, data_value=None)

Returns the metadata object where data_type is ‘published_by_formbuilder’

save(*args, **kwargs)

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

static set_google_sheet_details(content_object, data_value=None)

Returns Google Sheet details metadata object.

set_hash()

Returns the md5 hash of the metadata file.

soft_delete()

Mark the MetaData as soft deleted, by updating the deleted_at field.

static source(content_object, data_value=None, data_file=None)

Returns the metadata object where data_type is ‘source’

static submission_review(content_object, data_value=None)

Returns the metadata object where data_type is ‘submission_review’

static supporting_docs(content_object, data_file=None)

Returns the metadata object where data_type is ‘supporting_doc’

static textit(content_object, data_value=None)

Add a textit auth token flow uuid and default contact uuid

static textit_flow_details(content_object, data_value: str = '')

Returns the metadata object where data_type is ‘textit_details’

static xform_meta_permission(content_object, data_value=None)

Returns the metadata object where data_type is ‘xform_meta_perms’

onadata.apps.main.models.meta_data.clear_cached_metadata_instance_object(sender, instance=None, created=False, **kwargs)

Clear the cache for the metadata object.

onadata.apps.main.models.meta_data.create_media(media)

Download media link

onadata.apps.main.models.meta_data.get_default_content_type()

Returns the default content type id for the XForm model.

onadata.apps.main.models.meta_data.is_valid_url(uri)

Validates a URI.

onadata.apps.main.models.meta_data.media_resources(media_list, download=False)

List of MetaData objects of type media

@param media_list - list of MetaData objects of type media @param download - boolean, when True downloads media files when media.data_value is a valid url

return a list of MetaData objects

onadata.apps.main.models.meta_data.save_metadata(metadata_obj)

Saves the MetaData object and returns it.

onadata.apps.main.models.meta_data.type_for_form(content_object, data_type)

Returns the MetaData queryset for content_object of the given data_type.

onadata.apps.main.models.meta_data.unique_type_for_form(content_object, data_type, data_value=None, data_file=None)

Ensure that each metadata object has unique xform and data_type fields

return the metadata object

onadata.apps.main.models.meta_data.update_attached_object(sender, instance=None, created=False, **kwargs)

Save the content_object attached to a MetaData instance.

onadata.apps.main.models.meta_data.upload_to(instance, filename)

Returns the upload path for given filename.

onadata.apps.main.models.user_profile module

UserProfile model class

class onadata.apps.main.models.user_profile.UserProfile(*args, **kwargs)

Bases: Model

Userprofile model

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

address

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

country

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

created_by_id
date_modified

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

description

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_country_display(*, field=<django.db.models.fields.CharField: country>)
get_next_by_date_modified(*, field=<django.db.models.fields.DateTimeField: date_modified>, is_next=True, **kwargs)
get_previous_by_date_modified(*, field=<django.db.models.fields.DateTimeField: date_modified>, is_next=False, **kwargs)
property gravatar

Returns Gravatar URL.

property gravatar_exists

Check if Gravatar URL exists.

home_page

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

metadata

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

num_of_submissions

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
organization

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

organizationprofile

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

phonenumber

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

require_auth

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save(force_insert=False, force_update=False, using=None, update_fields=None)

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

twitter

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property twitter_clean

Remove the ‘@’ from twitter name.

user

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

user_id
userprofilegroupobjectpermission_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

userprofileuserobjectpermission_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class onadata.apps.main.models.user_profile.UserProfileGroupObjectPermission(*args, **kwargs)

Bases: GroupObjectPermissionBase

Guardian model to create direct foreign keys.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

content_object

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

content_object_id
group

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

permission

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

class onadata.apps.main.models.user_profile.UserProfileUserObjectPermission(*args, **kwargs)

Bases: UserObjectPermissionBase

Guardian model to create direct foreign keys.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

content_object

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

content_object_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

permission

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

onadata.apps.main.models.user_profile.create_auth_token(sender, instance=None, created=False, **kwargs)

Creates an authentication Token.

onadata.apps.main.models.user_profile.set_kpi_formbuilder_permissions(sender, instance=None, created=False, **kwargs)

Assign KPI permissions to allow the user to create forms using KPI formbuilder.

onadata.apps.main.models.user_profile.set_object_permissions(sender, instance=None, created=False, **kwargs)

Assign’s permission to the user that created the profile.

Module contents

Main models.