Esempio n. 1
0
 def migrate_answer(self, old_answer, question):
     answer = SurveyAnswer()
     if old_answer.__class__.__name__ == 'MultipleChoicesAnswer':
         answer.data = []
         for option in old_answer._selectedChoiceItems:
             answer.data.append(self._get_option_id(question, option))
     elif old_answer._question.__class__.__name__ in ('Radio', 'Select'):
         if old_answer._answerValue:
             answer.data = self._get_option_id(question, old_answer._answerValue)
     else:
         answer.data = _sanitize(old_answer._answerValue)
     self.print_success("   - Answer: {}".format(answer.data))
     return answer
Esempio n. 2
0
 def migrate_answer(self, old_answer, question):
     answer = SurveyAnswer()
     if old_answer.__class__.__name__ == 'MultipleChoicesAnswer':
         answer.data = []
         for option in old_answer._selectedChoiceItems:
             answer.data.append(self._get_option_id(question, option))
     elif old_answer._question.__class__.__name__ in ('Radio', 'Select'):
         if old_answer._answerValue:
             answer.data = self._get_option_id(question,
                                               old_answer._answerValue)
     else:
         answer.data = _sanitize(old_answer._answerValue)
     self.print_success("   - Answer: {}".format(answer.data))
     return answer
Esempio n. 3
0
 def _save_answers(self, form):
     survey = self.survey
     if not self.submission:
         self.submission = SurveySubmission(survey=survey, user=session.user)
     self.submission.is_anonymous = survey.anonymous
     for question in survey.questions:
         answer = SurveyAnswer(question=question, data=getattr(form, 'question_{}'.format(question.id)).data)
         self.submission.answers.append(answer)
     return self.submission
Esempio n. 4
0
 def _save_answers(self, form):
     survey = self.survey
     submission = SurveySubmission(survey=survey)
     if not survey.anonymous:
         submission.user = session.user
     for question in survey.questions:
         answer = SurveyAnswer(question=question, data=getattr(form, 'question_{}'.format(question.id)).data)
         submission.answers.append(answer)
     db.session.flush()
     return submission