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
def test_survey_clone(db, create_event, dummy_event): survey = Survey(event=dummy_event, title='test') first_section = SurveySection(title='section 1', display_as_section=True, position=2) survey.items.append(first_section) first_section.children.append( SurveyQuestion(title='question in s1', field_type='text', is_required=True)) second_section = SurveySection(title='section 2', display_as_section=True, position=1) survey.items.append(second_section) second_section.children.append(SurveyText(description='My text')) second_section.children.append( SurveyQuestion(title='What is your name?', field_type='text', is_required=False)) db.session.flush() new_event = create_event() cloner = EventSurveyCloner(dummy_event) cloner.run(new_event, {}, {}, False) assert len(new_event.surveys) == 1 assert len(new_event.surveys[0].items) == len(survey.items) for i, item in enumerate(new_event.surveys[0].items): for attr in get_simple_column_attrs(SurveyItem): assert getattr(item, attr) == getattr(survey.items[i], attr)
def _process_args(self): RHManageSurveysBase._process_args(self) self.text = SurveyText.find_one( SurveyText.id == request.view_args['text_id'], ~Survey.is_deleted, _join=SurveyText.survey, _eager=SurveyText.survey) self.survey = self.text.survey
def _checkParams(self, params): RHManageSurveysBase._checkParams(self, params) self.text = SurveyText.find_one( SurveyText.id == request.view_args['text_id'], ~Survey.is_deleted, _join=SurveyText.survey, _eager=SurveyText.survey) self.survey = self.text.survey
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)
def _checkParams(self, params): RHManageSurveysBase._checkParams(self, params) self.text = SurveyText.find_one(SurveyText.id == request.view_args['text_id'], ~Survey.is_deleted, _join=SurveyText.survey, _eager=SurveyText.survey) self.survey = self.text.survey
def _process_args(self): RHManageSurveysBase._process_args(self) self.text = SurveyText.find_one(SurveyText.id == request.view_args['text_id'], ~Survey.is_deleted, _join=SurveyText.survey, _eager=SurveyText.survey) self.survey = self.text.survey