本文整理汇总了Python中forms.TestForm.helper方法的典型用法代码示例。如果您正苦于以下问题:Python TestForm.helper方法的具体用法?Python TestForm.helper怎么用?Python TestForm.helper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.TestForm
的用法示例。
在下文中一共展示了TestForm.helper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_error_and_help_inline
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_error_and_help_inline(self):
form = TestForm({'email': 'invalidemail'})
form.helper = FormHelper()
form.helper.error_text_inline = False
form.helper.help_text_inline = True
form.helper.layout = Layout('email')
form.is_valid()
html = render_crispy_form(form)
# Check that help goes before error, otherwise CSS won't work
if settings.CRISPY_TEMPLATE_PACK == 'bootstrap':
help_position = html.find('<span id="hint_id_email" class="help-inline">')
error_position = html.find('<p id="error_1_id_email" class="help-block">')
self.assertTrue(help_position < error_position)
# Viceversa
form = TestForm({'email': 'invalidemail'})
form.helper = FormHelper()
form.helper.error_text_inline = True
form.helper.help_text_inline = False
form.helper.layout = Layout('email')
form.is_valid()
html = render_crispy_form(form)
# Check that error goes before help, otherwise CSS won't work
if settings.CRISPY_TEMPLATE_PACK == 'bootstrap':
error_position = html.find('<span id="error_1_id_email" class="help-inline">')
help_position = html.find('<p id="hint_id_email" class="help-block">')
self.assertTrue(error_position < help_position)
示例2: test_html5_required
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_html5_required(self):
form = TestForm()
form.helper = FormHelper()
form.helper.html5_required = True
html = render_crispy_form(form)
# 6 out of 7 fields are required and an extra one for the SplitDateTimeWidget makes 7.
self.assertEqual(html.count('required="required"'), 7)
form = TestForm()
form.helper = FormHelper()
form.helper.html5_required = False
html = render_crispy_form(form)
示例3: test_form_show_errors_non_field_errors
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_form_show_errors_non_field_errors(self):
form = TestForm({'password1': 'wargame', 'password2': 'god'})
form.helper = FormHelper()
form.helper.form_show_errors = True
form.is_valid()
template = get_template_from_string(u"""
{% load crispy_forms_tags %}
{% crispy testForm %}
""")
# First we render with errors
c = Context({'testForm': form})
html = template.render(c)
# Ensure those errors were rendered
self.assertTrue('<li>Passwords dont match</li>' in html)
self.assertTrue(unicode(_('This field is required.')) in html)
self.assertTrue('error' in html)
# Now we render without errors
form.helper.form_show_errors = False
c = Context({'testForm': form})
html = template.render(c)
# Ensure errors were not rendered
self.assertFalse('<li>Passwords dont match</li>' in html)
self.assertFalse(unicode(_('This field is required.')) in html)
self.assertFalse('error' in html)
示例4: test_multiwidget_field
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_multiwidget_field(self):
template = get_template_from_string(
u"""
{% load crispy_forms_tags %}
{% crispy form %}
"""
)
test_form = TestForm()
test_form.helper = FormHelper()
test_form.helper.layout = Layout(
MultiWidgetField(
"datetime_field",
attrs=({"rel": "test_dateinput"}, {"rel": "test_timeinput", "style": "width: 30px;", "type": "hidden"}),
)
)
c = Context({"form": test_form})
html = template.render(c)
self.assertEqual(html.count('class="dateinput"'), 1)
self.assertEqual(html.count('rel="test_dateinput"'), 1)
self.assertEqual(html.count('rel="test_timeinput"'), 1)
self.assertEqual(html.count('style="width: 30px;"'), 1)
self.assertEqual(html.count('type="hidden"'), 1)
示例5: test_field_with_buttons
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_field_with_buttons(self):
form = TestForm()
form.helper = FormHelper()
form.helper.layout = Layout(
FieldWithButtons(
Field("password1", css_class="span4"),
StrictButton("Go!", css_id="go-button"),
StrictButton("No!", css_class="extra"),
StrictButton("Test", type="submit", name="whatever", value="something"),
css_class="extra",
autocomplete="off",
)
)
html = render_crispy_form(form)
self.assertEqual(html.count('class="control-group extra"'), 1)
self.assertEqual(html.count('autocomplete="off"'), 1)
self.assertEqual(html.count('class="input-append"'), 1)
self.assertEqual(html.count('class="span4'), 1)
self.assertEqual(html.count('id="go-button"'), 1)
self.assertEqual(html.count("Go!"), 1)
self.assertEqual(html.count("No!"), 1)
self.assertEqual(html.count('class="btn"'), 2)
self.assertEqual(html.count('class="btn extra"'), 1)
self.assertEqual(html.count('type="submit"'), 1)
self.assertEqual(html.count('name="whatever"'), 1)
self.assertEqual(html.count('value="something"'), 1)
if settings.CRISPY_TEMPLATE_PACK == "bootstrap":
# Make sure white spaces between buttons are there in bootstrap
self.assertEqual(len(re.findall(r"</button> <", html)), 3)
示例6: test_form_show_errors
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_form_show_errors(self):
form = TestForm(
{
"email": "invalidemail",
"first_name": "first_name_too_long",
"last_name": "last_name_too_long",
"password1": "yes",
"password2": "yes",
}
)
form.helper = FormHelper()
form.helper.layout = Layout(
AppendedText("email", "whatever"),
PrependedText("first_name", "blabla"),
AppendedPrependedText("last_name", "foo", "bar"),
MultiField("legend", "password1", "password2"),
)
form.is_valid()
form.helper.form_show_errors = True
html = render_crispy_form(form)
self.assertEqual(html.count("error"), 6)
form.helper.form_show_errors = False
html = render_crispy_form(form)
self.assertEqual(html.count("error"), 0)
示例7: test_form_show_errors_non_field_errors
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_form_show_errors_non_field_errors(self):
form = TestForm({"password1": "wargame", "password2": "god"})
form.helper = FormHelper()
form.helper.form_show_errors = True
form.is_valid()
template = get_template_from_string(
u"""
{% load crispy_forms_tags %}
{% crispy testForm %}
"""
)
# First we render with errors
c = Context({"testForm": form})
html = template.render(c)
# Ensure those errors were rendered
self.assertTrue("<li>Passwords dont match</li>" in html)
self.assertTrue(unicode(_("This field is required.")) in html)
self.assertTrue("error" in html)
# Now we render without errors
form.helper.form_show_errors = False
c = Context({"testForm": form})
html = template.render(c)
# Ensure errors were not rendered
self.assertFalse("<li>Passwords dont match</li>" in html)
self.assertFalse(unicode(_("This field is required.")) in html)
self.assertFalse("error" in html)
示例8: test_getitem_by_field_name
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_getitem_by_field_name(self):
form = TestForm()
form.helper = FormHelper(form)
layout = Layout(Div("email"), "password1")
form.helper.layout = layout
form.helper["email"].wrap(Field, css_class="hero")
self.assertTrue(isinstance(layout.fields[0].fields[0], Field))
示例9: test_multiwidget_field
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_multiwidget_field(self):
template = get_template_from_string(u"""
{% load crispy_forms_tags %}
{% crispy form %}
""")
test_form = TestForm()
test_form.helper = FormHelper()
test_form.helper.layout = Layout(
MultiWidgetField(
'datetime_field',
attrs=(
{'rel': 'test_dateinput'},
{'rel': 'test_timeinput', 'style': 'width: 30px;', 'type': "hidden"}
)
)
)
c = Context({'form': test_form})
html = template.render(c)
self.assertEqual(html.count('class="dateinput"'), 1)
self.assertEqual(html.count('rel="test_dateinput"'), 1)
self.assertEqual(html.count('rel="test_timeinput"'), 1)
self.assertEqual(html.count('style="width: 30px;"'), 1)
self.assertEqual(html.count('type="hidden"'), 1)
示例10: test_exclude_by_widget
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_exclude_by_widget(self):
form = TestForm()
form.helper = FormHelper(form)
form.helper.layout = self.advanced_layout
self.assertEqual(
form.helper.exclude_by_widget(forms.PasswordInput).slice,
[[[0, 0, 0, 0], "email"], [[0, 3, 0], "first_name"], [[1], "last_name"]],
)
示例11: test_attrs
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_attrs(self):
form = TestForm()
form.helper = FormHelper()
form.helper.attrs = {'id': 'TestIdForm', 'autocomplete': "off"}
html = render_crispy_form(form)
self.assertTrue('autocomplete="off"' in html)
self.assertTrue('id="TestIdForm"' in html)
示例12: test_filter_by_widget
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_filter_by_widget(self):
form = TestForm()
form.helper = FormHelper(form)
form.helper.layout = self.advanced_layout
self.assertEqual(form.helper.filter_by_widget(forms.PasswordInput).slice, [
[[0, 1, 0, 0], 'password1'],
[[0, 4, 0], 'password2'],
])
示例13: test_getitem_by_field_name
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_getitem_by_field_name(self):
form = TestForm()
form.helper = FormHelper(form)
layout = Layout(
Div('email'),
'password1',
)
form.helper.layout = layout
form.helper['email'].wrap(Field, css_class='hero')
self.assertTrue(isinstance(layout.fields[0].fields[0], Field))
示例14: test_exclude_by_widget_and_wrap
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_exclude_by_widget_and_wrap(self):
form = TestForm()
form.helper = FormHelper(form)
form.helper.layout = self.advanced_layout
form.helper.exclude_by_widget(forms.PasswordInput).wrap(Field, css_class='hero')
# Check wrapped fields
self.assertTrue(isinstance(form.helper.layout[0][0][0][0], Field))
self.assertTrue(isinstance(form.helper.layout[0][3][0], Field))
self.assertTrue(isinstance(form.helper.layout[1], Field))
# Check others stay the same
self.assertTrue(isinstance(form.helper.layout[0][3][1], HTML))
self.assertTrue(isinstance(form.helper.layout[0][1][0][0], basestring))
self.assertTrue(isinstance(form.helper.layout[0][4][0], basestring))
示例15: test_filter_by_widget
# 需要导入模块: from forms import TestForm [as 别名]
# 或者: from forms.TestForm import helper [as 别名]
def test_filter_by_widget(self):
form = TestForm()
form.helper = FormHelper(form)
layout = Layout(
Div(
Div(Div('email')),
Div('password1'),
'password2'
)
)
form.helper.layout = layout
form.helper.filter_by_widget(forms.PasswordInput).wrap(Field, css_class='hero')
self.assertTrue(isinstance(layout.fields[0].fields[2], Field))