예제 #1
0
    def _process(self):
        try:
            field_cls = get_field_types()[request.view_args['type']]
        except KeyError:
            raise NotFound

        form = field_cls.create_config_form()
        try:
            clone_id = int(request.args['clone'])
        except (KeyError, ValueError):
            pass
        else:
            try:
                question_to_clone = SurveyQuestion.query.with_parent(
                    self.survey).filter_by(id=clone_id).one()
                form = question_to_clone.field.create_config_form(
                    obj=FormDefaults(
                        question_to_clone,
                        **question_to_clone.field.copy_field_data()))
            except NoResultFound:
                pass

        if form.validate_on_submit():
            question = add_survey_question(self.section, field_cls, form.data)
            flash(
                _('Question "{title}" added').format(title=question.title),
                'success')
            return jsonify_data(
                questionnaire=_render_questionnaire_preview(self.survey))
        return jsonify_template('forms/form_common_fields_first.html',
                                form=form)
예제 #2
0
def _render_questionnaire_preview(survey):
    # load the survey once again with all the necessary data
    survey = (Survey.find(id=survey.id).options(
        joinedload(Survey.sections).joinedload(SurveySection.children)).one())
    tpl = get_template_module(
        'events/surveys/management/_questionnaire_preview.html')
    form = make_survey_form(survey)()
    return tpl.render_questionnaire_preview(survey, form, get_field_types())
예제 #3
0
 def _process(self):
     field_types = get_field_types()
     preview_form = make_survey_form(self.survey)()
     return WPManageSurvey.render_template(
         'management/survey_questionnaire.html',
         self.event,
         survey=self.survey,
         field_types=field_types,
         preview_form=preview_form)
예제 #4
0
def _render_questionnaire_preview(survey):
    # load the survey once again with all the necessary data
    survey = (Survey
              .find(id=survey.id)
              .options(joinedload(Survey.sections).joinedload(SurveySection.children))
              .one())
    tpl = get_template_module('events/surveys/management/_questionnaire_preview.html')
    form = make_survey_form(survey)()
    return tpl.render_questionnaire_preview(survey, form, get_field_types())
예제 #5
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)
예제 #6
0
 def _import_section_item(self, section, data):
     self._remove_false_values(data)
     if data['type'] == 'text':
         form = TextForm(formdata=MultiDict(data.items()), csrf_enabled=False)
         if form.validate():
             add_survey_text(section, form.data)
         else:
             raise ValueError('Invalid text item')
     elif data['type'] == 'question':
         for key, value in data['field_data'].iteritems():
             if value is not None:
                 data[key] = value
         field_cls = get_field_types()[data['field_type']]
         data = field_cls.process_imported_data(data)
         form = field_cls.create_config_form(formdata=MultiDict(data.items()), csrf_enabled=False)
         if not form.validate():
             raise ValueError('Invalid question')
         add_survey_question(section, field_cls, form.data)
예제 #7
0
 def _import_section_item(self, section, data):
     self._remove_false_values(data)
     if data['type'] == 'text':
         form = TextForm(formdata=MultiDict(data.items()), csrf_enabled=False)
         if form.validate():
             add_survey_text(section, form.data)
         else:
             raise ValueError('Invalid text item')
     elif data['type'] == 'question':
         for key, value in data['field_data'].iteritems():
             if value is not None:
                 data[key] = value
         field_cls = get_field_types()[data['field_type']]
         data = field_cls.process_imported_data(data)
         form = field_cls.create_config_form(formdata=MultiDict(data.items()), csrf_enabled=False)
         if not form.validate():
             raise ValueError('Invalid question')
         add_survey_question(section, field_cls, form.data)
예제 #8
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)
예제 #9
0
    def _process(self):
        try:
            field_cls = get_field_types()[request.view_args['type']]
        except KeyError:
            raise NotFound

        form = field_cls.create_config_form()
        try:
            clone_id = int(request.args['clone'])
        except (KeyError, ValueError):
            pass
        else:
            try:
                question_to_clone = SurveyQuestion.query.with_parent(self.survey).filter_by(id=clone_id).one()
                form = question_to_clone.field.create_config_form(
                    obj=FormDefaults(question_to_clone, **question_to_clone.field.copy_field_data()))
            except NoResultFound:
                pass

        if form.validate_on_submit():
            question = add_survey_question(self.section, field_cls, form.data)
            flash(_('Question "{title}" added').format(title=question.title), 'success')
            return jsonify_data(questionnaire=_render_questionnaire_preview(self.survey))
        return jsonify_template('forms/form_common_fields_first.html', form=form)
예제 #10
0
 def field(self):
     try:
         impl = get_field_types()[self.field_type]
     except KeyError:
         return None
     return impl(self)
예제 #11
0
 def field(self):
     try:
         impl = get_field_types()[self.field_type]
     except KeyError:
         return None
     return impl(self)
예제 #12
0
 def _process(self):
     field_types = get_field_types()
     preview_form = make_survey_form(self.survey)()
     return WPManageSurvey.render_template('management/survey_questionnaire.html', self.event, survey=self.survey,
                                           field_types=field_types, preview_form=preview_form)