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 next_inline(self, question, groups=ALL_GROUPS, channel=ODKAccess.choice_name(), exclude_groups=[]): qflows = QuestionFlow.objects.filter(question__batch=self, validation_test__isnull=True) if qflows.exists(): return next_inline_question( question, qflows, groups, AnswerAccessDefinition.answer_types(channel), exclude_groups)
def next_inline(self, question, channel=ODKAccess.choice_name()): @cached_as( QuestionSet.objects.get( id=self.id), QuestionLoop.objects.filter( loop_starter__qset__id=self.id), Question.objects.filter( qset__id=self.id), self.inline_flows()) def _next_inline(): qflows = self.inline_flows() if qflows.exists(): return next_inline_question( question, qflows, AnswerAccessDefinition.answer_types(channel)) return _next_inline()
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(), answers_context={}): """ Respond to given reply for specified channel. Irrespective to group. Might be depreciating group in the near future 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 is None or (self.last_question and reply is None): self.last_question = self.question_set.start_question self.save() return self.last_question.display_text(channel=channel, context=answers_context) 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.question_set.start_question # now confirm the question is applicable if next_question and AnswerAccessDefinition.is_valid( channel, next_question.answer_type) is False: # if not get next line question next_question = self.question_set.next_inline(self.last_question, channel=channel) response_text = None if next_question: self.last_question = next_question response_text = self.last_question.display_text( channel=channel, context=answers_context) else: self.closure_date = timezone.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
def respond(self, reply=None, channel=ODKAccess.choice_name(), answers_context={}): """ Respond to given reply for specified channel. Irrespective to group. Might be depreciating group in the near future 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 is None or (self.last_question and reply is None): self.last_question = self.question_set.start_question self.save() return self.last_question.display_text(channel=channel, context=answers_context) 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.question_set.start_question # now confirm the question is applicable if next_question and AnswerAccessDefinition.is_valid(channel, next_question.answer_type) is False: # if not get next line question next_question = self.question_set.next_inline(self.last_question, channel=channel) response_text = None if next_question: self.last_question = next_question response_text = self.last_question.display_text(channel=channel, context=answers_context) else: self.closure_date = timezone.now() self.save() return response_text
def next_inline(self, question, groups=ALL_GROUPS, channel=ODKAccess.choice_name(), exclude_groups=[]): qflows = QuestionFlow.objects.filter(question__batch=self, validation_test__isnull=True) if qflows.exists(): return next_inline_question(question, qflows, groups, AnswerAccessDefinition.answer_types(channel), exclude_groups)