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
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
def migrate_submission(self, old_submission, question_map, timezone): submission = SurveySubmission() submitted_dt = old_submission.submissionDate submission.submitted_dt = submitted_dt if submitted_dt.tzinfo else localize_as_utc(submitted_dt, timezone) if not old_submission.anonymous and old_submission._submitter: avatar = old_submission._submitter with db.session.no_autoflush: submission.user = User.get(int(avatar.id)) self.print_success(" - Submission from user {}".format(submission.user_id or 'anonymous')) for old_answer in old_submission._answers: question = question_map[old_answer._question] answer = self.migrate_answer(old_answer, question) submission.answers.append(answer) question.answers.append(answer) return submission
def migrate_submission(self, old_submission, question_map, timezone): submission = SurveySubmission() submitted_dt = old_submission.submissionDate submission.submitted_dt = submitted_dt if submitted_dt.tzinfo else localize_as_utc( submitted_dt, timezone) if not old_submission.anonymous and old_submission._submitter: avatar = old_submission._submitter with db.session.no_autoflush: submission.user = User.get(int(avatar.id)) self.print_success(" - Submission from user {}".format( submission.user_id or 'anonymous')) for old_answer in old_submission._answers: question = question_map[old_answer._question] answer = self.migrate_answer(old_answer, question) submission.answers.append(answer) question.answers.append(answer) return submission