feature_phone.models module

Model definitions.

This module defines how information used by Malasakit is structured and how the Python layer interfaces with a database.

The Question and Response models used in v2.0 are linked to their corresponding quantitative question, qualitative question, and response objects from v1.25 through the RelatedObjectMixin.

References

class feature_phone.models.Instructions(*args, **kwargs)

Bases: feature_phone.models.Recording

An Instruction is a string of text that will be spoken to a caller.

key

str – A unique identifier for this Instruction.

language

str – The language the Instruction is written in.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

MAX_TEXT_DISPLAY_LENGTH = 140
exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

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

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.

recording

The descriptor for the file attribute on the model instance. Returns a FieldFile when accessed so you can do stuff like:

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

Assigns a file object on assignment so you can do:

>>> with open('/path/to/hello.world', 'r') as f:
...     instance.file = File(f)
class feature_phone.models.Question(*args, **kwargs)

Bases: feature_phone.models.Instructions, feature_phone.models.RelatedObjectMixin

A Question is a type of Instruction that is specifically spoken to the caller during the quantitative and qualitative question part of the call.

exception DoesNotExist

Bases: feature_phone.models.DoesNotExist

exception MultipleObjectsReturned

Bases: feature_phone.models.MultipleObjectsReturned

objects = <django.db.models.manager.Manager object>
related_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.

validate_unique(exclude=None)
class feature_phone.models.Recording(*args, **kwargs)

Bases: django.db.models.base.Model

A Recording is an abstract model of a recording

recording

Contains the path to which the recording is stored on disk.

text

str – The text content of the Recording.

class Meta

Bases: pcari.models.ViewMeta

abstract = False
recording

The descriptor for the file attribute on the model instance. Returns a FieldFile when accessed so you can do stuff like:

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

Assigns a file object on assignment so you can do:

>>> with open('/path/to/hello.world', 'r') as f:
...     instance.file = File(f)
class feature_phone.models.RelatedObjectMixin(*args, **kwargs)

Bases: django.db.models.base.Model

The RelatedObjectMixin provides models access to their corresponding linked database objects from PCARI v1.25 models.

To use this mixin on a model, have the model inherit from this class after it inherits from django.db.models.Model (or some subclass of Model). It cannot be inherited on its own, and must be included via multiple inheritance to any v2 model.

related_object_type

The type of the linked v1.25 object.

related_object_id

The id of the linked v1.25 object.

related_object

The linked v1.25 object.

class Meta
abstract = False
related_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.

class feature_phone.models.Respondent(*args, **kwargs)

Bases: django.db.models.base.Model

A Respondent represents a one-time participant in the survey.

call_sid

A unique identifier for the call made by this respondent. Generated by Twilio.

age

The age of the respondent in years.

gender

The gender of the respondent

location

The respondent’s residence. (In the particular context of the Philippines, this field should contain the respondent’s province, city or municipality, and barangay.)

language

The language preferred by this respondent. Selected from pcari.models.LANGUAGES.

related_object

Ties the respondent with the corresponding database object from v1.25

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

age

The descriptor for the file attribute on the model instance. Returns a FieldFile when accessed so you can do stuff like:

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

Assigns a file object on assignment so you can do:

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

The descriptor for the file attribute on the model instance. Returns a FieldFile when accessed so you can do stuff like:

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

Assigns a file object on assignment so you can do:

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

The descriptor for the file attribute on the model instance. Returns a FieldFile when accessed so you can do stuff like:

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

Assigns a file object on assignment so you can do:

>>> with open('/path/to/hello.world', 'r') as f:
...     instance.file = File(f)
objects = <django.db.models.manager.Manager object>
class feature_phone.models.Response(*args, **kwargs)

Bases: feature_phone.models.Recording, feature_phone.models.RelatedObjectMixin

A Response is a Recording of the caller’s answer to the prompted Questions.

timestamp

datetime.datetime – When this Response was made.

respondent

The Respondent who made this Response.

url

str – The voice response’s Twilio URL.

prompt_type

The type of the prompt which this Response addressed.

prompt_id

The ID of the prompt which this Response addressed.

prompt

The prompt which this Response addressed.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

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

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.

recording

The descriptor for the file attribute on the model instance. Returns a FieldFile when accessed so you can do stuff like:

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

Assigns a file object on assignment so you can do:

>>> with open('/path/to/hello.world', 'r') as f:
...     instance.file = File(f)
related_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.

feature_phone.models.generate_recording_path(instance, filename)

Create a path in the file tree to which the recording is stored.

Parameters:
  • instance – A recording object.
  • filename (String) – The filename for the recording.
Returns:

A path, containing a folder and a directory, to which the recording is stored.

Return type:

String