def display_text(self, channel=USSDAccess.choice_name(), context={}): text = self.text if channel == USSDAccess.choice_name() and self.answer_type == MultiChoiceAnswer.choice_name(): extras = [] # append question options for option in self.options.all().order_by('order'): extras.append(option.to_text) text = '%s\n%s' % (text, '\n'.join(extras)) return Template(text).render(Context(context))
def reload_answer_categories(cls): from survey.models import USSDAccess, ODKAccess, WebAccess cls.objects.get_or_create(channel=USSDAccess.choice_name(), answer_type=AutoResponse.choice_name()) cls.objects.get_or_create(channel=USSDAccess.choice_name(), answer_type=NumericalAnswer.choice_name()) cls.objects.get_or_create(channel=USSDAccess.choice_name(), answer_type=TextAnswer.choice_name()) cls.objects.get_or_create(channel=USSDAccess.choice_name(), answer_type=MultiChoiceAnswer.choice_name()) # ODK definition cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=AutoResponse.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=NumericalAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=TextAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=MultiChoiceAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=MultiSelectAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=ImageAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=GeopointAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=DateAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=AudioAnswer.choice_name()) cls.objects.get_or_create(channel=ODKAccess.choice_name(), answer_type=VideoAnswer.choice_name()) # web form definition cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=NumericalAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=TextAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=MultiChoiceAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=MultiSelectAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=ImageAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=GeopointAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=DateAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=AudioAnswer.choice_name()) cls.objects.get_or_create(channel=WebAccess.choice_name(), answer_type=VideoAnswer.choice_name())
def display_text(self, channel=None): text = self.text if channel and channel== USSDAccess.choice_name() and self.answer_type == MultiChoiceAnswer.choice_name(): extras = [] #append question options for option in self.options.all().order_by('order'): extras.append(option.to_text) text = '%s\n%s' % (text, '\n'.join(extras)) return text
def respond(self, reply=None, channel=ODKAccess.choice_name()): """ Respond to given reply for specified channel. This method is volatile.Raises exception if some error happens in the process :param reply: :param channel: :return: Returns next question if any """ if self.is_closed(): return if self.last_question and reply is None: return self.householdmember.get_composed(self.last_question.display_text(USSDAccess.choice_name())) next_question = None if self.has_started: # save reply answer_class = Answer.get_class(self.last_question.answer_type) answer_class.create(self, self.last_question, reply) # compute nnext next_question = self.last_question.next_question(reply) else: next_question = self.batch.start_question # now confirm the question is applicable if ( next_question and ( self.householdmember.belongs_to(next_question.group) and AnswerAccessDefinition.is_valid(channel, next_question.answer_type) ) is False ): next_question = self.batch.next_inline( self.last_question, groups=self.householdmember.groups, channel=channel ) # if not get next line question response_text = None if next_question: self.last_question = next_question response_text = self.householdmember.get_composed(next_question.display_text(USSDAccess.choice_name())) else: print "interview batch ", self.batch.name # if self.batch.name == 'Test5': # import pdb; pdb.set_trace() # no more questions to ask. capture this time as closure self.closure_date = datetime.now() self.save() return response_text
def respond(self, reply=None, channel=ODKAccess.choice_name()): ''' Respond to given reply for specified channel. This method is volatile.Raises exception if some error happens in the process :param reply: :param channel: :return: Returns next question if any ''' if self.is_closed(): return if self.last_question and reply is None: return self.householdmember.get_composed(self.last_question.display_text(USSDAccess.choice_name())) next_question = None if self.has_started: #save reply answer_class = Answer.get_class(self.last_question.answer_type) answer_class.create(self, self.last_question, reply) #compute nnext next_question = self.last_question.next_question(reply) else: next_question = self.batch.start_question #now confirm the question is applicable if next_question and (self.householdmember.belongs_to(next_question.group) \ and AnswerAccessDefinition.is_valid(channel, next_question.answer_type)) is False: next_question = self.batch.next_inline(self.last_question, groups=self.householdmember.groups, channel=channel) #if not get next line question response_text = None if next_question: self.last_question = next_question response_text = self.householdmember.get_composed(next_question.display_text(USSDAccess.choice_name())) else: print 'interview batch ', self.batch.name # if self.batch.name == 'Test5': # import pdb; pdb.set_trace() #no more questions to ask. capture this time as closure self.closure_date = datetime.now() self.save() return response_text