onadata.apps.viewer.models package

Submodules

onadata.apps.viewer.models.column_rename module

class onadata.apps.viewer.models.column_rename.ColumnRename(id, xpath, column_name)

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

column_name

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

classmethod get_dict()
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>
xpath

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

onadata.apps.viewer.models.data_dictionary module

DataDictionary model.

class onadata.apps.viewer.models.data_dictionary.DataDictionary(*args, **kwargs)

Bases: onadata.apps.logger.models.xform.XForm

DataDictionary model class.

exception DoesNotExist

Bases: onadata.apps.logger.models.xform.DoesNotExist

exception MultipleObjectsReturned

Bases: onadata.apps.logger.models.xform.MultipleObjectsReturned

file_name()
metadata_set

Accessor to the related objects manager on the one-to-many relation created by GenericRelation.

In the example:

class Post(Model):
    comments = GenericRelation(Comment)

post.comments is a ReverseGenericManyToOneDescriptor instance.

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.

tagged_items

Accessor to the related objects manager on the one-to-many relation created by GenericRelation.

In the example:

class Post(Model):
    comments = GenericRelation(Comment)

post.comments is a ReverseGenericManyToOneDescriptor instance.

onadata.apps.viewer.models.data_dictionary.is_newline_error(e)

Return True is e is a new line error based on the error text. Otherwise return False.

onadata.apps.viewer.models.data_dictionary.process_xlsform(xls, default_name)

Process XLSForm file and return the survey dictionary for the XLSForm.

onadata.apps.viewer.models.data_dictionary.save_project(sender, instance=None, created=False, **kwargs)

Receive XForm project to update date_modified field of the project and on the next XHR request the form will be included in the project data.

onadata.apps.viewer.models.data_dictionary.set_object_permissions(instance=None, created=False)

Apply the relevant object permissions for the form to all users who should have access to it.

onadata.apps.viewer.models.data_dictionary.setup_xls_dataelements(instance, created)

Start creation of dataelements

onadata.apps.viewer.models.data_dictionary.setup_xls_file(instance=None, created=False, **kwargs)

Sets up XLS File: creates permissions and dataelements file

onadata.apps.viewer.models.data_dictionary.sheet_to_csv(xls_content, sheet_name)

Writes a csv file of a specified sheet from a an excel file

Parameters
  • xls_content – Excel file contents

  • sheet_name – the name of the excel sheet to generate the csv file

Returns

a (StrionIO) csv file object

onadata.apps.viewer.models.data_dictionary.upload_to(instance, filename, username=None)

Return XLSForm file upload path.

onadata.apps.viewer.models.export module

Export model.

class onadata.apps.viewer.models.export.Export(*args, **kwargs)

Bases: django.db.models.base.Model

Class representing a data export from an XForm

CSV_EXPORT = 'csv'
CSV_ZIP_EXPORT = 'csv_zip'
DHIS2CSV_EXPORT = 'dhis2csv'
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

EXPORT_MIMES = {'csv': 'csv', 'csv_zip': 'zip', 'dhis2csv': 'csv', 'kml': 'vnd.google-earth.kml+xml', 'osm': 'osm', 'sav': 'sav', 'sav_zip': 'zip', 'xls': 'vnd.ms-excel', 'xlsx': 'vnd.openxmlformats', 'zip': 'zip'}
EXPORT_OPTION_FIELDS = ['binary_select_multiples', 'dataview_pk', 'group_delimiter', 'include_images', 'include_labels', 'include_labels_only', 'include_hxl', 'language', 'query', 'remove_group_name', 'show_choice_labels', 'include_reviews', 'split_select_multiples', 'value_select_multiples', 'win_excel_utf8', 'start', 'end', 'start_index', 'limit']
EXPORT_TYPES = [('xls', 'Excel'), ('csv', 'CSV'), ('dhis2csv', 'DHIS2CSV'), ('zip', 'ZIP'), ('kml', 'kml'), ('csv_zip', 'CSV ZIP'), ('sav_zip', 'SAV ZIP'), ('sav', 'SAV'), ('external', 'Excel'), ('osm', 'osm'), ('gsheets', 'Google Sheets')]
EXPORT_TYPE_DICT = {'csv': 'CSV', 'csv_zip': 'CSV ZIP', 'dhis2csv': 'DHIS2CSV', 'external': 'Excel', 'gsheets': 'Google Sheets', 'kml': 'kml', 'osm': 'osm', 'sav': 'SAV', 'sav_zip': 'SAV ZIP', 'xls': 'Excel', 'zip': 'ZIP'}
EXTERNAL_EXPORT = 'external'
FAILED = 2
GOOGLE_SHEETS_EXPORT = 'gsheets'
KML_EXPORT = 'kml'
MAX_EXPORTS = 10
exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

