pcari.models module

Model definitions.

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

The core of the database consists of concrete models derived from the abstract Question and Response models. Generally speaking, there is a one-to-one correspondence between a type of question and its associated response.

References

pcari.models.LANGUAGE_VALIDATOR

A compiled regular expression that matches language codes specified in settings (for instance, “en”). This regular expression also matches a blank string, which indicates no language.

class pcari.models.Comment(*args, **kwargs)

Bases: pcari.models.Response

A Comment is an open-ended text response to a QualitativeQuestion.

MAX_MESSAGE_DISPLAY_LENGTH

int – The maximum number of characters in the message to display in this comment’s string representation.

question

The question this comment answers.

language

str – A language code.

message

str – The comment’s contents itself written in language.

flagged

bool – Whether this comment was flagged for further inspection. A flagged comment will not show up to other respondents.

tag

str – A short summary of this comment’s message.

original

If this comment is a translation, this field references the original comment.

word_count

int – The number of words in the message. (Words are delimited with contiguous whitespace.)

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

MAX_MESSAGE_DISPLAY_LENGTH = 140
exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

objects = <pcari.models.RatingStatisticsManager object>
class pcari.models.QuantitativeQuestionRating(*args, **kwargs)

Bases: pcari.models.Rating

A QuantitativeQuestionRating rates a QuantitativeQuestion. A respondent can only rate a quantitative question once.

question

The quantitative question rated.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

clean()

Validates the score falls between question.min_score and question.max_score.

Raises:ValidationError – if the score is not legal.
objects = <django.db.models.manager.Manager object>
class pcari.models.CommentRating(*args, **kwargs)

Bases: pcari.models.Rating

A CommentRating rates a Comment. A respondent can only rate a comment once.

comment

The comment rated.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

objects = <django.db.models.manager.Manager object>
class pcari.models.QualitativeQuestion(*args, **kwargs)

Bases: pcari.models.Question

A QualitativeQuestion is a question that asks for a Comment.

input_type

str – What interface to use for collecting qualitative question responses.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

input_type = u'textarea'
objects = <django.db.models.manager.Manager object>
class pcari.models.QuantitativeQuestion(*args, **kwargs)

Bases: pcari.models.Question

A QuantitativeQuestion is a question that asks for a number.

INPUT_TYPE_CHOICES

tuple – Input type choices, each of which is a two-element tuple consisting of the shorthand and the name of an input type. Current options are: * range: Render the question as a “slider”. * number: Render the question as a number-only text field.

left_anchor

str – The text that describes the minimum score. For a range input_type, this text is rendered on the left end of the slider.

right_anchor

str – The text that describes the maximum score. For a range input_type, this text is rendered on the right end of the slider.

min_score

int – The smallest possible score for this question. A value of None is treated as negative infinity (that is, no lower bound).

max_score

int – The largest possible score for this question. A value of None is treated as positive infinity (that is, no upper bound).

input_type

str – How the input should be rendered.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

INPUT_TYPE_CHOICES = ((u'range', u'Slider'), (u'number', u'Numeric text'), (u'buttons', u'Buttons'))
exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

objects = <pcari.models.RatingStatisticsManager object>
class pcari.models.Respondent(*args, **kwargs)

Bases: django.db.models.base.Model

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

GENDERS

tuple – Choices for the gender field. Each gender is a pair of strings, of which the second entry is the gender’s full name and the first is a single-letter abbreviation.

age

int – The age of the respondent in years.

gender

str – The gender of the respondent, as selected from GENDERS (an abbreviation).

location

str – An open text field that describes 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

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

num_questions_rated

int – The number of quantitative questions answered by this respondent. From this number, one can infer whether this respondent reached the rating stage of the survey. This excludes questions the respondent skipped or otherwise did not rate.

num_comments_rated

int – The number of comments reviewed by this respondent. Similarly, one can infer user progression from this attribute. This excludes comments the respondent did not rate.

comments

A Django QuerySet of all comments attached to this respondent.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

GENDERS = ((u'', u'(Empty)'), (u'M', u'Male'), (u'F', u'Female'))
exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

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

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.

class pcari.models.OptionQuestion(*args, **kwargs)

Bases: pcari.models.Question

An OptionQuestion is a question that asks the respondent to select one element from a set of unordered choices.

INPUT_TYPE_CHOICES

tuple – Input type choices, each of which is a two-element tuple consisting of the shorthand and the name of an input type. Current options are: * select: Render the question as a dropdown menu. * radio: Render the question as a list of radio buttons.

_options_text

str – A JSON list of options. This field should only be used internally by this model.

options

list of str – A wrapper around _options_text that automatically serializes and unserializes a Python list of options. This is the preferred way of manipulating the list of options.

input_type

str – How the input should be rendered.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

INPUT_TYPE_CHOICES = ((u'select', u'Dropdown'), (u'radio', u'Multiple choice'))
exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

clean_fields(exclude=None)
objects = <django.db.models.manager.Manager object>
class pcari.models.OptionQuestionChoice(*args, **kwargs)

Bases: pcari.models.Response

An OptionQuestionChoice is a response to an OptionQuestion.

question

The question answered.

option

str – The option selected by the respondent. This must be an element of question.options.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

clean()

Validates the value of option.

Raises:ValidationError – if option is not an element of question.options.
objects = <django.db.models.manager.Manager object>
class pcari.models.Location(*args, **kwargs)

Bases: django.db.models.base.Model

A Location represents a named government-designated area in the world.

country

str – The name of the country of the location.

province

str – The name of the province (in the United States, this would be analogous to a state).

municipality

str – The name of a municipality (can vary from a county to a city or town).

division

str – The name of the smallest possible administrative unit (roughly analogous to a precinct, ward, etc).

enabled

bool – Indicates whether this location should be presented to users as a possible input.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

objects = <django.db.models.manager.Manager object>
pcari.models.get_concrete_fields(model)
pcari.models.get_direct_fields(model)