예제 #1
0
 def send_submission_notification(self, submission):
     if not self.notifications_enabled:
         return
     template_module = get_template_module("events/surveys/emails/new_submission_email.txt", submission=submission)
     email = make_email(bcc_list=self.new_submission_emails, template=template_module)
     send_email(email, event=self.event, module="Surveys")
     logger.info("Sending submission notification for survey {}".format(self))
예제 #2
0
파일: surveys.py 프로젝트: OmeGak/indico
 def send_submission_notification(self, submission):
     if not self.notifications_enabled:
         return
     template_module = get_template_module('events/surveys/emails/new_submission_email.txt', submission=submission)
     email = make_email(bcc_list=self.new_submission_emails, template=template_module)
     send_email(email, event=self.event_new, module='Surveys')
     logger.info('Sending submission notification for survey %s', self)
예제 #3
0
파일: surveys.py 프로젝트: OmeGak/indico
 def send_start_notification(self):
     if not self.notifications_enabled or self.start_notification_sent or not self.event_new.has_feature('surveys'):
         return
     template_module = get_template_module('events/surveys/emails/start_notification_email.txt', survey=self)
     email = make_email(bcc_list=self.start_notification_recipients, template=template_module)
     send_email(email, event=self.event_new, module='Surveys')
     logger.info('Sending start notification for survey %s', self)
     self.start_notification_sent = True
예제 #4
0
 def send_start_notification(self):
     if not self.notifications_enabled or self.start_notification_sent or not self.event.has_feature("surveys"):
         return
     template_module = get_template_module("events/surveys/emails/start_notification_email.txt", survey=self)
     email = make_email(bcc_list=self.start_notification_recipients, template=template_module)
     send_email(email, event=self.event, module="Surveys")
     logger.info("Sending start notification for survey {}".format(self))
     self.start_notification_sent = True
예제 #5
0
 def _process(self):
     form = TextForm(obj=FormDefaults(self.text))
     if form.validate_on_submit():
         form.populate_obj(self.text)
         db.session.flush()
         flash(_('Text item updated'), 'success')
         logger.info('Survey text item {} modified by {}'.format(self.text, session.user))
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('events/surveys/management/edit_survey_item.html', form=form)
예제 #6
0
 def _process(self):
     form = TextForm(obj=FormDefaults(self.text))
     if form.validate_on_submit():
         form.populate_obj(self.text)
         db.session.flush()
         flash(_('Text item updated'), 'success')
         logger.info('Survey text item %s modified by %s', self.text, session.user)
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('forms/form_common_fields_first.html', form=form)
예제 #7
0
 def _process(self):
     form = self.question.field.config_form(obj=FormDefaults(self.question, **self.question.field_data))
     if form.validate_on_submit():
         old_title = self.question.title
         self.question.field.save_config(form)
         db.session.flush()
         flash(_('Question "{title}" updated').format(title=old_title), 'success')
         logger.info('Survey question {} modified by {}'.format(self.question, session.user))
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('events/surveys/management/edit_survey_item.html', form=form)
예제 #8
0
 def _process(self):
     db.session.delete(self.section)
     db.session.flush()
     if self.section.title:
         message = _('Section "{title}" deleted').format(title=self.section.title)
     else:
         message = _('Standalone section deleted')
     flash(message, 'success')
     logger.info('Survey section %s deleted by %s', self.section, session.user)
     return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
예제 #9
0
파일: survey.py 프로젝트: indico/indico
 def _process(self):
     form = SurveyForm(event=self.event, obj=self._get_form_defaults())
     if form.validate_on_submit():
         form.populate_obj(self.survey)
         db.session.flush()
         flash(_('Survey modified'), 'success')
         logger.info('Survey %s modified by %s', self.survey, session.user)
         return jsonify_data(flash=False)
     return jsonify_template('events/surveys/management/edit_survey.html', event=self.event, form=form,
                             survey=self.survey)
