本文整理匯總了Python中questionnaire.forms.questions.QuestionForm類的典型用法代碼示例。如果您正苦於以下問題:Python QuestionForm類的具體用法?Python QuestionForm怎麽用?Python QuestionForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QuestionForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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())
示例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]
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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])
示例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)
示例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])
示例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))
示例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]
示例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])