Пример #1
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
Пример #2
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
Пример #3
0
 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
Пример #4
0
def was_survey_submitted(survey):
    """Check whether the current user has submitted a survey"""
    if session.user and session.user.survey_submissions.filter_by(survey=survey).count():
        return True
    submission_id = session.get("submitted_surveys", {}).get(survey.id)
    if submission_id is None:
        return False
    return bool(SurveySubmission.find(id=submission_id).count())
Пример #5
0
def was_survey_submitted(survey):
    """Check whether the current user has submitted a survey"""
    if session.user and session.user.survey_submissions.filter_by(survey=survey).count():
        return True
    submission_id = session.get('submitted_surveys', {}).get(survey.id)
    if submission_id is None:
        return False
    return bool(SurveySubmission.find(id=submission_id).count())
Пример #6
0
 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
Пример #7
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
Пример #8
0
 def _process_args(self):
     RHManageSurveysBase._process_args(self)
     survey_strategy = joinedload('survey')
     answers_strategy = defaultload('answers').joinedload('question')
     sections_strategy = joinedload('survey').defaultload(
         'sections').joinedload('children')
     self.submission = (SurveySubmission.find(
         id=request.view_args['submission_id']).options(
             answers_strategy, survey_strategy, sections_strategy).one())
Пример #9
0
 def _process(self):
     pending_answers = {
         k: v
         for k, v in request.form.lists() if k.startswith('question_')
     }
     if not self.submission:
         self.submission = SurveySubmission(survey=self.survey,
                                            user=session.user)
     self.submission.pending_answers = pending_answers
     self.submission.is_anonymous = self.survey.anonymous
Пример #10
0
def was_survey_submitted(survey):
    """Check whether the current user has submitted a survey"""
    from indico.modules.events.surveys.models.surveys import Survey
    query = (Survey.query.with_parent(survey.event)
             .filter(Survey.submissions.any(db.and_(SurveySubmission.is_submitted,
                                                    SurveySubmission.user == session.user))))
    user_submitted_surveys = set(query)
    if session.user and survey in user_submitted_surveys:
        return True
    submission_id = session.get('submitted_surveys', {}).get(survey.id)
    if submission_id is None:
        return False
    return SurveySubmission.find(id=submission_id, is_submitted=True).has_rows()
Пример #11
0
    def migrate_submission(self, old_submission, question_map, friendly_id):
        submitter = old_submission._submitter
        if not old_submission.anonymous and submitter is not None:
            user = self.global_ns.avatar_merged_user[submitter.id]
        else:
            user = None

        submission = SurveySubmission(is_submitted=True,
                                      is_anonymous=(user is None),
                                      user=user,
                                      friendly_id=friendly_id)
        submitted_dt = old_submission.submissionDate
        submission.submitted_dt = submitted_dt if submitted_dt.tzinfo else self._naive_to_aware(
            submitted_dt)
        self.print_success(" - Submission from user {}".format(submission.user
                                                               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
Пример #12
0
def was_survey_submitted(survey):
    """Check whether the current user has submitted a survey"""
    from indico.modules.events.surveys.models.surveys import Survey
    query = (Survey.query.with_parent(survey.event)
             .filter(Survey.submissions.any(db.and_(SurveySubmission.is_submitted,
                                                    SurveySubmission.user == session.user))))
    user_submitted_surveys = set(query)
    if session.user and survey in user_submitted_surveys:
        return True
    submission_id = session.get('submitted_surveys', {}).get(survey.id)
    if submission_id is None:
        return False
    return SurveySubmission.find(id=submission_id, is_submitted=True).has_rows()
Пример #13
0
def _merge_users(target, source, **kwargs):
    from indico.modules.events.surveys.models.submissions import SurveySubmission
    SurveySubmission.find(user_id=source.id).update(
        {SurveySubmission.user_id: target.id})
Пример #14
0
def _filter_submissions(survey, submission_ids):
    if submission_ids:
        return SurveySubmission.find_all(
            SurveySubmission.id.in_(submission_ids), survey=survey)
    return [x for x in survey.submissions if x.is_submitted]
Пример #15
0
def _filter_submissions(survey, submission_ids):
    if submission_ids:
        return SurveySubmission.find_all(
            SurveySubmission.id.in_(submission_ids), survey=survey)
    return survey.submissions
Пример #16
0
def _filter_submissions(survey, submission_ids):
    if submission_ids:
        return SurveySubmission.find_all(SurveySubmission.id.in_(submission_ids), survey=survey)
    return survey.submissions
Пример #17
0
def _merge_users(target, source, **kwargs):
    from indico.modules.events.surveys.models.submissions import SurveySubmission
    SurveySubmission.find(user_id=source.id).update({SurveySubmission.user_id: target.id})
Пример #18
0
def _filter_submissions(survey, submission_ids):
    if submission_ids:
        return SurveySubmission.find_all(SurveySubmission.id.in_(submission_ids), survey=survey)
    return [x for x in survey.submissions if x.is_submitted]