OSM_EXPORT = 'osm'
PENDING = 0
SAV_EXPORT = 'sav'
SAV_ZIP_EXPORT = 'sav_zip'
SUCCESSFUL = 1
XLS_EXPORT = 'xls'
ZIP_EXPORT = 'zip'
created_on

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

error_message

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

export_type

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

export_url

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

classmethod exports_outdated(xform, export_type, options=None)

Return True if export is outdated or there is no export matching the export_type with the specified options.

filedir

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

filename

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

filepath

Return the file path of an export file, None if the file does not exist.

full_filepath

Return the full filepath of an export file, None if the file does not exist.

get_export_type_display(*, field=<django.db.models.fields.CharField: export_type>)
get_next_by_created_on(*, field=<django.db.models.fields.DateTimeField: created_on>, is_next=True, **kwargs)
get_previous_by_created_on(*, field=<django.db.models.fields.DateTimeField: created_on>, is_next=False, **kwargs)
id

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

internal_status

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

classmethod is_filename_unique(xform, filename)

Return True if the filename is unique.

is_pending

Return True if an export status is pending.

is_successful

Return True if an export status successful.

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

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

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.

set_filename(filename)

Set the filename of an export and mark internal_status as Export.SUCCESSFUL.

status

Return the status [FAILED|PENDING|SUCCESSFUL] of an export.

task_id

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

time_of_last_submission

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

xform

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.

xform_id

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

exception onadata.apps.viewer.models.export.ExportConnectionError

Bases: Exception

ExportConnectionError exception class.

exception onadata.apps.viewer.models.export.ExportTypeError

Bases: Exception

ExportTypeError exception class.

onadata.apps.viewer.models.export.export_delete_callback(sender, **kwargs)

Delete export file when an export object is deleted.

onadata.apps.viewer.models.export.get_export_options_query_kwargs(options)

Get dict with options JSONField lookups for export options field

onadata.apps.viewer.models.parsed_instance module

exception onadata.apps.viewer.models.parsed_instance.ParseError

Bases: Exception

class onadata.apps.viewer.models.parsed_instance.ParsedInstance(id, instance, start_time, end_time, lat, lng)

Bases: django.db.models.base.Model

DEFAULT_BATCHSIZE = 1000
DEFAULT_LIMIT = 1000000
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

STATUS = '_status'
USERFORM_ID = '_userform_id'
add_note(note)
classmethod dicts(xform)
end_time

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

get_notes()
id

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

instance

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.

instance_id

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

lat

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

lng

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>
remove_note(pk)
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.

start_time

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

to_dict()
to_dict_for_mongo()
onadata.apps.viewer.models.parsed_instance.datetime_from_str(text)
onadata.apps.viewer.models.parsed_instance.dict_for_mongo(d)
onadata.apps.viewer.models.parsed_instance.get_etag_hash_from_query(queryset, sql=None, params=None)

Returns md5 hash from the date_modified field or

onadata.apps.viewer.models.parsed_instance.get_name_from_survey_element(element)
onadata.apps.viewer.models.parsed_instance.get_sql_with_params(xform, query=None, fields=None, sort=None, start=None, end=None, start_index=None, limit=None, count=None)
onadata.apps.viewer.models.parsed_instance.query_data(xform, query=None, fields=None, sort=None, start=None, end=None, start_index=None, limit=None, count=None)

Module contents