Exemplo n.º 1
0
 def _set_preference(self, answer, category_id, question_id, mod_flag):
     prefs = self._get_or_create_preferences()
     if mod_flag == modify_flag['UPDATE']:
         mod_flag = modify_flag['MODIFY']  # preferences use the modify flag instead
     answer.ModifyFlag = mod_flag
     q_category = None
     has_question = False
     for cat in prefs.QuestionCategory:
         if cat.CategoryID == category_id:
             q_category = cat
             for q in cat.QuestionAnswers:
                 if q.QuestionID == question_id:
                     q.add_Answer(answer)
                     has_question = True
                     break
         if q_category:
             break
     # if the question category or question does not exist
     if not has_question:
         if not q_category:
             q_category = CategoryType(CategoryID=category_id)
             prefs.add_QuestionCategory(q_category)
         q_answer = QuestionAnswerType(QuestionID=question_id)
         q_category.add_QuestionAnswers(q_answer)
         q_answer.add_Answer(answer)
Exemplo n.º 2
0
 def add_question_answer(self, question_id, category_id, option_id=None, answer_text=None, mod_flag=modify_flag['MODIFY']):
     obj = self.object
     answer = AnswerType(OptionID=option_id, AnswerText=answer_text, ModifyFlag=mod_flag)
     q_category = None
     has_question = False
     for cat in obj.QuestionCategory:
         if cat.CategoryID == category_id:
             q_category = cat
             for q in cat.QuestionAnswers:
                 if q.QuestionID == question_id:
                     q.add_Answer(answer)
                     has_question = True
                     self.answer_set.add(q)
                     break
         if q_category:
             break
     # if the question category or question does not exist
     if not has_question:
         if not q_category:
             q_category = CategoryType(CategoryID=category_id)
             obj.add_QuestionCategory(q_category)
         q_answer = QuestionAnswerType(QuestionID=question_id)
         q_category.add_QuestionAnswers(q_answer)
         q_answer.add_Answer(answer)
         self.answer_set.add(q_answer)