Exemplo n.º 1
0
 def _get_group_next_question(question, proposed_next):
     next_question = proposed_next
     present_question_group = question.group if hasattr(question, 'group') else None
     if next_question and AnswerAccessDefinition.is_valid(access.choice_name(),
                                                          next_question.answer_type) is False:
         next_question = _get_group_next_question(question, next_question.next_question(reply))
     # I hope the next line is not so confusing!
     # Basically it means treat only if the next question belongs to a different group from the present.
     # That's if present has a group
     if hasattr(next_question, 'group') and present_question_group != next_question.group:
         question_group = next_question.group
         if question_group:
             qset = QuestionSet.get(pk=next_question.qset.pk)
             valid_group = True
             for condition in question_group.group_conditions.all():
                 # we are interested in the qset param list with same identifier name as condition.test_question
                 test_question = qset.parameter_list.questions.get(identifier=condition.test_question.identifier)
                 param_value = ''            # use answer.as value
                 if session_data[ANSWERS][-1].get(test_question.identifier, None):    # last answer entry
                     param_value = session_data[ANSWERS][-1][test_question.identifier]
                 answer_class = Answer.get_class(condition.test_question.answer_type)
                 validator = getattr(answer_class, condition.validation_test, None)
                 if validator is None:
                     raise ValueError('unsupported validator defined on listing question')
                 try:
                     slogger.debug('parm val: %s, params: %s' % (param_value, condition.test_params))
                     is_valid = validator(param_value, *condition.test_params)
                 except:
                     is_valid = True
                 if is_valid is False:
                     valid_group = False
                     break   # fail if any condition fails
             if valid_group is False:
                 next_question = _get_group_next_question(question, next_question.next_question(reply))
     return next_question
Exemplo n.º 2
0
 def _get_group_next_question(question, proposed_next):
     next_question = proposed_next
     present_question_group = question.group if hasattr(
         question, 'group') else None
     if next_question and AnswerAccessDefinition.is_valid(
             access.choice_name(), next_question.answer_type) is False:
         next_question = _get_group_next_question(
             question, next_question.next_question(reply))
     # I hope the next line is not so confusing!
     # Basically it means treat only if the next question belongs to a different group from the present.
     # That's if present has a group
     if hasattr(
             next_question,
             'group') and present_question_group != next_question.group:
         question_group = next_question.group
         if question_group:
             qset = QuestionSet.get(pk=next_question.qset.pk)
             valid_group = True
             for condition in question_group.group_conditions.all():
                 # we are interested in the qset param list with same identifier name as condition.test_question
                 test_question = qset.parameter_list.questions.get(
                     identifier=condition.test_question.identifier)
                 param_value = ''  # use answer.as value
                 if session_data[ANSWERS][-1].get(
                         test_question.identifier,
                         None):  # last answer entry
                     param_value = session_data[ANSWERS][-1][
                         test_question.identifier]
                 answer_class = Answer.get_class(
                     condition.test_question.answer_type)
                 validator = getattr(answer_class,
                                     condition.validation_test, None)
                 if validator is None:
                     raise ValueError(
                         'unsupported validator defined on listing question'
                     )
                 try:
                     slogger.debug('parm val: %s, params: %s' %
                                   (param_value, condition.test_params))
                     is_valid = validator(param_value,
                                          *condition.test_params)
                 except:
                     is_valid = True
                 if is_valid is False:
                     valid_group = False
                     break  # fail if any condition fails
             if valid_group is False:
                 next_question = _get_group_next_question(
                     question, next_question.next_question(reply))
     return next_question