本文整理匯總了Python中questionnaire.forms.questions.QuestionForm.is_valid方法的典型用法代碼示例。如果您正苦於以下問題:Python QuestionForm.is_valid方法的具體用法?Python QuestionForm.is_valid怎麽用?Python QuestionForm.is_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類questionnaire.forms.questions.QuestionForm
的用法示例。
在下文中一共展示了QuestionForm.is_valid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_editing_question_used_in_an_unpublished_questionnaire_updates_question
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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)
示例2: QuestionForm
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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())
示例3: CreateQuestion
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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)
示例4: CreateQuestion
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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)
示例5: test_clean_answer_number_sub_type_valid
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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)
示例6: test_edit_removes_deleted_options_from_the_question
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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]
示例7: test_form_invalid_if_multichoice_question_and_no_options_in_data_options
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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])
示例8: test_duplicate_question_maintains_region
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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)
示例9: test_form_invalid_if_multipleresponse_question_and_no_options_in_data_options
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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])
示例10: test_editing_question_used_in_a_published_questionnaire_creates_a_duplicate_question
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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))
示例11: test_form_invalid_if_multipleresponse_question_is_primary
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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])
示例12: test_multichoice_options_are_only_edited_in_the_duplicate_questions
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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]
示例13: test_clean_export_label
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
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'])
示例14: test_clean_answer_date_sub_type
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
def test_clean_answer_date_sub_type(self):
data = self.form_data.copy()
data['answer_type'] = AnswerTypes.DATE
question_form = QuestionForm(data=data)
self.assertFalse(question_form.is_valid())
self.assertIn("This field is required if you select '%s'" % AnswerTypes.DATE, question_form.errors['answer_sub_type'])
示例15: test_clean_answer_type
# 需要導入模塊: from questionnaire.forms.questions import QuestionForm [as 別名]
# 或者: from questionnaire.forms.questions.QuestionForm import is_valid [as 別名]
def test_clean_answer_type(self):
data = self.form_data.copy()
data['answer_type'] = ''
question_form = QuestionForm(data=data)
self.assertFalse(question_form.is_valid())
self.assertIn("This field is required.", question_form.errors['answer_type'])