onadata.libs.utils package¶
Submodules¶
onadata.libs.utils.api_export_tools module¶
-
onadata.libs.utils.api_export_tools.
custom_response_handler
(request, xform, query, export_type, token=None, meta=None, dataview=False, filename=None)¶
-
onadata.libs.utils.api_export_tools.
external_export_response
(export)¶
-
onadata.libs.utils.api_export_tools.
generate_google_web_flow
(request)¶
-
onadata.libs.utils.api_export_tools.
get_async_response
(job_uuid, request, xform, count=0)¶
-
onadata.libs.utils.api_export_tools.
include_hxl_row
(dv_columns, hxl_columns)¶ This function returns a boolean value. If the dataview’s columns are not part of the hxl columns, we return False. Returning False would mean that we don’t have to add the hxl column row if there aren’t any hxl columns in the dataview. :param dv_columns - dataview columns :param hxl_columns - hxl columns from the dataview’s xform
:return True or False
-
onadata.libs.utils.api_export_tools.
log_export
(request, xform, export_type)¶
-
onadata.libs.utils.api_export_tools.
process_async_export
(request, xform, export_type, options=None)¶ Check if should generate export or just return the latest export. Rules for regenerating an export are:
Filter included on the exports.
New submission done.
- Always regenerate external exports.
- (External exports uses templates and the template might have
changed)
Parameters: - request –
- xform –
- export_type –
- options – additional export params that may include query: export filter token: template url for xls external reports meta: metadataid that contains the external xls report template url remove_group_name: Flag to determine if group names should appear
Returns: response dictionary
-
onadata.libs.utils.api_export_tools.
response_for_format
(data, format=None)¶
onadata.libs.utils.async_status module¶
-
onadata.libs.utils.async_status.
async_status
(status, error=None)¶
-
onadata.libs.utils.async_status.
celery_state_to_status
(state)¶
onadata.libs.utils.audit module¶
onadata.libs.utils.backup_tools module¶
-
onadata.libs.utils.backup_tools.
create_zip_backup
(zip_output_file, user, xform=None)¶
-
onadata.libs.utils.backup_tools.
restore_backup_from_path
(dir_path, username, status)¶ Only restores xml submissions, media files are assumed to still be in storage and will be retrieved by the filename stored within the submission
-
onadata.libs.utils.backup_tools.
restore_backup_from_xml_file
(xml_instance_path, username)¶
-
onadata.libs.utils.backup_tools.
restore_backup_from_zip
(zip_file_path, username)¶
onadata.libs.utils.briefcase_client module¶
-
class
onadata.libs.utils.briefcase_client.
BriefcaseClient
(url, username, password, user)¶ Bases:
object
-
download_instances
(form_id, cursor=0, num_entries=100)¶
-
download_manifest
(manifest_url, id_string)¶
-
download_media_files
(xml_doc, media_path)¶
-
download_xforms
(include_instances=False)¶
-
get_instances_uuids
(xml_doc)¶
-
push
()¶
-
-
onadata.libs.utils.briefcase_client.
django_file
(file_obj, field_name, content_type)¶
-
onadata.libs.utils.briefcase_client.
node_value
(node, tag_name)¶
-
onadata.libs.utils.briefcase_client.
retry
(tries, delay=3, backoff=2)¶ - Adapted from code found here:
- http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
Retries a function or method until it returns True.
delay sets the initial delay in seconds, and backoff sets the factor by which the delay should lengthen after each failure. backoff must be greater than 1, or else it isn’t really a backoff. tries must be at least 0, and delay greater than 0.
onadata.libs.utils.chart_tools module¶
-
onadata.libs.utils.chart_tools.
build_chart_data
(xform, language_index=0, page=0)¶
-
onadata.libs.utils.chart_tools.
build_chart_data_for_field
(xform, field, language_index=0, choices=None, group_by=None, data_view=None)¶
-
onadata.libs.utils.chart_tools.
build_chart_data_from_widget
(widget, language_index=0)¶
-
onadata.libs.utils.chart_tools.
calculate_ranges
(page, items_per_page, total_items)¶ Return the offset and end indices for a slice.
-
onadata.libs.utils.chart_tools.
find_choice_label
(choices, string)¶
-
onadata.libs.utils.chart_tools.
get_chart_data_for_field
(field_name, xform, accepted_format, group_by, field_xpath=None, data_view=None)¶ Get chart data for a given xlsform field.
-
onadata.libs.utils.chart_tools.
get_choice_label
(choices, string)¶ string is the name value found in the choices sheet.
Select one names should not contain spaces but some do and this conflicts with Select Multiple fields which use spaces to distinguish multiple choices.
A temporal fix to this is to search the choices list for both the full-string and the split keys.
-
onadata.libs.utils.chart_tools.
get_field_choices
(field, xform)¶ Retrieve field choices from a form survey element :param field: :param xform: :return: Form field choices
-
onadata.libs.utils.chart_tools.
get_field_from_field_name
(field_name, xform)¶
-
onadata.libs.utils.chart_tools.
get_field_from_field_xpath
(field_xpath, xform)¶
-
onadata.libs.utils.chart_tools.
get_field_label
(field, language_index=0)¶
-
onadata.libs.utils.chart_tools.
utc_time_string_for_javascript
(date_string)¶ Convert 2014-01-16T12:07:23.322+03 to 2014-01-16T12:07:23.322+03:00
Cant use datetime.str[fp]time here since python 2.7’s %z is platform dependant - http://stackoverflow.com/questions/2609259/converting-string-t o-datetime-object-in-python
onadata.libs.utils.common_tags module¶
onadata.libs.utils.common_tools module¶
-
onadata.libs.utils.common_tools.
get_boolean_value
(str_var, default=None)¶
-
onadata.libs.utils.common_tools.
str_to_bool
(s)¶ Return boolean True or False if string s represents a boolean value
onadata.libs.utils.country_field module¶
onadata.libs.utils.csv_builder module¶
-
class
onadata.libs.utils.csv_builder.
AbstractDataFrameBuilder
(username, id_string, filter_query=None, group_delimiter='/', split_select_multiples=True, binary_select_multiples=False, start=None, end=None, remove_group_name=False, xform=None, include_labels=False, include_labels_only=False, include_images=True, include_hxl=False, win_excel_utf8=False)¶ Bases:
object
-
ADDITIONAL_COLUMNS
= [u'_uuid', u'_submission_time', u'_tags', u'_notes', u'_version', u'_duration', u'_submitted_by']¶
-
BINARY_SELECT_MULTIPLES
= False¶ Group functionality used by any DataFrameBuilder i.e. XLS, CSV and KML
-
IGNORED_COLUMNS
= [u'_xform_id_string', u'_status', u'_id', u'_attachments', u'_geolocation', u'_bamboo_dataset_id', u'_deleted_at', '_edited']¶
-
-
class
onadata.libs.utils.csv_builder.
CSVDataFrameBuilder
(username, id_string, filter_query=None, group_delimiter='/', split_select_multiples=True, binary_select_multiples=False, start=None, end=None, remove_group_name=False, xform=None, include_labels=False, include_labels_only=False, include_images=False, include_hxl=False, win_excel_utf8=False)¶ Bases:
onadata.libs.utils.csv_builder.AbstractDataFrameBuilder
-
export_to
(path, dataview=None)¶
-
-
onadata.libs.utils.csv_builder.
get_column_names_only
(columns, dd, group_delimiter)¶
-
onadata.libs.utils.csv_builder.
get_labels_from_columns
(columns, dd, group_delimiter)¶
-
onadata.libs.utils.csv_builder.
get_prefix_from_xpath
(xpath)¶
-
onadata.libs.utils.csv_builder.
remove_dups_from_list_maintain_order
(l)¶
-
onadata.libs.utils.csv_builder.
write_to_csv
(path, rows, columns, columns_with_hxl=None, remove_group_name=False, dd=None, group_delimiter='/', include_labels=False, include_labels_only=False, include_hxl=False, win_excel_utf8=False)¶
onadata.libs.utils.csv_import module¶
-
onadata.libs.utils.csv_import.
dict2xmlsubmission
(submission_dict, xform, instance_id, submission_date)¶ Creates and xml submission from an appropriate dict (& other data)
Parameters: Returns: An xml submission string
Return type:
-
onadata.libs.utils.csv_import.
dict_merge
(a, b)¶ Returns a merger of two dicts a and b
credits: https://www.xormedia.com/recursively-merge-dictionaries-in-python
Parameters: Returns: The merger
Return type:
-
onadata.libs.utils.csv_import.
dict_pathkeys_to_nested_dicts
(dictionary)¶ Turns a flat dict to a nested dict
Takes a dict with pathkeys or “slash-namespaced” keys and inflates them into nested dictionaries i.e:- d[‘/path/key/123’] -> d[‘path’][‘key’][‘123’]
Parameters: dictionary (dict) – A dict with one or more “slash-namespaced” keys Returns: A nested dict Return type: dict
-
onadata.libs.utils.csv_import.
get_async_csv_submission_status
(job_uuid)¶ Gets CSV Submision progress or result Can be used to pol long running submissions :param str job_uuid: The submission job uuid returned by _submit_csv.delay :return: Dict with import progress info (insertions & total) :rtype: Dict
-
onadata.libs.utils.csv_import.
get_submission_meta_dict
(xform, instance_id)¶ Generates metadata for our submission
Checks if instance_id belongs to an existing submission. If it does, it’s considered an edit and its uuid gets deprecated. In either case, a new one is generated and assigned.
Parameters: - xform (onadata.apps.logger.models.XForm) – The submission’s XForm.
- instance_id (string) – The submission/instance uuid.
Returns: The metadata dict
Return type:
-
onadata.libs.utils.csv_import.
submit_csv
(username, xform, csv_file)¶ Imports CSV data to an existing form
Takes a csv formatted file or string containing rows of submission/instance and converts those to xml submissions and finally submits them by calling
onadata.libs.utils.logger_tools.safe_create_instance()
Parameters: - username (str) – the subission user
- xfrom (onadata.apps.logger.models.XForm) – The submission’s XForm.
- or file) ((str) – A CSV formatted file with submission rows.
Returns: If sucessful, a dict with import summary else dict with error str.
Return type: Dict
onadata.libs.utils.csv_reader module¶
-
class
onadata.libs.utils.csv_reader.
CsvReader
(path)¶ Bases:
object
Typical usage:
csv_reader = CsvReader(path) for d in csv_reader.iter_dicts(): Variable.objects.create(**d)
-
close
()¶
-
iter_dicts
()¶
-
next
()¶ A CsvReader object is iterable (since we have defined __iter__ and next methods. Each iteration of this object returns a row of data.
-
open
(path)¶
-
onadata.libs.utils.decorators module¶
-
onadata.libs.utils.decorators.
apply_form_field_names
(func)¶
-
onadata.libs.utils.decorators.
check_obj
(f)¶
-
onadata.libs.utils.decorators.
is_owner
(view_func)¶
onadata.libs.utils.dict_tools module¶
-
onadata.libs.utils.dict_tools.
csv_dict_to_nested_dict
(a)¶
-
onadata.libs.utils.dict_tools.
get_values_matching_key
(doc, key)¶
-
onadata.libs.utils.dict_tools.
list_to_dict
(items, value)¶
-
onadata.libs.utils.dict_tools.
merge_list_of_dicts
(list_of_dicts)¶
-
onadata.libs.utils.dict_tools.
remove_indices_from_dict
(obj)¶
onadata.libs.utils.export_builder module¶
-
class
onadata.libs.utils.export_builder.
ExportBuilder
¶ Bases:
object
-
BINARY_SELECT_MULTIPLES
= False¶
-
CONVERT_FUNCS
= {'int': <function <lambda> at 0x7ffa0bab5758>, 'date': <function <lambda> at 0x7ffa0bab5848>, 'decimal': <function <lambda> at 0x7ffa0bab57d0>, 'dateTime': <function <lambda> at 0x7ffa0bab58c0>}¶
-
EXTRA_FIELDS
= [u'_id', u'_uuid', u'_submission_time', u'_index', u'_parent_table_name', u'_parent_index', u'_tags', u'_notes', u'_version', u'_duration', u'_submitted_by']¶
-
GROUP_DELIMITER
= '/'¶
-
GROUP_DELIMITERS
= ['/', '.']¶
-
GROUP_DELIMITER_DOT
= '.'¶
-
GROUP_DELIMITER_SLASH
= '/'¶
-
IGNORED_COLUMNS
= [u'_xform_id_string', u'_status', u'_attachments', u'_geolocation', u'_bamboo_dataset_id', u'_deleted_at']¶
-
INCLUDE_HXL
= False¶
-
INCLUDE_IMAGES
= True¶
-
INCLUDE_LABELS
= False¶
-
INCLUDE_LABELS_ONLY
= False¶
-
SPLIT_SELECT_MULTIPLES
= True¶
-
TRUNCATE_GROUP_TITLE
= False¶
-
TYPES_TO_CONVERT
= ['int', 'decimal', 'date']¶
-
XLS_SHEET_NAME_MAX_CHARS
= 31¶
-
classmethod
convert_type
(value, data_type)¶ Convert data to its native type e.g. string ‘1’ to int 1 @param value: the string value to convert @param data_type: the native data type to convert to @return: the converted value
-
classmethod
decode_mongo_encoded_fields
(row, encoded_fields)¶
-
classmethod
decode_mongo_encoded_section_names
(data)¶
-
classmethod
format_field_title
(abbreviated_xpath, field_delimiter, data_dictionary, remove_group_name=False)¶
-
get_choice_label_from_dict
(label)¶
-
get_default_language
(languages)¶
-
get_fields
(dataview, section, key)¶
-
classmethod
get_valid_sheet_name
(desired_name, existing_names)¶
-
pre_process_row
(row, section)¶ Split select multiples, gps and decode . and $
-
section_by_name
(name)¶
-
set_survey
(survey)¶
-
classmethod
split_gps_components
(row, gps_fields)¶
-
classmethod
split_select_multiples
(row, select_multiples)¶
-
classmethod
string_to_date_with_xls_validation
(date_str)¶
-
to_flat_csv_export
(path, data, username, id_string, filter_query, **kwargs)¶
-
to_xls_export
(path, data, *args, **kwargs)¶
-
to_zipped_csv
(path, data, *args, **kwargs)¶
-
to_zipped_sav
(path, data, *args, **kwargs)¶
-
url
= None¶
-
-
onadata.libs.utils.export_builder.
current_site_url
(path)¶ Returns fully qualified URL (no trailing slash) for the current site. :param path :return: complete url
-
onadata.libs.utils.export_builder.
dict_to_joined_export
(data, index, indices, name, survey, row, media_xpaths=[])¶ Converts a dict into one or more tabular datasets :param data: current record which can be changed or updated :param index: keeps count of record number :param indices: a dictionary storing list values if data is a dict :param name: the name of the survey :param survey: the survey :param row: current record that remains unchanged on this function’s recall
-
onadata.libs.utils.export_builder.
encode_if_str
(row, key, encode_dates=False)¶
-
onadata.libs.utils.export_builder.
get_data_dictionary_from_survey
(survey)¶
-
onadata.libs.utils.export_builder.
get_value_or_attachment_uri
(key, value, row, data_dictionary, media_xpaths, attachment_list=None)¶ Gets either the attachment value or the attachment url :param key: used to retrieve survey element :param value: filename :param row: current records row :param data_dictionary: form structure :param include_images: boolean value to either inlcude images or not :param attachment_list: to be used incase row doesn’t have ATTACHMENTS key :return: value
onadata.libs.utils.export_tools module¶
-
onadata.libs.utils.export_tools.
clean_keys_of_slashes
(record)¶ Replaces the slashes found in a dataset keys with underscores :param record: list containing a couple of dictionaries :return: record with keys without slashes
-
onadata.libs.utils.export_tools.
create_export_object
(xform, export_type, options)¶
-
onadata.libs.utils.export_tools.
dict_to_flat_export
(d, parent_index=0)¶
-
onadata.libs.utils.export_tools.
export_retry
(tries, delay=3, backoff=2)¶ - Adapted from code found here:
- http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
Retries a function or method until it returns True.
delay sets the initial delay in seconds, and backoff sets the factor by which the delay should lengthen after each failure. backoff must be greater than 1, or else it isn’t really a backoff. tries must be at least 0, and delay greater than 0.
-
onadata.libs.utils.export_tools.
generate_attachments_zip_export
(export_type, username, id_string, export_id=None, options=None, xform=None)¶ Generates zip export of attachments.
param: export_type params: username: logged in username params: id_string: xform id_string params: export_id: ID of export object associated with the request param: options: additional parameters required for the lookup.
ext: File extension of the generated export
-
onadata.libs.utils.export_tools.
generate_export
(self, *args, **kwargs)¶
-
onadata.libs.utils.export_tools.
generate_external_export
(export_type, username, id_string, export_id=None, options=None, xform=None)¶ Generates external export using ONA data through an external service.
param: export_type params: username: logged in username params: id_string: xform id_string params: export_id: ID of export object associated with the request param: options: additional parameters required for the lookup.
data_id: instance id query: filter_query for custom queries meta: metadata associated with external export token: authentication key required by external service
-
onadata.libs.utils.export_tools.
generate_kml_export
(export_type, username, id_string, export_id=None, options=None, xform=None)¶ Generates kml export for geographical data
param: export_type params: username: logged in username params: id_string: xform id_string params: export_id: ID of export object associated with the request param: options: additional parameters required for the lookup.
ext: File extension of the generated export
-
onadata.libs.utils.export_tools.
generate_osm_export
(export_type, username, id_string, export_id=None, options=None, xform=None)¶ Generates osm export for OpenStreetMap data
param: export_type params: username: logged in username params: id_string: xform id_string params: export_id: ID of export object associated with the request param: options: additional parameters required for the lookup.
ext: File extension of the generated export
-
onadata.libs.utils.export_tools.
get_export_options
(options)¶
-
onadata.libs.utils.export_tools.
get_or_create_export
(export_id, xform, export_type, options)¶
-
onadata.libs.utils.export_tools.
increment_index_in_filename
(filename)¶ filename should be in the form file.ext or file-2.ext - we check for the dash and index and increment appropriately
-
onadata.libs.utils.export_tools.
kml_export_data
(id_string, user, xform=None)¶
-
onadata.libs.utils.export_tools.
md5hash
(string)¶
-
onadata.libs.utils.export_tools.
newest_export_for
(xform, export_type, options)¶ Retrieve the latest export given the following arguments:
param: xform param: export_type param: options: additional parameters required for the lookup.
remove_group_name: boolean flag group_delimiter: “/” or ”.” with “/” as the default split_select_multiples: boolean flag binary_select_multiples: boolean flag
-
onadata.libs.utils.export_tools.
parse_request_export_options
(params)¶ Parse export options in the request object into values returned in a list. The list represents a boolean for whether the group name should be removed, the group delimiter, and a boolean for whether select multiples should be split.
-
onadata.libs.utils.export_tools.
should_create_new_export
(xform, export_type, options, request=None)¶ Function that determines whether to create a new export. param: xform param: export_type param: options: additional parameters required for the lookup.
remove_group_name: boolean flag group_delimiter: “/” or ”.” with “/” as the default split_select_multiples: boolean flag binary_select_multiples: boolean flagparams: request: Get params are used to determine if new export is required
-
onadata.libs.utils.export_tools.
upload_template_for_external_export
(server, file_obj)¶
onadata.libs.utils.google module¶
onadata.libs.utils.gravatar module¶
-
onadata.libs.utils.gravatar.
email_md5
(user)¶
-
onadata.libs.utils.gravatar.
get_gravatar_img_link
(user)¶
-
onadata.libs.utils.gravatar.
gravatar_exists
(user)¶
onadata.libs.utils.image_tools module¶
-
onadata.libs.utils.image_tools.
flat
(*nums)¶ Build a tuple of ints from float or integer arguments. Useful because PIL crop and resize require integer points. source: https://gist.github.com/16a01455
-
onadata.libs.utils.image_tools.
get_dimensions
()¶
-
onadata.libs.utils.image_tools.
image_url
(attachment, suffix)¶ Return url of an image given size(@param suffix) e.g large, medium, small, or generate required thumbnail
-
onadata.libs.utils.image_tools.
resize
(filename)¶
-
onadata.libs.utils.image_tools.
resize_local_env
(filename)¶
onadata.libs.utils.log module¶
-
class
onadata.libs.utils.log.
AuditLogHandler
(model='')¶ Bases:
logging.Handler
-
emit
(record)¶
-
get_model
(name)¶
-
-
onadata.libs.utils.log.
audit_log
(action, request_user, account_user, message, audit, request, level=10)¶ Create a log message based on these params
@param action: Action performed e.g. form-deleted @param request_username: User performing the action @param account_username: The formhub account the action was performed on @param message: The message to be displayed on the log @param level: log level @param audit: a dict of key/values of other info pertaining to the action e.g. form’s id_string, submission uuid @return: None
onadata.libs.utils.logger_tools module¶
-
class
onadata.libs.utils.logger_tools.
BaseOpenRosaResponse
(*args, **kwargs)¶ Bases:
django.http.response.HttpResponse
-
status_code
= 201¶
-
-
class
onadata.libs.utils.logger_tools.
OpenRosaResponse
(*args, **kwargs)¶ Bases:
onadata.libs.utils.logger_tools.BaseOpenRosaResponse
-
status_code
= 201¶
-
-
class
onadata.libs.utils.logger_tools.
OpenRosaResponseBadRequest
(*args, **kwargs)¶ Bases:
onadata.libs.utils.logger_tools.OpenRosaResponse
-
status_code
= 400¶
-
-
class
onadata.libs.utils.logger_tools.
OpenRosaResponseForbidden
(*args, **kwargs)¶ Bases:
onadata.libs.utils.logger_tools.OpenRosaResponse
-
status_code
= 403¶
-
-
class
onadata.libs.utils.logger_tools.
OpenRosaResponseNotAllowed
(*args, **kwargs)¶ Bases:
onadata.libs.utils.logger_tools.OpenRosaResponse
-
status_code
= 405¶
-
-
class
onadata.libs.utils.logger_tools.
OpenRosaResponseNotFound
(*args, **kwargs)¶ Bases:
onadata.libs.utils.logger_tools.OpenRosaResponse
-
status_code
= 404¶
-
-
onadata.libs.utils.logger_tools.
check_edit_submission_permissions
(request_user, xform)¶
-
onadata.libs.utils.logger_tools.
check_submission_permissions
(request, xform)¶ Check that permission is required and the request user has permission.
- The user does no have permissions iff:
- the user is authed,
- either the profile or the form require auth,
- the xform user is not submitting.
Since we have a username, the Instance creation logic will handle checking for the forms existence by its id_string.
Returns: None. Raises: PermissionDenied based on the above criteria.
-
onadata.libs.utils.logger_tools.
create_instance
(username, xml_file, media_files, status=u'submitted_via_web', uuid=None, date_created_override=None, request=None)¶ I used to check if this file had been submitted already, I’ve taken this out because it was too slow. Now we’re going to create a way for an admin to mark duplicate instances. This should simplify things a bit. Submission cases: * If there is a username and no uuid, submitting an old ODK form. * If there is a username and a uuid, submitting a new ODK form.
-
onadata.libs.utils.logger_tools.
dict2xform
(jsform, form_id)¶
-
onadata.libs.utils.logger_tools.
generate_content_disposition_header
(name, extension, show_date=True)¶
-
onadata.libs.utils.logger_tools.
get_filtered_instances
(*args, **kwargs)¶ Get filtered instances - mainly to allow mocking in tests
-
onadata.libs.utils.logger_tools.
get_uuid_from_submission
(xml)¶
-
onadata.libs.utils.logger_tools.
get_xform_from_submission
(xml, username, uuid=None)¶
-
onadata.libs.utils.logger_tools.
inject_instanceid
(xml_str, uuid)¶
-
onadata.libs.utils.logger_tools.
publish_form
(callback)¶
-
onadata.libs.utils.logger_tools.
publish_xls_form
(xls_file, user, project, id_string=None, created_by=None)¶ Create or update DataDictionary with xls_file, user id_string is optional when updating
-
onadata.libs.utils.logger_tools.
publish_xml_form
(xml_file, user, project, id_string=None, created_by=None)¶
-
onadata.libs.utils.logger_tools.
remove_xform
(xform)¶
-
onadata.libs.utils.logger_tools.
report_exception
(subject, info, exc_info=None)¶
-
onadata.libs.utils.logger_tools.
response_with_mimetype_and_name
(mimetype, name, extension=None, show_date=True, file_path=None, use_local_filesystem=False, full_mime=False)¶
-
onadata.libs.utils.logger_tools.
safe_create_instance
(username, xml_file, media_files, uuid, request)¶ Create an instance and catch exceptions.
Returns: A list [error, instance] where error is None if there was no error.
-
onadata.libs.utils.logger_tools.
save_attachments
(xform, instance, media_files)¶
-
onadata.libs.utils.logger_tools.
save_submission
(xform, xml, media_files, new_uuid, submitted_by, status, date_created_override)¶
-
onadata.libs.utils.logger_tools.
store_temp_file
(data)¶
onadata.libs.utils.middleware module¶
-
class
onadata.libs.utils.middleware.
ExceptionLoggingMiddleware
¶ Bases:
object
-
process_exception
(request, exception)¶
-
-
class
onadata.libs.utils.middleware.
HTTPResponseNotAllowedMiddleware
¶ Bases:
object
-
process_response
(request, response)¶
-
onadata.libs.utils.model_tools module¶
-
onadata.libs.utils.model_tools.
generate_uuid_for_form
()¶
-
onadata.libs.utils.model_tools.
get_columns_with_hxl
(survey_elements)¶ Returns a dictionary whose keys are xform field names and values are instance::hxl values set on the xform :param include_hxl - boolean value :param survey_elements - survey elements of an xform return dictionary or None
-
onadata.libs.utils.model_tools.
queryset_iterator
(queryset, chunksize=100)¶ ‘’ Iterate over a Django Queryset.
This method loads a maximum of chunksize (default: 100) rows in its memory at the same time while django normally would load all rows in its memory. Using the iterator() method only causes it to not preload all the classes.
-
onadata.libs.utils.model_tools.
set_uuid
(obj)¶ Only give an object a new UUID if it does not have one.
onadata.libs.utils.mongo module¶
onadata.libs.utils.numeric module¶
-
onadata.libs.utils.numeric.
int_or_parse_error
(value, error_string)¶ If value is not an int raise a parse error with error_string, which is a format string that takes one argument, the value.
onadata.libs.utils.osm module¶
-
onadata.libs.utils.osm.
get_combined_osm
(osm_list)¶ Combine osm xml form list of OsmData objects
-
onadata.libs.utils.osm.
osm_flat_dict
(instance_id)¶
-
onadata.libs.utils.osm.
parse_osm
(osm_xml, include_osm_id=False)¶
-
onadata.libs.utils.osm.
parse_osm_nodes
(osm_xml, include_osm_id=False)¶ Converts an OSM XMl to a list of GEOSGeometry objects
Retrieves all the tags from a osm xml node
-
onadata.libs.utils.osm.
parse_osm_ways
(osm_xml, include_osm_id=False)¶ Converts an OSM XMl to a list of GEOSGeometry objects
-
onadata.libs.utils.osm.
save_osm_data
(instance_id)¶
onadata.libs.utils.profiler module¶
-
onadata.libs.utils.profiler.
profile
(log_file)¶ Profile some callable.
This decorator uses the hotshot profiler to profile some callable (like a view function or method) and dumps the profile data somewhere sensible for later processing and examination.
It takes one argument, the profile log name. If it’s a relative path, it places it under the PROFILE_LOG_BASE. It also inserts a time stamp into the file name, such that ‘my_view.prof’ become ‘my_view-20100211T170321.prof’, where the time stamp is in UTC. This makes it easy to run and compare multiple trials.
onadata.libs.utils.project_utils module¶
-
onadata.libs.utils.project_utils.
set_project_perms_to_xform
(xform, project)¶
onadata.libs.utils.qrcode module¶
-
onadata.libs.utils.qrcode.
generate_qrcode
(message, stream=None, eclevel='M', margin=10, data_mode='8bits', format='PNG', scale=2.5)¶ Generate a QRCode, settings options and output.
onadata.libs.utils.quick_converter module¶
-
class
onadata.libs.utils.quick_converter.
QuickConverter
(data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None)¶ Bases:
django.forms.forms.Form
-
base_fields
= OrderedDict([('xls_file', <django.forms.fields.FileField object at 0x7ffa07819390>)])¶
-
declared_fields
= OrderedDict([('xls_file', <django.forms.fields.FileField object at 0x7ffa07819390>)])¶
-
media
¶
-
publish
(user)¶
-
onadata.libs.utils.timing module¶
-
onadata.libs.utils.timing.
calculate_duration
(start_time, end_time)¶ This function calculates duration when given start and end times. An empty string is returned if either of the time formats does not match ‘_format’ format else, the duration is returned
-
onadata.libs.utils.timing.
get_date
(_object=None)¶
-
onadata.libs.utils.timing.
get_header_date_format
(date_modified)¶
-
onadata.libs.utils.timing.
last_modified_header
(last_modified_date)¶
-
onadata.libs.utils.timing.
merge_dicts
(*args)¶
-
onadata.libs.utils.timing.
print_time
(func)¶ @print_time
Put this decorator around a function to see how many seconds each call of this function takes to run.
onadata.libs.utils.user_auth module¶
-
class
onadata.libs.utils.user_auth.
HttpResponseNotAuthorized
¶ Bases:
django.http.response.HttpResponse
-
status_code
= 401¶
-
-
onadata.libs.utils.user_auth.
add_cors_headers
(response)¶
-
onadata.libs.utils.user_auth.
basic_http_auth
(func)¶
-
onadata.libs.utils.user_auth.
check_and_set_form_by_id
(pk, request)¶
-
onadata.libs.utils.user_auth.
check_and_set_form_by_id_string
(username, id_string, request)¶
-
onadata.libs.utils.user_auth.
check_and_set_user
(request, username)¶
-
onadata.libs.utils.user_auth.
check_and_set_user_and_form
(username, id_string, request)¶
-
onadata.libs.utils.user_auth.
get_user_default_project
(user)¶
-
onadata.libs.utils.user_auth.
get_xform_and_perms
(username, id_string, request)¶
-
onadata.libs.utils.user_auth.
has_edit_permission
(xform, owner, request, shared=False)¶
-
onadata.libs.utils.user_auth.
has_permission
(xform, owner, request, shared=False)¶
-
onadata.libs.utils.user_auth.
helper_auth_helper
(request)¶
-
onadata.libs.utils.user_auth.
http_auth_string
(username, password)¶
-
onadata.libs.utils.user_auth.
set_api_permissions_for_user
(user)¶
-
onadata.libs.utils.user_auth.
set_profile_data
(data, content_user)¶
onadata.libs.utils.viewer_tools module¶
-
exception
onadata.libs.utils.viewer_tools.
EnketoError
¶ Bases:
exceptions.Exception
-
exception
onadata.libs.utils.viewer_tools.
MyError
¶ Bases:
exceptions.Exception
-
onadata.libs.utils.viewer_tools.
create_attachments_zipfile
(attachments)¶
-
onadata.libs.utils.viewer_tools.
django_file
(path, field_name, content_type)¶
-
onadata.libs.utils.viewer_tools.
enketo_url
(form_url, id_string, instance_xml=None, instance_id=None, return_url=None, **kwargs)¶
-
onadata.libs.utils.viewer_tools.
export_def_from_filename
(filename)¶
-
onadata.libs.utils.viewer_tools.
generate_enketo_form_defaults
(xform, **kwargs)¶
-
onadata.libs.utils.viewer_tools.
get_client_ip
(request)¶
-
onadata.libs.utils.viewer_tools.
get_enketo_edit_url
(request, instance, return_url)¶
-
onadata.libs.utils.viewer_tools.
get_enketo_preview_url
(request, username, id_string)¶
-
onadata.libs.utils.viewer_tools.
get_form
(kwargs)¶
-
onadata.libs.utils.viewer_tools.
get_form_url
(request, username=None, protocol='https', preview=False)¶
-
onadata.libs.utils.viewer_tools.
get_path
(path, suffix)¶
-
onadata.libs.utils.viewer_tools.
image_urls
(instance)¶
-
onadata.libs.utils.viewer_tools.
image_urls_for_form
(xform)¶
-
onadata.libs.utils.viewer_tools.
parse_xform_instance
(xml_str)¶ ‘xml_str’ is a str object holding the XML of an XForm instance. Return a python object representation of this XML file.
-
onadata.libs.utils.viewer_tools.
report_exception
(subject, info, exc_info=None)¶