Example #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))
Example #2
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_new, module='Surveys')
     logger.info('Sending submission notification for survey %s', self)
Example #3
0
 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
Example #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
Example #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)
Example #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)
Example #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)
Example #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))
Example #9
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 jsonify_data(flash=False)
     return jsonify_template('events/surveys/management/edit_survey.html', event=self.event, form=form,
                             survey=self.survey)
Example #10
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 jsonify_data(flash=False)
     return jsonify_template('events/surveys/management/edit_survey.html', event=self.event, form=form,
                             survey=self.survey)
Example #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)
Example #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)
Example #13
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 %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)
Example #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))
Example #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)
Example #16
0
 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))
Example #17
0
 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))
Example #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))
Example #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)
Example #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)
Example #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)
Example #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)
Example #23
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 %s', self)
     self.start_notification_sent = True
Example #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)
Example #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)
Example #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
Example #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
Example #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
Example #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)
Example #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
Example #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)
Example #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)
Example #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)
Example #34
0
 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)
Example #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})
Example #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)
Example #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})
Example #38
0
 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)
Example #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
Example #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
Example #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)
Example #42
0
 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)
Example #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)
Example #44
0
 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)
Example #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)
Example #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
Example #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)
Example #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
Example #49
0
 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
     )
Example #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))
Example #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))
Example #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))
Example #53
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))
Example #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))
Example #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))
Example #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)
Example #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))