• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python questions.QuestionForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中questionnaire.forms.questions.QuestionForm的典型用法代码示例。如果您正苦于以下问题:Python QuestionForm类的具体用法?Python QuestionForm怎么用?Python QuestionForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了QuestionForm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: QuestionForm

    def test_editing_question_used_in_a_published_questionnaire_give_the_duplicate_question_old_question_order(self):
        self.questionnaire.status = Questionnaire.PUBLISHED
        self.questionnaire.save()
        self.question1.orders.create(order=1, question_group=self.parent_group)

        draft_questionnaire = Questionnaire.objects.create(name="draft qnaire",description="haha",
                                                           status=Questionnaire.DRAFT)
        section_1 = Section.objects.create(title="section 1", order=1, questionnaire=draft_questionnaire, name="ha")
        sub_section_1 = SubSection.objects.create(title="subs1", order=1, section=section_1)
        parent_group_d = QuestionGroup.objects.create(subsection=sub_section_1, name="group")
        parent_group_d.question.add(self.question1)
        self.question1.orders.create(order=2, question_group=parent_group_d)

        finalized_questionnaire = Questionnaire.objects.create(name="finalized qnaire",description="haha",
                                                           status=Questionnaire.FINALIZED)
        section_1_f = Section.objects.create(title="section 1", order=1, questionnaire=finalized_questionnaire, name="ha")
        sub_section_1_f = SubSection.objects.create(title="subs1", order=1, section=section_1_f)
        parent_group_f = QuestionGroup.objects.create(subsection=sub_section_1_f, name="group")
        parent_group_f.question.add(self.question1)
        self.question1.orders.create(order=3, question_group=parent_group_f)

        data = self.form_data.copy()
        history_form = QuestionForm(data=data, instance=self.question1)

        self.assertTrue(history_form.is_valid())
        duplicate_question = history_form.save()

        self.assertEqual(1, self.question1.orders.get(question_group=self.parent_group).order)
        self.assertEqual(0, duplicate_question.orders.filter(question_group=self.parent_group).count())

        self.assertEqual(2, duplicate_question.orders.get(question_group=parent_group_d).order)
        self.assertEqual(0, self.question1.orders.filter(question_group=parent_group_d).count())

        self.assertEqual(3, duplicate_question.orders.get(question_group=parent_group_f).order)
        self.assertEqual(0, self.question1.orders.filter(question_group=parent_group_f).count())
开发者ID:remo4sam,项目名称:ejrf,代码行数:35,代码来源:test_questions_form.py


示例2: test_edit_removes_deleted_options_from_the_question

    def test_edit_removes_deleted_options_from_the_question(self):
        question = QuestionFactory(text='whats up?', answer_type=AnswerTypes.MULTI_CHOICE)

        QuestionOptionFactory(question=question, text='Yes', order=1)
        QuestionOptionFactory(question=question, text='NR', order=2)
        QuestionOptionFactory(question=question, text='No', order=3)

        changed_options = ['Yes', 'No', 'Maybe']

        data = {'text': 'changed text',
                'instructions': 'Some instructions',
                'export_label': 'blah',
                'answer_type': 'MultiChoice',
                'theme': self.theme.id,
                'options': changed_options}

        history_form = QuestionForm(data=data, instance=question)

        self.assertTrue(history_form.is_valid())
        edited_question = history_form.save()

        question1_options = edited_question.options.all()

        self.assertEqual(3, question1_options.count())
        [self.assertIn(question_option.text, changed_options) for question_option in question1_options]
开发者ID:eJRF,项目名称:ejrf,代码行数:25,代码来源:test_questions_form.py


示例3: test_clean_answer_number_sub_type_valid

 def test_clean_answer_number_sub_type_valid(self):
     data = self.form_data.copy()
     data['answer_type'] = AnswerTypes.NUMBER
     data['answer_sub_type'] = AnswerTypes.DECIMAL
     question_form = QuestionForm(data=data)
     self.assertTrue(question_form.is_valid())
     self.assertTrue(len(question_form.errors) == 0)
开发者ID:eJRF,项目名称:ejrf,代码行数:7,代码来源:test_questions_form.py


示例4: CreateQuestion