예제 #10
0
파일: survey.py 프로젝트: mkopcic/indico
 def _process(self):
     form = SurveyForm(event=self.event, obj=self._get_form_defaults())
     if form.validate_on_submit():
         form.populate_obj(self.survey)
         db.session.flush()
         flash(_('Survey modified'), 'success')
         logger.info('Survey %s modified by %s', self.survey, session.user)
         return jsonify_data(flash=False)
     return jsonify_template('events/surveys/management/edit_survey.html', event=self.event, form=form,
                             survey=self.survey)
예제 #11
0
 def send_submission_notification(self, submission):
     if not self.notifications_enabled:
         return
     template_module = get_template_module(
         'events/surveys/emails/new_submission_email.txt',
         submission=submission)
     email = make_email(bcc_list=self.new_submission_emails,
                        template=template_module)
     send_email(email, event=self.event, module='Surveys')
     logger.info('Sending submission notification for survey %s', self)
예제 #12
0
 def _process(self):
     submission_ids = set(map(int, request.form.getlist('submission_ids')))
     for submission in self.survey.submissions[:]:
         if submission.id in submission_ids:
             self.survey.submissions.remove(submission)
             logger.info('Submission {} deleted from survey {}'.format(submission, self.survey))
             self.event.log(EventLogRealm.management, EventLogKind.negative, 'Surveys',
                            'Submission removed from survey "{}"'.format(self.survey.title),
                            data={'Submitter': submission.user.full_name if submission.user else 'Anonymous'})
     return jsonify(success=True)
예제 #13
0
파일: results.py 프로젝트: OmeGak/indico
 def _process(self):
     submission_ids = set(map(int, request.form.getlist('submission_ids')))
     for submission in self.survey.submissions[:]:
         if submission.id in submission_ids:
             self.survey.submissions.remove(submission)
             logger.info('Submission %s deleted from survey %s', submission, self.survey)
             self.event_new.log(EventLogRealm.management, EventLogKind.negative, 'Surveys',
                                'Submission removed from survey "{}"'.format(self.survey.title),
                                data={'Submitter': submission.user.full_name if submission.user else 'Anonymous'})
     return jsonify(success=True)
예제 #14
0
 def _process(self):
     db.session.delete(self.question)
     db.session.flush()
     flash(
         _('Question "{title}" deleted').format(title=self.question.title),
         'success')
     logger.info('Survey question %s deleted by %s', self.question,
                 session.user)
     return jsonify_data(
         questionnaire=_render_questionnaire_preview(self.survey))
예제 #15
0
 def _process(self):
     form = self.question.field.create_config_form(obj=FormDefaults(self.question, **self.question.field_data))
     if form.validate_on_submit():
         old_title = self.question.title
         self.question.field.update_object(form.data)
         db.session.flush()
         flash(_('Question "{title}" updated').format(title=old_title), 'success')
         logger.info('Survey question %s modified by %s', self.question, session.user)
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('forms/form_common_fields_first.html', form=form)
예제 #16
0
파일: survey.py 프로젝트: indico/indico
 def _process(self):
     if self.survey.state == SurveyState.finished:
         self.survey.end_dt = None
         self.survey.start_notification_sent = False
     else:
         self.survey.open()
     self.survey.send_start_notification()
     flash(_("Survey is now open"), 'success')
     logger.info("Survey %s opened by %s", self.survey, session.user)
     return redirect(url_for('.manage_survey', self.survey))
예제 #17
0
파일: survey.py 프로젝트: mkopcic/indico
 def _process(self):
     if self.survey.state == SurveyState.finished:
         self.survey.end_dt = None
         self.survey.start_notification_sent = False
     else:
         self.survey.open()
     self.survey.send_start_notification()
     flash(_("Survey is now open"), 'success')
     logger.info("Survey %s opened by %s", self.survey, session.user)
     return redirect(url_for('.manage_survey', self.survey))
예제 #18
0
 def _process(self):
     db.session.delete(self.section)
     db.session.flush()
     if self.section.title:
         message = _('Section "{title}" deleted').format(title=self.section.title)
     else:
         message = _('Standalone section deleted')
     flash(message, 'success')
     logger.info('Survey section %s deleted by %s', self.section, session.user)
     return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
