Exemplo n.º 1
0
    def migrate_survey(self, evaluation, event):
        survey = Survey(event_id=int(event.id))
        if evaluation.title and not evaluation.title.startswith(
                'Evaluation for '):
            survey.title = _sanitize(evaluation.title)
        if not survey.title:
            survey.title = "Evaluation"
        survey.introduction = _sanitize(evaluation.announcement)
        if evaluation.contactInfo:
            contact_text = "Contact: ".format(_sanitize(
                evaluation.contactInfo))
            survey.introduction += "\n\n{}".format(
                contact_text) if survey.introduction else contact_text
        survey.submission_limit = evaluation.submissionsLimit if evaluation.submissionsLimit else None
        survey.anonymous = evaluation.anonymous
        # Require the user to login if the survey is not anonymous or if logging in was required before
        survey.require_user = not survey.anonymous or evaluation.mandatoryAccount

        if evaluation.startDate.date() == date.min or evaluation.endDate.date(
        ) == date.min:
            survey.start_dt = event.endDate
            survey.end_dt = survey.start_dt + timedelta(days=7)
        else:
            survey.start_dt = localize_as_utc(evaluation.startDate, event.tz)
            survey.end_dt = localize_as_utc(evaluation.endDate, event.tz)
        if survey.end_dt < survey.start_dt:
            survey.end_dt = survey.end_dt + timedelta(days=7)

        for kind, notification in evaluation.notifications.iteritems():
            survey.notifications_enabled = True
            recipients = set(notification._toList) | set(notification._ccList)
            if kind == 'evaluationStartNotify':
                survey.start_notification_emails = list(recipients)
            elif kind == 'newSubmissionNotify':
                survey.new_submission_emails = list(recipients)

        self.print_success(cformat('%{cyan}{}%{reset}').format(survey),
                           always=True,
                           event_id=event.id)

        question_map = {}
        section = SurveySection(survey=survey, display_as_section=False)
        for position, old_question in enumerate(evaluation._questions):
            question = self.migrate_question(old_question, position)
            question_map[old_question] = question
            section.children.append(question)

        for old_submission in evaluation._submissions:
            submission = self.migrate_submission(old_submission, question_map,
                                                 event.tz)
            survey.submissions.append(submission)

        return survey
Exemplo n.º 2
0
 def _deserialize(occ):
     try:
         dt = dateutil.parser.parse('{} {}'.format(occ['date'], occ['time']))
     except ValueError:
         raise ValueError('Invalid date/time: {} {}'.format(escape(occ['date']), escape(occ['time'])))
     if occ['duration'] < 1:
         raise ValueError('Invalid duration')
     return localize_as_utc(dt, self.timezone), timedelta(minutes=occ['duration'])
Exemplo n.º 3
0
    def migrate_survey(self, evaluation, event):
        survey = Survey(event_id=int(event.id))
        if evaluation.title and not evaluation.title.startswith('Evaluation for '):
            survey.title = _sanitize(evaluation.title)
        if not survey.title:
            survey.title = "Evaluation"
        survey.introduction = _sanitize(evaluation.announcement)
        if evaluation.contactInfo:
            contact_text = "Contact: ".format(_sanitize(evaluation.contactInfo))
            survey.introduction += "\n\n{}".format(contact_text) if survey.introduction else contact_text
        survey.submission_limit = evaluation.submissionsLimit if evaluation.submissionsLimit else None
        survey.anonymous = evaluation.anonymous
        # Require the user to login if the survey is not anonymous or if logging in was required before
        survey.require_user = not survey.anonymous or evaluation.mandatoryAccount

        if evaluation.startDate.date() == date.min or evaluation.endDate.date() == date.min:
            survey.start_dt = event.endDate
            survey.end_dt = survey.start_dt + timedelta(days=7)
        else:
            survey.start_dt = localize_as_utc(evaluation.startDate, event.tz)
            survey.end_dt = localize_as_utc(evaluation.endDate, event.tz)
        if survey.end_dt < survey.start_dt:
            survey.end_dt = survey.end_dt + timedelta(days=7)

        for kind, notification in evaluation.notifications.iteritems():
            survey.notifications_enabled = True
            recipients = set(notification._toList) | set(notification._ccList)
            if kind == 'evaluationStartNotify':
                survey.start_notification_emails = list(recipients)
            elif kind == 'newSubmissionNotify':
                survey.new_submission_emails = list(recipients)

        self.print_success(cformat('%{cyan}{}%{reset}').format(survey), always=True, event_id=event.id)

        question_map = {}
        section = SurveySection(survey=survey, display_as_section=False)
        for position, old_question in enumerate(evaluation._questions):
            question = self.migrate_question(old_question, position)
            question_map[old_question] = question
            section.children.append(question)

        for old_submission in evaluation._submissions:
            submission = self.migrate_submission(old_submission, question_map, event.tz)
            survey.submissions.append(submission)

        return survey
Exemplo n.º 4
0
 def process_formdata(self, valuelist):
     if any(valuelist):
         if not valuelist[0]:
             self.date_missing = True
         if not valuelist[1]:
             self.time_missing = True
     if valuelist:
         valuelist = [' '.join(valuelist).strip()]
     super(IndicoDateTimeField, self).process_formdata(valuelist)
     if self.data and not self.data.tzinfo:
         self.data = localize_as_utc(self.data, self.timezone)
Exemplo n.º 5
0
 def process_formdata(self, valuelist):
     if any(valuelist):
         if not valuelist[0]:
             self.date_missing = True
         if not valuelist[1]:
             self.time_missing = True
     if valuelist:
         valuelist = [' '.join(valuelist).strip()]
     super(IndicoDateTimeField, self).process_formdata(valuelist)
     if self.data and not self.data.tzinfo:
         self.data = localize_as_utc(self.data, self.timezone)
Exemplo n.º 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
Exemplo n.º 7
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
Exemplo n.º 8
0
 def _deserialize(occ):
     try:
         dt = dateutil.parser.parse('{} {}'.format(occ['date'], occ['time']))
     except ValueError:
         raise ValueError('Invalid date/time: {} {}'.format(escape(occ['date']), escape(occ['time'])))
     return localize_as_utc(dt, self.timezone), timedelta(minutes=occ['duration'])