class CreateQuestion(PermissionRequiredMixin, CreateView):
    permission_required = 'auth.can_edit_questionnaire'

    def __init__(self, **kwargs):
        super(CreateQuestion, self).__init__(**kwargs)
        self.template_name = 'questions/new.html'
        self.object = Question
        self.model = Question
        self.form_class = QuestionForm
        self.form = None

    def get_context_data(self, **kwargs):
        context = super(CreateQuestion, self).get_context_data(**kwargs)
        context.update({'btn_label': 'CREATE', 'id': 'id-new-question-form',
                        'cancel_url': reverse('list_questions_page'), 'title': 'New Question'})
        return context

    def post(self, request, *args, **kwargs):
        region = self.request.user.user_profile.region
        self.form = QuestionForm(region=region, data=request.POST)
        if self.form.is_valid():
            return self._form_valid()
        return self._form_invalid()

    def _form_valid(self):
        self.form.save()
        messages.success(self.request, "Question successfully created.")
        return HttpResponseRedirect(reverse('list_questions_page'))

    def _form_invalid(self):
        messages.error(self.request, "Question NOT created. See errors below.")
        context = {'form': self.form, 'btn_label': "CREATE", 'id': 'id-new-question-form',
                   'cancel_url': reverse('list_questions_page'), 'title': 'New Question'}
        return self.render_to_response(context)
开发者ID:remo4sam,项目名称:ejrf,代码行数:34,代码来源:questions.py


示例5: test_increments_uid_of_existing_question_by_one_upon_save_given_instance

 def test_increments_uid_of_existing_question_by_one_upon_save_given_instance(self):
     Question.objects.create(text='B. Number of cases tested',
                             instructions="Enter the total number of cases", UID='00001', answer_type='Number',
                             answer_sub_type="Integer")
     question_form = QuestionForm(data=self.form_data)
     question = question_form.save(commit=True)
     self.assertEqual('00002', question.UID)
开发者ID:eJRF,项目名称:ejrf,代码行数:7,代码来源:test_questions_form.py


示例6: CreateQuestion

class CreateQuestion(CreateView):
    def __init__(self, **kwargs):
        super(CreateQuestion, self).__init__(**kwargs)
        self.template_name = 'questions/new.html'
        self.object = Question
        self.model = Question
        self.form_class = QuestionForm
        self.form = None

    def get_context_data(self, **kwargs):
        context = super(CreateQuestion, self).get_context_data(**kwargs)
        context.update({'btn_label': 'CREATE', 'id': 'id-new-question-form'})
        return context

    def post(self, request, *args, **kwargs):
        self.form = QuestionForm(data=request.POST)
        if self.form.is_valid():
            return self._form_valid()
        return self._form_invalid()

    def _form_valid(self):
        self.form.save()
        messages.success(self.request, "Question successfully created.")
        return HttpResponseRedirect(reverse('list_questions_page'))

    def _form_invalid(self):
        messages.error(self.request, "Question NOT created. See errors below.")
        context = {'form': self.form, 'btn_label': "CREATE", 'id': 'id-new-question-form'}
        return self.render_to_response(context)
开发者ID:testvidya11,项目名称:ejrf,代码行数:29,代码来源:questions.py


示例7: test_assigns_region_on_save_if_region_is_given

 def test_assigns_region_on_save_if_region_is_given(self):
     region = Region.objects.create(name="ASEAN")
     form = {'text': 'How many kids were immunised this year?',
             'instructions': 'Some instructions',
             'short_instruction': 'short version',
             'export_label': 'blah',
             'answer_type': 'Text',
             'theme': self.theme.id}
     question_form = QuestionForm(region=region, data=form)
     question = question_form.save(commit=True)
     self.assertEqual(region, question.region)
开发者ID:eJRF,项目名称:ejrf,代码行数:11,代码来源:test_questions_form.py


示例8: test_assigns_region_on_save_if_region_is_given

 def test_assigns_region_on_save_if_region_is_given(self):
     global_admin, country, region = self.create_user_with_no_permissions()
     form = {'text': 'How many kids were immunised this year?',
             'instructions': 'Some instructions',
             'short_instruction': 'short version',
             'export_label': 'blah',
             'answer_type': 'Text',
             'theme': self.theme.id}
     question_form = QuestionForm(region=region, data=form)
     question = question_form.save(commit=True)
     self.assertEqual(region, question.region)
开发者ID:remo4sam,项目名称:ejrf,代码行数:11,代码来源:test_questions_form.py


示例9: test_editing_question_used_in_an_unpublished_questionnaire_updates_question

    def test_editing_question_used_in_an_unpublished_questionnaire_updates_question(self):
        data = self.form_data.copy()
        history_form = QuestionForm(data=data, instance=self.question1)
        history_form.is_valid()

        history_form.save()

        questions = Question.objects.filter(UID=self.question1.UID)

        self.assertEqual(1, questions.count())
        self.failUnless(self.question1.id, questions[0].id)
开发者ID:eJRF,项目名称:ejrf,代码行数:11,代码来源:test_questions_form.py