예제 #19
0
 def _process(self):
     form = SurveyForm(event=self.event, obj=self._get_form_defaults())
     if form.validate_on_submit():
         form.populate_obj(self.survey)
         db.session.flush()
         flash(_('Survey modified'), 'success')
         logger.info('Survey {} modified by {}'.format(self.survey, session.user))
         return redirect(url_for('.manage_survey', self.survey))
     return WPManageSurvey.render_template('management/edit_survey.html', self.event, event=self.event, form=form,
                                           survey=self.survey)
예제 #20
0
 def _process(self):
     form = self.question.field.create_config_form(obj=FormDefaults(self.question, **self.question.field_data))
     if form.validate_on_submit():
         old_title = self.question.title
         self.question.field.update_object(form.data)
         db.session.flush()
         flash(_('Question "{title}" updated').format(title=old_title), 'success')
         logger.info('Survey question %s modified by %s', self.question, session.user)
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('forms/form_common_fields_first.html', form=form)
예제 #21
0
 def _process(self):
     form = TextForm()
     if form.validate_on_submit():
         text = SurveyText()
         form.populate_obj(text)
         self.section.children.append(text)
         db.session.flush()
         flash(_('Text item added'), 'success')
         logger.info('Survey text item {} added by {}'.format(text, session.user))
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('events/surveys/management/edit_survey_item.html', form=form)
예제 #22
0
 def _process(self):
     form = SectionForm()
     if form.validate_on_submit():
         section = SurveySection(survey=self.survey)
         form.populate_obj(section)
         db.session.add(section)
         db.session.flush()
         flash(_('Section "{title}" added').format(title=section.title), 'success')
         logger.info('Survey section {} added by {}'.format(section, session.user))
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('events/surveys/management/edit_survey_item.html', form=form)
예제 #23
0
파일: surveys.py 프로젝트: javfg/indico
 def send_start_notification(self):
     if not self.notifications_enabled or self.start_notification_sent or not self.event.has_feature(
             'surveys'):
         return
     template_module = get_template_module(
         'events/surveys/emails/start_notification_email.txt', survey=self)
     email = make_email(bcc_list=self.start_notification_recipients,
                        template=template_module)
     send_email(email, event=self.event, module='Surveys')
     logger.info('Sending start notification for survey %s', self)
     self.start_notification_sent = True
