feature_phone.views module¶
This module defines the application’s views, which are needed to render pages.
“Pages” are generated in TwiML (Twilio Markup Language) for Twilio to play desired audio.
See https://www.twilio.com/docs/api/twiml and https://twilio.github.io/twilio-python/6.5.0/twiml/
-
class
feature_phone.views.CommentRatingInstructions(**kwargs)¶ Bases:
feature_phone.views.PromptViewExplain the peer evaluation section, and select the suggestions to be presented.
-
accept_keypress= True¶
-
accept_speech= False¶
-
post(request)¶ Serve the Twilio client directions for collecting input.
-
prompts= ['comment-rating-instructions']¶
-
submit_view= 'feature-phone:prompt-comment'¶
-
timeout= 0¶
-
-
class
feature_phone.views.PromptAgeView(**kwargs)¶ Bases:
feature_phone.views.PromptViewAsk listeners for their age.
-
accept_keypress= False¶
-
accept_speech= True¶
-
prompts= ['age-prompt']¶
-
recording_callback= 'feature-phone:download-age'¶
-
submit_view= 'feature-phone:prompt-barangay'¶
-
-
class
feature_phone.views.PromptBarangayView(**kwargs)¶ Bases:
feature_phone.views.PromptViewAsk listeners for their barangay.
-
accept_keypress= False¶
-
accept_speech= True¶
-
prompts= ['barangay-prompt']¶
-
recording_callback= 'feature-phone:download-barangay'¶
-
submit_view= 'feature-phone:quantitative-question-instructions'¶
-
-
class
feature_phone.views.PromptCommentView(**kwargs)¶ Bases:
feature_phone.views.PromptViewPlay back a suggestion to the listener.
-
accept_keypress= True¶
-
accept_speech= True¶
-
ask(request, action)¶
-
post(request)¶ Serve the Twilio client directions for collecting input.
-
recording_callback= 'feature-phone:download-recording'¶
-
recording_max_duration= 15¶
-
submit_view= 'feature-phone:save-comment-rating'¶
-
-
class
feature_phone.views.PromptGenderView(**kwargs)¶ Bases:
feature_phone.views.PromptViewAsk listeners for their gender.
-
accept_keypress= True¶
-
accept_speech= False¶
-
prompts= ['gender-prompt']¶
-
submit_view= 'feature-phone:save-gender'¶
-
-
class
feature_phone.views.PromptIRBNoticeView(**kwargs)¶ Bases:
feature_phone.views.PromptViewPresent an IRB notice to listeners, and allow them to opt-out.
-
accept_keypress= True¶
-
accept_speech= False¶
-
post(request)¶ Serve the Twilio client directions for collecting input.
-
prompts= ['welcome', 'introduction', 'irb-notice', 'irb-notice-prompt']¶
-
submit_view= 'feature-phone:verify-irb-notice'¶
-
-
class
feature_phone.views.PromptQuantitativeQuestionView(**kwargs)¶ Bases:
feature_phone.views.PromptViewAsk a quantitative question.
-
accept_keypress= True¶
-
accept_speech= True¶
-
ask(request, action)¶
-
post(request)¶ Serve the Twilio client directions for collecting input.
-
recording_callback= 'feature-phone:download-recording'¶
-
recording_max_duration= 15¶
-
submit_view= 'feature-phone:save-quantitative-rating'¶
-
-
class
feature_phone.views.PromptView(**kwargs)¶ Bases:
django.views.generic.base.ViewPresent a question to the listener, and gather any desired inputs.
-
submit_view¶ str – The name of the view the Twilio client yields control to after this prompt. Any data recorded arrives as POST parameters Digits or RecordingUrl.
-
prompts¶ list – A list of keys of instructions to read.
-
accept_keypress¶ bool – A flag that determines whether this view should accept a single keypress as input.
-
timeout¶ float – The maximum amount of time in seconds the Twilio client will wait for without input from the listener before moving to
submit_view.
-
accept_speech¶ bool – A flag that determines whether this view should accept spoken recordings as input.
-
play_beep¶ bool – A flag that determines whether the Twilio client should play a beep tone to signal the start of a recording period.
-
recording_max_duration¶ float – The maximum amount of time a recording may take.
-
recording_callback¶ str – The name of the view that will handle actions made after Twilio finalizes the recording.
Note
Keypresses made while a prompt plays will interrupt the playback, while speech will not. Only speech made after the prompt plays will be recorded.
-
accept_keypress= True
-
accept_speech= False
-
ask(request, action)¶
-
dispatch(*args, **kwargs)¶
-
fallback(voice_response)¶
-
http_method_names= ['post']¶
-
play_beep= True
-
post(request)¶ Serve the Twilio client directions for collecting input.
-
prompts= []
-
recording_callback= None
-
recording_max_duration= 60
-
submit_view= None
-
timeout= 4
-
-
class
feature_phone.views.QualitativeQuestionInstructionsView(**kwargs)¶ Bases:
feature_phone.views.PromptViewRead the qualitative question to the participant.
-
accept_keypress= True¶
-
accept_speech= True¶
-
prompts= ['qualitative-question-instructions']¶
-
recording_callback= 'feature-phone:download-recording'¶
-
submit_view= 'feature-phone:save-comment'¶
-
-
class
feature_phone.views.QuantiativeQuestionInstructionsView(**kwargs)¶ Bases:
feature_phone.views.PromptViewExplain the quantitative question section, and initialize session data.
-
accept_keypress= True¶
-
accept_speech= False¶
-
ask(request, action)¶
-
prompts= ['quantitative-question-instructions', 'quantitative-question-reminder']¶
-
submit_view= 'feature-phone:prompt-quantitative-question'¶
-
timeout= 0¶
-
-
class
feature_phone.views.SaveCommentRatingView(**kwargs)¶ Bases:
feature_phone.views.SaveViewRecording a rating of a suggestion.
-
next_view= 'feature-phone:prompt-comment'¶
-
post(request)¶ Handle incoming input.
-
save(request, voice_response)¶
-
-
class
feature_phone.views.SaveCommentView(**kwargs)¶ Bases:
feature_phone.views.SaveViewHandle responses to the participant’s comment.
-
next_view= 'feature-phone:end'¶
-
post(request)¶ Handle incoming input.
-
-
class
feature_phone.views.SaveGenderView(**kwargs)¶ Bases:
feature_phone.views.SaveViewSave responses to the gender question.
-
key_to_gender= {'1': 'M', '2': 'F'}¶
-
next_view= 'feature-phone:prompt-age'¶
-
save(request, voice_response)¶
-
-
class
feature_phone.views.SaveQuantitativeRatingView(**kwargs)¶ Bases:
feature_phone.views.SaveViewRecord a rating to a quantitative question.
-
next_view= 'feature-phone:prompt-quantitative-question'¶
-
post(request)¶ Handle incoming input.
-
save(request, voice_response)¶
-
-
class
feature_phone.views.SaveView(**kwargs)¶ Bases:
django.views.generic.base.ViewProcess incoming data, then redirect the listener to another view.
-
dispatch(*args, **kwargs)¶
-
http_method_names= ['post']¶
-
next_view= None¶
-
post(request)¶ Handle incoming input.
-
save(request, voice_response)¶
-
-
class
feature_phone.views.VerifyIRBNoticeView(**kwargs)¶ Bases:
feature_phone.views.SaveViewHang up if the listener does not accept the IRB, or continue otherwise.
-
accept_irb_key= '1'¶
-
next_view= 'feature-phone:prompt-gender'¶
-
post(request)¶ Handle incoming input.
-
-
feature_phone.views.download_age_recording(*args, **kwargs)¶ Download recordings of listeners stating their ages.
-
feature_phone.views.download_barangay_recording(*args, **kwargs)¶ Download recordings of listeners stating their barangays.
-
feature_phone.views.download_recording(*args, **kwargs)¶ Download a recording for a Response instance, which must have had its URL set.
-
feature_phone.views.end(*args, **kwargs)¶ Clean up local session data, thank the listener, and hang up.
-
feature_phone.views.error(*args, **kwargs)¶ Read an error message to a listener, and gracefully exit.
This should never happen. Uses a minimal Say verb to avoid points of failure.
-
feature_phone.views.fetch_question_pks(question_type, include_orphans=False)¶ Fetch all primary keys (in order) of a given question type.
Parameters: - question_type – A ContentType instance of the question model.
- include_orphans (bool) – A flag that indicates whether the query should return feature phone-only questions.
-
feature_phone.views.fetch_recording(file_field, url)¶ Download a recording from the given URL as a file field value.
-
feature_phone.views.get_respondent(session, pk_key='respondent-pk')¶
-
feature_phone.views.make_response(respondent, prompt, related_object)¶ Make a feature phone response.
-
feature_phone.views.play_recording(action, recording)¶ Play a voice recording, either from a file or using speech synthesis.
Parameters: - action – A Twilio object that supports Say and Play verbs.
- recording – A Recording instance.
-
feature_phone.views.select_comment_pks(num_to_select=2)¶ Select comments to play to a listener.
-
feature_phone.views.speak(action, instruction_keys, pause_duration=0)¶ Play a list of instructions.
Parameters: - action – A Twilio object that supports Say, Play, and Pause verbs.
- instruction_keys (list) – A list of instruction keys.
- pause_duration (float) – The delay between instructions in seconds.
Note
To minimize possibly unwanted latency, a pause does not follow the last instruction spoken.
-
feature_phone.views.transcribe_rating(response, text='')¶ Transcribe a keypress to its related web-facing model.