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
def migrate_survey(self, evaluation): survey = Survey(event_new=self.event) title = convert_to_unicode(evaluation.title) if title and not title.startswith('Evaluation for '): survey.title = sanitize_user_input(title) if not survey.title: survey.title = "Evaluation" survey.introduction = sanitize_user_input(evaluation.announcement) if evaluation.contactInfo: contact_text = "Contact: ".format( sanitize_user_input(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 = self.event.end_dt survey.end_dt = survey.start_dt + timedelta(days=7) else: survey.start_dt = self._naive_to_aware(evaluation.startDate) survey.end_dt = self._naive_to_aware(evaluation.endDate) 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('%[cyan]{}%[reset]'.format(survey)) 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 i, old_submission in enumerate(evaluation._submissions, 1): submission = self.migrate_submission(old_submission, question_map, i) survey.submissions.append(submission) survey._last_friendly_submission_id = len(survey.submissions) return survey
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