Exemple #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)
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)