示例10: test_form_invalid_if_multichoice_question_and_no_options_in_data_options

    def test_form_invalid_if_multichoice_question_and_no_options_in_data_options(self):
        form = {'text': 'How many kids were immunised this year?',
                'instructions': 'Some instructions',
                'short_instruction': 'short version',
                'export_label': 'blah',
                'answer_type': 'MultiChoice',
                'options': ['', '']}
        question_form = QuestionForm(data=form)

        self.assertFalse(question_form.is_valid())
        message = "MultiChoice questions must have at least one option"
        self.assertIn(message, question_form.errors['answer_type'][0])
开发者ID:testvidya11,项目名称:ejrf,代码行数:12,代码来源:test_questions_form.py


示例11: test_duplicate_question_maintains_region

    def test_duplicate_question_maintains_region(self):
        self.questionnaire.status = Questionnaire.PUBLISHED
        self.questionnaire.save()
        region = Region.objects.create(name="AFR")
        self.question1.region = region
        self.question1.save()
        data = self.form_data.copy()
        history_form = QuestionForm(data=data, instance=self.question1)

        self.assertTrue(history_form.is_valid())
        duplicate_question = history_form.save()

        self.assertEqual(region, duplicate_question.region)
开发者ID:eJRF,项目名称:ejrf,代码行数:13,代码来源:test_questions_form.py


示例12: test_form_invalid_if_multipleresponse_question_and_no_options_in_data_options

    def test_form_invalid_if_multipleresponse_question_and_no_options_in_data_options(self):
        form = {'text': 'How many kids were immunised this year?',
                'instructions': 'Some instructions',
                'short_instruction': 'short version',
                'export_label': 'blah',
                'answer_type': AnswerTypes.MULTIPLE_RESPONSE,
                'options': ['', ''],
                'theme': self.theme.id}
        question_form = QuestionForm(data=form)

        self.assertFalse(question_form.is_valid())
        message = "%s questions must have at least one option" % AnswerTypes.MULTIPLE_RESPONSE
        self.assertIn(message, question_form.errors['answer_type'][0])
开发者ID:eJRF,项目名称:ejrf,代码行数:13,代码来源:test_questions_form.py


示例13: test_editing_question_used_in_a_published_questionnaire_creates_a_duplicate_question

    def test_editing_question_used_in_a_published_questionnaire_creates_a_duplicate_question(self):
        self.questionnaire.status = Questionnaire.PUBLISHED
        self.questionnaire.save()
        data = self.form_data.copy()
        history_form = QuestionForm(data=data, instance=self.question1)

        self.assertTrue(history_form.is_valid())

        history_form.save()

        questions = Question.objects.filter(UID=self.question1.UID)

        self.assertEqual(2, questions.count())
        self.failUnless(questions.filter(**data))
开发者ID:eJRF,项目名称:ejrf,代码行数:14,代码来源:test_questions_form.py


示例14: test_save_multichoice_question_saves_options

    def test_save_multichoice_question_saves_options(self):
        options = ['Yes', 'No', 'Maybe']
        form = {'text': 'How many kids were immunised this year?',
                'instructions': 'Some instructions',
                'short_instruction': 'short version',
                'export_label': 'blah',
                'answer_type': 'MultiChoice',
                'options': options}

        question_form = QuestionForm(data=form)
        question = question_form.save(commit=True)
        question_options = QuestionOption.objects.filter(question=question)

        self.assertEqual(3, question_options.count())
        [self.assertIn(question_option.text, options) for question_option in question_options]
开发者ID:testvidya11,项目名称:ejrf,代码行数:15,代码来源:test_questions_form.py


示例15: test_form_invalid_if_multipleresponse_question_is_primary

    def test_form_invalid_if_multipleresponse_question_is_primary(self):
        options = ['', 'Yes', 'No', 'Maybe']
        form = {'text': 'How many kids were immunised this year?',
                'instructions': 'Some instructions',
                'short_instruction': 'short version',
                'export_label': 'blah',
                'answer_type': AnswerTypes.MULTIPLE_RESPONSE,
                'is_primary': 'true',
                'options': options,
                'theme': self.theme.id}
        question_form = QuestionForm(data=form)

        self.assertFalse(question_form.is_valid())
        message = "%s questions cannot be primary" % AnswerTypes.MULTIPLE_RESPONSE
        self.assertIn(message, question_form.errors['is_primary'][0])
开发者ID:eJRF,项目名称:ejrf,代码行数:15,代码来源:test_questions_form.py


示例16: post

 def post(self, request, *args, **kwargs):
     region = self.request.user.user_profile.region
     self.form = QuestionForm(region=region, data=request.POST)
     self.form.question_options = map(lambda o: str(o), dict(request.POST).get('options', []))
     if self.form.is_valid():
         return self._form_valid()
     return self._form_invalid()
