onadata.apps.sms_support package

Subpackages

Submodules

onadata.apps.sms_support.autodoc module

SMS Support Automatic Documentation (Web View)

Provides the get_autodoc_for(xform) function. It is used inside the main.views.show() view to display an HTML documentation about how to fill the SMS for that form.

Output is HTML ; not raw. Output uses only span markup with classes so it should be somewhat easy to restyle

onadata.apps.sms_support.autodoc.get_autodoc_for(xform)

The generated documentation in a dict (HTML output)

line_names: example line filled with question line_names line_values: example line filled with fake (yet valid) data helpers: list of tuples (name, text) of helper texts.

Helper texts are based on type of question and accepted values

onadata.apps.sms_support.autodoc.get_helper_text(question, json_survey)

The full sentence (html) of the helper for a question

Includes the type, a description and potentialy accepted values or format

onadata.apps.sms_support.autodoc.get_sample_data_for(question, json_survey, as_names=False)

return an example data for a particular question.

If as_names is True, returns name (not sms_field) of the question

onadata.apps.sms_support.parser module

SMS parser module - utility functionality to process SMS messages.

exception onadata.apps.sms_support.parser.SMSCastingError(message, question=None)

Bases: ValueError

A custom SMS type casting error exception class.

exception onadata.apps.sms_support.parser.SMSSyntaxError

Bases: ValueError

A custom SMS syntax error exception class.

onadata.apps.sms_support.parser.parse_sms_text(xform, identity, sms_text)

Parses an SMS text to return XForm specific answers, media, notes.

onadata.apps.sms_support.parser.process_incoming_smses(username, incomings, id_string=None)

Process Incoming (identity, text[, id_string]) SMS

onadata.apps.sms_support.tools module

sms_support utility functions module.

onadata.apps.sms_support.tools.check_form_sms_compatibility(form, json_survey=None)

Tests all SMS related rules on the XForm representation

Returns a view-compatible dict(type, text) with warnings or a success message

onadata.apps.sms_support.tools.generate_instance(username, xml_file, media_files, uuid=None)

Process an XForm submission as if done via HTTP

Parameters:
  • xml_file (IO) – file-like object containing XML XForm

  • username (string) – username of the Form’s owner

  • media_files (list) – a list of UploadedFile objects

  • uuid (string) – an optionnal uuid for the instance.

:returns a (status, message) tuple.

onadata.apps.sms_support.tools.get_sms_instance_id(instance)

Human-friendly unique ID of a submission for latter ref/update

For now, we strip down to the first 8 chars of the UUID. Until we figure out what we really want (might as well be used by formhub XML)

onadata.apps.sms_support.tools.is_last(index, items)

Returns True if index is the last index in items.

Whether a form is considered to want sms Support

return True if one sms-related field is defined.

onadata.apps.sms_support.tools.sms_media_to_file(file_object, name)

Returns a file object from an SMS string.

onadata.apps.sms_support.views module

sms_support views.

onadata.apps.sms_support.views.get_response(data)

Returns a JsonResponse object with status, message, instanceID and sendouts based on the input data object.

onadata.apps.sms_support.views.import_multiple_submissions(request, username)

Process several POSTED SMS texts as XForm submissions

Parameters:

messages (json) – JSON list of {“identity”: “x”, “text”: “x”}

Returns json list of {“status”:

“x”, “message”: “x”, “id”: “x”}

onadata.apps.sms_support.views.import_multiple_submissions_for_form(request, username, id_string)

idem import_multiple_submissions with a defined id_string

onadata.apps.sms_support.views.import_submission(request, username)

Process an SMS text as a form submission

Parameters:
  • identity (string) – phone number of the sender

  • text (string) – SMS content

Returns:

a JSON dict with: ‘status’: one of ‘ACCEPTED’, ‘REJECTED’, ‘PARSING_FAILED’ ‘message’: Error message if not ACCEPTED. ‘id: Unique submission ID if ACCEPTED.

onadata.apps.sms_support.views.import_submission_for_form(request, username, id_string)

idem import_submission with a defined id_string

Module contents