예제 #24
0
 def _process(self):
     form = TextForm(obj=FormDefaults(self.text))
     if form.validate_on_submit():
         form.populate_obj(self.text)
         db.session.flush()
         flash(_('Text item updated'), 'success')
         logger.info('Survey text item %s modified by %s', self.text,
                     session.user)
         return jsonify_data(
             questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('forms/form_common_fields_first.html',
                             form=form)
예제 #25
0
 def _process(self):
     form = TextForm(obj=FormDefaults(self.text))
     if form.validate_on_submit():
         form.populate_obj(self.text)
         db.session.flush()
         flash(_('Text item updated'), 'success')
         logger.info('Survey text item {} modified by {}'.format(
             self.text, session.user))
         return jsonify_data(
             questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template(
         'events/surveys/management/edit_survey_item.html', form=form)
예제 #26
0
def add_survey_text(section, data):
    """Add a text item to a survey.

    :param section: The `SurveySection` to which the question will be added.
    :param data: The `TextForm.data` to populate the question with.
    :return: The added `SurveyText`.
    """
    text = SurveyText()
    text.populate_from_dict(data)
    section.children.append(text)
    db.session.flush()
    logger.info('Survey text item %s added by %s', text, session.user)
    return text
예제 #27
0
def add_survey_text(section, data):
    """Add a text item to a survey.

    :param section: The `SurveySection` to which the question will be added.
    :param data: The `TextForm.data` to populate the question with.
    :return: The added `SurveyText`.
    """
    text = SurveyText()
    text.populate_from_dict(data)
    section.children.append(text)
    db.session.flush()
    logger.info('Survey text item %s added by %s', text, session.user)
    return text
예제 #28
0
def add_survey_section(survey, data):
    """Add a section to a survey.

    :param survey: The `Survey` to which the section will be added.
    :param data: Attributes of the new `SurveySection`.
    :return: The added `SurveySection`.
    """
    section = SurveySection(survey=survey)
    section.populate_from_dict(data)
    db.session.add(section)
    db.session.flush()
    logger.info('Survey section %s added by %s', section, session.user)
    return section
예제 #29
0
 def _process(self):
     form = SurveyForm(event=self.event, obj=self._get_form_defaults())
     if form.validate_on_submit():
         form.populate_obj(self.survey)
         db.session.flush()
         flash(_('Survey modified'), 'success')
         logger.info('Survey %s modified by %s', self.survey, session.user)
         return redirect(url_for('.manage_survey', self.survey))
     return WPManageSurvey.render_template('management/edit_survey.html',
                                           self.event,
                                           event=self.event,
                                           form=form,
                                           survey=self.survey)
예제 #30
0
def add_survey_section(survey, data):
    """Add a section to a survey.

    :param survey: The `Survey` to which the section will be added.
    :param data: Attributes of the new `SurveySection`.
    :return: The added `SurveySection`.
    """
    section = SurveySection(survey=survey)
    section.populate_from_dict(data)
    db.session.add(section)
    db.session.flush()
    logger.info('Survey section %s added by %s', section, session.user)
    return section
예제 #31
0
 def _process(self):
     form = SurveyForm(obj=FormDefaults(require_user=True), event=self.event)
     if form.validate_on_submit():
         survey = Survey(event_new=self.event.as_event)
         # add a default section so people can start adding questions right away
         survey.items.append(SurveySection(display_as_section=False))
         form.populate_obj(survey)
         db.session.add(survey)
         db.session.flush()
         flash(_('Survey created'), 'success')
         logger.info('Survey {} created by {}'.format(survey, session.user))
         return redirect(url_for('.manage_survey', survey))
     return WPManageSurvey.render_template('management/edit_survey.html',
                                           self.event, event=self.event, form=form, survey=None)
예제 #32
0
 def _process(self):
     form = SectionForm(obj=FormDefaults(self.section))
     if form.validate_on_submit():
         old_title = self.section.title
         form.populate_obj(self.section)
         db.session.flush()
         if old_title:
             message = _('Section "{title}" updated').format(title=old_title)
         else:
             message = _('Standalone section updated')
         flash(message, 'success')
         logger.info('Survey section %s modified by %s', self.section, session.user)
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('forms/form_common_fields_first.html', form=form)
예제 #33
0
 def _process(self):
     form = TextForm()
     if form.validate_on_submit():
         text = SurveyText()
         form.populate_obj(text)
         self.section.children.append(text)
         db.session.flush()
         flash(_('Text item added'), 'success')
         logger.info('Survey text item {} added by {}'.format(
             text, session.user))
         return jsonify_data(
             questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template(
         'events/surveys/management/edit_survey_item.html', form=form)
예제 #34
0
파일: survey.py 프로젝트: indico/indico
 def _process(self):
     form = SurveyForm(obj=FormDefaults(require_user=True), event=self.event)
     if form.validate_on_submit():
         survey = Survey(event=self.event)
         # add a default section so people can start adding questions right away
         survey.items.append(SurveySection(display_as_section=False))
         form.populate_obj(survey)
         db.session.add(survey)
         db.session.flush()
         flash(_('Survey created'), 'success')
         logger.info('Survey %s created by %s', survey, session.user)
         return jsonify_data(flash=False)
     return jsonify_template('events/surveys/management/edit_survey.html', event=self.event, form=form,
                             survey=None)
예제 #35
0
 def _process(self):
     form = ImportQuestionnaireForm()
     if form.validate_on_submit():
         try:
             data = json.load(form.json_file.data.file)
             self._import_data(data)
         except ValueError as exception:
             logger.info('%s tried to import an invalid JSON file: %s', session.user, exception.message)
             flash(_("Invalid file selected."), 'error')
         else:
             flash(_("The questionnaire has been imported."), 'success')
             logger.info('Questionnaire imported from JSON document by %s', session.user)
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_form(form, form_header_kwargs={'action': request.relative_url})
예제 #36
0
 def _process(self):
     form = SectionForm(obj=FormDefaults(self.section))
     if form.validate_on_submit():
         old_title = self.section.title
         form.populate_obj(self.section)
         db.session.flush()
         if old_title:
             message = _('Section "{title}" updated').format(title=old_title)
         else:
             message = _('Standalone section updated')
         flash(message, 'success')
         logger.info('Survey section %s modified by %s', self.section, session.user)
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template('forms/form_common_fields_first.html', form=form)
예제 #37
0
 def _process(self):
     form = ImportQuestionnaireForm()
     if form.validate_on_submit():
         try:
             data = json.load(form.json_file.data.file)
             self._import_data(data)
         except ValueError as exception:
             logger.info('%s tried to import an invalid JSON file: %s', session.user, exception.message)
             flash(_("Invalid file selected."), 'error')
         else:
             flash(_("The questionnaire has been imported."), 'success')
             logger.info('Questionnaire imported from JSON document by %s', session.user)
         return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_form(form, form_header_kwargs={'action': request.relative_url})
예제 #38
0
파일: survey.py 프로젝트: mkopcic/indico
 def _process(self):
     form = SurveyForm(obj=FormDefaults(require_user=True), event=self.event)
     if form.validate_on_submit():
         survey = Survey(event=self.event)
         # add a default section so people can start adding questions right away
         survey.items.append(SurveySection(display_as_section=False))
         form.populate_obj(survey)
         db.session.add(survey)
         db.session.flush()
         flash(_('Survey created'), 'success')
         logger.info('Survey %s created by %s', survey, session.user)
         return jsonify_data(flash=False)
     return jsonify_template('events/surveys/management/edit_survey.html', event=self.event, form=form,
                             survey=None)
예제 #39
0
def add_survey_question(section, field_cls, data):
    """Add a question to a survey.

    :param section: The `SurveySection` to which the question will be added.
    :param field_cls: The field class of this question.
    :param data: The `FieldConfigForm.data` to populate the question with.
    :return: The added `SurveyQuestion`.
    """
    question = SurveyQuestion()
    field = field_cls(question)
    field.update_object(data)
    section.children.append(question)
    db.session.flush()
    logger.info('Survey question %s added by %s', question, session.user)
    return question
예제 #40
0
def add_survey_question(section, field_cls, data):
    """Add a question to a survey.

    :param section: The `SurveySection` to which the question will be added.
    :param field_cls: The field class of this question.
    :param data: The `FieldConfigForm.data` to populate the question with.
    :return: The added `SurveyQuestion`.
    """
    question = SurveyQuestion()
    field = field_cls(question)
    field.update_object(data)
    section.children.append(question)
    db.session.flush()
    logger.info('Survey question %s added by %s', question, session.user)
    return question
예제 #41
0
 def _process(self):
     form = SectionForm(obj=FormDefaults(self.section))
     if form.validate_on_submit():
         old_title = self.section.title
         form.populate_obj(self.section)
         db.session.flush()
         flash(
             _('Section "{title}" updated').format(title=old_title),
             'success')
         logger.info('Survey section {} modified by {}'.format(
             self.section, session.user))
         return jsonify_data(
             questionnaire=_render_questionnaire_preview(self.survey))
     return jsonify_template(
         'events/surveys/management/edit_survey_item.html', form=form)
예제 #42
0
파일: survey.py 프로젝트: mkopcic/indico
 def _process(self):
     allow_reschedule_start = self.survey.state in (SurveyState.ready_to_open, SurveyState.active_and_clean,
                                                    SurveyState.finished)
     form = ScheduleSurveyForm(obj=self._get_form_defaults(), survey=self.survey,
                               allow_reschedule_start=allow_reschedule_start)
     if form.validate_on_submit():
         if allow_reschedule_start:
             self.survey.start_dt = form.start_dt.data
             if getattr(form, 'resend_start_notification', False):
                 self.survey.start_notification_sent = not form.resend_start_notification.data
         self.survey.end_dt = form.end_dt.data
         flash(_('Survey was scheduled'), 'success')
         logger.info('Survey %s scheduled by %s', self.survey, session.user)
         return jsonify_data(flash=False)
     disabled_fields = ('start_dt',) if not allow_reschedule_start else ()
     return jsonify_form(form, submit=_('Schedule'), disabled_fields=disabled_fields)
예제 #43
0
    def _process(self):
        try:
            field_cls = get_field_types()[request.view_args['type']]
        except KeyError:
            raise NotFound

        form = field_cls.config_form()
        if form.validate_on_submit():
            question = SurveyQuestion()
            field_cls(question).save_config(form)
            self.section.children.append(question)
            db.session.flush()
            flash(_('Question "{title}" added').format(title=question.title), 'success')
            logger.info('Survey question {} added by {}'.format(question, session.user))
            return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
        return jsonify_template('events/surveys/management/edit_survey_item.html', form=form)
예제 #44
0
파일: survey.py 프로젝트: indico/indico
 def _process(self):
     allow_reschedule_start = self.survey.state in (SurveyState.ready_to_open, SurveyState.active_and_clean,
                                                    SurveyState.finished)
     form = ScheduleSurveyForm(obj=self._get_form_defaults(), survey=self.survey,
                               allow_reschedule_start=allow_reschedule_start)
     if form.validate_on_submit():
         if allow_reschedule_start:
             self.survey.start_dt = form.start_dt.data
             if getattr(form, 'resend_start_notification', False):
                 self.survey.start_notification_sent = not form.resend_start_notification.data
         self.survey.end_dt = form.end_dt.data
         flash(_('Survey was scheduled'), 'success')
         logger.info('Survey %s scheduled by %s', self.survey, session.user)
         return jsonify_data(flash=False)
     disabled_fields = ('start_dt',) if not allow_reschedule_start else ()
     return jsonify_form(form, submit=_('Schedule'), disabled_fields=disabled_fields)
예제 #45
0
 def _process(self):
     form = SurveyForm(obj=FormDefaults(require_user=True),
                       event=self.event)
     if form.validate_on_submit():
         survey = Survey(event_new=self.event.as_event)
         # add a default section so people can start adding questions right away
         survey.items.append(SurveySection(display_as_section=False))
         form.populate_obj(survey)
         db.session.add(survey)
         db.session.flush()
         flash(_('Survey created'), 'success')
         logger.info('Survey {} created by {}'.format(survey, session.user))
         return redirect(url_for('.manage_survey', survey))
     return WPManageSurvey.render_template('management/edit_survey.html',
                                           self.event,
                                           event=self.event,
                                           form=form,
                                           survey=None)
예제 #46
0
 def _sort_items(self):
     section = SurveySection.find_one(survey=self.survey, id=request.form['section_id'],
                                      _eager=SurveySection.children)
     section_items = {x.id: x for x in section.children}
     item_ids = map(int, request.form.getlist('item_ids'))
     changed_section = None
     for position, item_id in enumerate(item_ids, 1):
         try:
             section_items[item_id].position = position
         except KeyError:
             # item is not in section, was probably moved
             item = SurveyItem.find_one(SurveyItem.survey == self.survey, SurveyItem.id == item_id,
                                        SurveyItem.type != SurveyItemType.section, _eager=SurveyItem.parent)
             changed_section = item.parent
             item.position = position
             item.parent = section
             logger.info('Item {} moved to section {} by {}'.format(item, section, session.user))
     logger.info('Items in {} reordered by {}'.format(section, session.user))
     if changed_section is not None:
         for position, item in enumerate(changed_section.children, 1):
             item.position = position
예제 #47
0
    def _process(self):
        try:
            field_cls = get_field_types()[request.view_args['type']]
        except KeyError:
            raise NotFound

        form = field_cls.config_form()
        if form.validate_on_submit():
            question = SurveyQuestion()
            field_cls(question).save_config(form)
            self.section.children.append(question)
            db.session.flush()
            flash(
                _('Question "{title}" added').format(title=question.title),
                'success')
            logger.info('Survey question {} added by {}'.format(
                question, session.user))
            return jsonify_data(
                questionnaire=_render_questionnaire_preview(self.survey))
        return jsonify_template(
            'events/surveys/management/edit_survey_item.html', form=form)
예제 #48
0
 def _sort_items(self):
     section = SurveySection.find_one(survey=self.survey, id=request.form['section_id'],
                                      _eager=SurveySection.children)
     section_items = {x.id: x for x in section.children}
     item_ids = map(int, request.form.getlist('item_ids'))
     changed_section = None
     for position, item_id in enumerate(item_ids, 1):
         try:
             section_items[item_id].position = position
         except KeyError:
             # item is not in section, was probably moved
             item = SurveyItem.find_one(SurveyItem.survey == self.survey, SurveyItem.id == item_id,
                                        SurveyItem.type != SurveyItemType.section, _eager=SurveyItem.parent)
             changed_section = item.parent
             item.position = position
             item.parent = section
             logger.info('Item %s moved to section %s by %s', item, section, session.user)
     logger.info('Items in %s reordered by %s', section, session.user)
     if changed_section is not None:
         for position, item in enumerate(changed_section.children, 1):
             item.position = position
예제 #49
0
파일: survey.py 프로젝트: hennogous/indico
 def _process(self):
     allow_reschedule_start = self.survey.state in (
         SurveyState.ready_to_open,
         SurveyState.active_and_clean,
         SurveyState.finished,
     )
     form = ScheduleSurveyForm(
         obj=self._get_form_defaults(), survey=self.survey, allow_reschedule_start=allow_reschedule_start
     )
     if form.validate_on_submit():
         if allow_reschedule_start:
             self.survey.start_dt = form.start_dt.data
             if getattr(form, "resend_start_notification", False):
                 self.survey.start_notification_sent = not form.resend_start_notification.data
         self.survey.end_dt = form.end_dt.data
         flash(_("Survey was scheduled"), "success")
         logger.info("Survey {} scheduled by {}".format(self.survey, session.user))
         return jsonify_data(flash=False)
     disabled_fields = ("start_dt",) if not allow_reschedule_start else ()
     return jsonify_template(
         "events/surveys/management/schedule_survey.html", form=form, disabled_fields=disabled_fields
     )
예제 #50
0
 def _process(self):
     self.survey.is_deleted = True
     flash(_('Survey deleted'), 'success')
     logger.info('Survey %s deleted by %s', self.survey, session.user)
     return redirect(url_for('.manage_survey_list', self.event))
예제 #51
0
 def _process(self):
     self.survey.close()
     flash(_("Survey is now closed"), 'success')
     logger.info("Survey %s closed by %s", self.survey, session.user)
     return redirect(url_for('.manage_survey', self.survey))
예제 #52
0
 def _sort_sections(self):
     sections = {section.id: section for section in self.survey.sections}
     section_ids = map(int, request.form.getlist('section_ids'))
     for position, section_id in enumerate(section_ids, 1):
         sections[section_id].position = position
     logger.info('Sections in {} reordered by {}'.format(self.survey, session.user))
예제 #53
0
파일: survey.py 프로젝트: indico/indico
 def _process(self):
     self.survey.is_deleted = True
     flash(_('Survey deleted'), 'success')
     logger.info('Survey %s deleted by %s', self.survey, session.user)
     return redirect(url_for('.manage_survey_list', self.event))
예제 #54
0
 def _process(self):
     db.session.delete(self.text)
     db.session.flush()
     flash(_('Text item deleted'), 'success')
     logger.info('Survey question {} deleted by {}'.format(self.text, session.user))
     return jsonify_data(questionnaire=_render_questionnaire_preview(self.text.survey))
예제 #55
0
 def _process(self):
     db.session.delete(self.text)
     db.session.flush()
     flash(_('Text item deleted'), 'success')
     logger.info('Survey question %s deleted by %s', self.text, session.user)
     return jsonify_data(questionnaire=_render_questionnaire_preview(self.text.survey))
예제 #56
0
 def _sort_sections(self):
     sections = {section.id: section for section in self.survey.sections}
     section_ids = map(int, request.form.getlist('section_ids'))
     for position, section_id in enumerate(section_ids, 1):
         sections[section_id].position = position
     logger.info('Sections in %s reordered by %s', self.survey, session.user)
예제 #57
0
 def _process(self):
     db.session.delete(self.question)
     db.session.flush()
     flash(_('Question "{title}" deleted').format(title=self.question.title), 'success')
     logger.info('Survey question {} deleted by {}'.format(self.question, session.user))
     return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))