开发者ID:eJRF,项目名称:ejrf,代码行数:7,代码来源:questions.py


示例17: test_save__multipleresponse_question_saves_listed_options

    def test_save__multipleresponse_question_saves_listed_options(self):
        options = ['', 'Yes', 'No', 'Maybe']
        form = {'text': 'How many kids were immunised this year?',
                'instructions': 'Some instructions',
                'short_instruction': 'short version',
                'export_label': 'blah',
                'answer_type': AnswerTypes.MULTIPLE_RESPONSE,
                'options': options,
                'theme': self.theme.id}

        question_form = QuestionForm(data=form)
        question = question_form.save(commit=True)
        question_options = QuestionOption.objects.filter(question=question)

        self.assertEqual(3, question_options.count())
        [self.assertIn(question_option.text, ['Yes', 'No', 'Maybe']) for question_option in question_options]
开发者ID:eJRF,项目名称:ejrf,代码行数:16,代码来源:test_questions_form.py


示例18: test_multichoice_options_are_only_edited_in_the_duplicate_questions

    def test_multichoice_options_are_only_edited_in_the_duplicate_questions(self):
        self.questionnaire.status = Questionnaire.PUBLISHED
        self.questionnaire.save()
        self.question1.orders.create(order=1, question_group=self.parent_group)
        self.question1.answer_type = 'MultiChoice'
        self.question1.save()
        question1_options_texts = ["Yes", "No", "DK"]
        for text in question1_options_texts:
            self.question1.options.create(text=text)

        draft_questionnaire = Questionnaire.objects.create(name="draft qnaire", description="haha",
                                                           status=Questionnaire.DRAFT)
        section_1 = Section.objects.create(title="section 1", order=1, questionnaire=draft_questionnaire, name="ha")
        sub_section_1 = SubSection.objects.create(title="subs1", order=1, section=section_1)
        parent_group_d = QuestionGroup.objects.create(subsection=sub_section_1, name="group")
        parent_group_d.question.add(self.question1)
        self.question1.orders.create(order=2, question_group=parent_group_d)

        finalized_questionnaire = Questionnaire.objects.create(name="finalized qnaire", description="haha",
                                                               status=Questionnaire.FINALIZED)
        section_1_f = Section.objects.create(title="section 1", order=1, questionnaire=finalized_questionnaire,
                                             name="ha")
        sub_section_1_f = SubSection.objects.create(title="subs1", order=1, section=section_1_f)
        parent_group_f = QuestionGroup.objects.create(subsection=sub_section_1_f, name="group")
        parent_group_f.question.add(self.question1)
        self.question1.orders.create(order=3, question_group=parent_group_f)

        changed_options = ['', 'haha', 'hehe', 'hihi']
        data = {'text': 'changed text',
                'instructions': 'Some instructions',
                'export_label': 'blah',
                'answer_type': 'MultiChoice',
                'theme': self.theme.id,
                'options': changed_options}

        history_form = QuestionForm(data=data, instance=self.question1)

        self.assertTrue(history_form.is_valid())
        duplicate_question = history_form.save()

        question1_options = self.question1.options.all()
        self.assertEqual(3, question1_options.count())
        [self.assertIn(question_option.text, question1_options_texts) for question_option in question1_options]

        duplicate_question_options = duplicate_question.options.all()
        self.assertEqual(3, duplicate_question_options.count())
        [self.assertIn(question_option.text, changed_options) for question_option in duplicate_question_options]
开发者ID:eJRF,项目名称:ejrf,代码行数:47,代码来源:test_questions_form.py


示例19: post

 def post(self, request, *args, **kwargs):
     region = self.request.user.user_profile.region
     self.form = QuestionForm(region=region, data=request.POST)
     if self.form.is_valid():
         return self._form_valid()
     return self._form_invalid()
开发者ID:remo4sam,项目名称:ejrf,代码行数:6,代码来源:questions.py


示例20: test_clean_export_label

 def test_clean_export_label(self):
     data = self.form_data.copy()
     data['export_label'] = ''
     question_form = QuestionForm(data=data)
     self.assertFalse(question_form.is_valid())
     self.assertIn("All questions must have export label.", question_form.errors['export_label'])
开发者ID:eJRF,项目名称:ejrf,代码行数:6,代码来源:test_questions_form.py



注:本文中的questionnaire.forms.questions.QuestionForm类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python users.UserQuestionnaireService类代码示例发布时间:2022-05-26
下一篇:
Python question.Question类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap