本文整理汇总了Python中floppyforms.templatetags.floppyforms.FormConfig类的典型用法代码示例。如果您正苦于以下问题:Python FormConfig类的具体用法?Python FormConfig怎么用?Python FormConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_change_widget
def test_change_widget(self):
form = SimpleForm()
config = FormConfig()
config.configure('widget', forms.PasswordInput(), filter=ConfigFilter(form['name']))
self.assertHTMLEqual(render("""{% form myform using %}
{% formfield form.name %}
{% endform %}""", {'myform': form}, config), """<input type="password" name="name" id="id_name" />""")
示例2: test_field_filter_works_on_subclasses
def test_field_filter_works_on_subclasses(self):
form = RegistrationForm()
config = FormConfig()
config.configure("widget", widgets.HiddenInput(), filter=ConfigFilter("IntegerField"))
widget = config.retrieve("widget", bound_field=form["age"])
self.assertEqual(widget.__class__, widgets.HiddenInput)
示例3: test_filter_for_field_class_name
def test_filter_for_field_class_name(self):
form = RegistrationForm()
config = FormConfig()
config.configure('widget', widgets.TextInput(), filter=ConfigFilter('CharField'))
widget = config.retrieve('widget', bound_field=form['comment'])
self.assertEqual(widget.__class__, widgets.TextInput)
widget = config.retrieve('widget', bound_field=form['name'])
self.assertEqual(widget.__class__, widgets.TextInput)
示例4: test_retrieve_for_multiple_valid_values
def test_retrieve_for_multiple_valid_values(self):
form = RegistrationForm()
config = FormConfig()
config.configure("widget", widgets.Textarea(), filter=ConfigFilter("CharField"))
config.configure("widget", widgets.HiddenInput(), filter=ConfigFilter("short_biography"))
widget = config.retrieve("widget", bound_field=form["name"])
self.assertEqual(widget.__class__, widgets.Textarea)
widget = config.retrieve("widget", bound_field=form["comment"])
self.assertEqual(widget.__class__, widgets.Textarea)
# we get HiddenInput since this was configured last, even the Textarea
# config applies to ``short_biography``
widget = config.retrieve("widget", bound_field=form["short_biography"])
self.assertEqual(widget.__class__, widgets.HiddenInput)
示例5: test_filter_for_name_object
def test_filter_for_name_object(self):
form = RegistrationForm()
config = FormConfig()
config.configure('widget', widgets.Textarea(), filter=ConfigFilter('object'))
widget = config.retrieve('widget', bound_field=form['email'])
self.assertEqual(widget.__class__, widgets.EmailInput)
widget = config.retrieve('widget', bound_field=form['name'])
self.assertEqual(widget.__class__, widgets.TextInput)
widget = config.retrieve('widget', bound_field=form['comment'])
self.assertEqual(widget.__class__, widgets.Textarea)
示例6: test_default_retrieve
def test_default_retrieve(self):
"""
Test if FormConfig returns the correct default values if no
configuration was made.
"""
form = RegistrationForm()
config = FormConfig()
# retrieve widget
widget = config.retrieve('widget', bound_field=form['name'])
self.assertTrue(isinstance(widget, widgets.TextInput))
self.assertEqual(widget, form.fields['name'].widget)
widget = config.retrieve('widget', bound_field=form['comment'])
self.assertTrue(isinstance(widget, widgets.Textarea))
self.assertEqual(widget, form.fields['comment'].widget)
# retrieve widget template
template_name = config.retrieve('widget_template', bound_field=form['name'])
self.assertEqual(template_name, 'floppyforms/input.html')
template_name = config.retrieve('widget_template', bound_field=form['comment'])
self.assertEqual(template_name, 'floppyforms/textarea.html')
# retrieve label
label = config.retrieve('label', bound_field=form['email'])
self.assertEqual(label, 'Email')
label = config.retrieve('label', bound_field=form['name'])
self.assertEqual(label, 'First- and Lastname')
# retrieve help text
help_text = config.retrieve('help_text', bound_field=form['name'])
self.assertFalse(help_text)
help_text = config.retrieve('help_text', bound_field=form['email'])
self.assertEqual(help_text, 'Please enter a valid email.')
# retrieve row template
template = config.retrieve('row_template', fields=(form['name'], form['email'],))
self.assertEqual(template, 'floppyforms/rows/default.html')
# retrieve form layout
template = config.retrieve('layout', forms=(form,))
self.assertEqual(template, 'floppyforms/layouts/default.html')
示例7: test_retrieve_all
def test_retrieve_all(self):
config = FormConfig()
config.configure('number', 1)
config.configure('number', 2)
self.assertEqual(list(config.retrieve_all('number')), [2, 1])
config.configure('number', 4, filter=lambda nr=None, **kwargs: nr == 'four')
self.assertEqual(list(config.retrieve_all('number')), [2, 1])
self.assertEqual(list(config.retrieve_all('number', nr='four')), [4, 2, 1])
config.push()
config.configure('number', 5, filter=lambda nr=None, **kwargs: nr == 'five')
self.assertEqual(list(config.retrieve_all('number')), [2, 1])
self.assertEqual(list(config.retrieve_all('number', nr='five')), [5, 2, 1])
config.configure('number', -1)
self.assertEqual(list(config.retrieve_all('number')), [-1, 2, 1])
self.assertEqual(list(config.retrieve_all('number', nr='four')), [-1, 4, 2, 1])
self.assertEqual(list(config.retrieve_all('number', nr='five')), [-1, 5, 2, 1])
config.pop()
self.assertEqual(list(config.retrieve_all('number')), [2, 1])
self.assertEqual(list(config.retrieve_all('number', nr='four')), [4, 2, 1])
self.assertEqual(list(config.retrieve_all('number', nr='five')), [2, 1])
示例8: test_stacked_config
def test_stacked_config(self):
form = RegistrationForm()
config = FormConfig()
config.push()
config.configure(
'widget', widgets.Textarea(),
filter=ConfigFilter("CharField"),
)
config.push()
config.configure(
'widget', widgets.HiddenInput(),
filter=ConfigFilter('short_biography'),
)
widget = config.retrieve('widget', bound_field=form['short_biography'])
self.assertEqual(widget.__class__, widgets.HiddenInput)
config.pop()
widget = config.retrieve('widget', bound_field=form['short_biography'])
self.assertEqual(widget.__class__, widgets.Textarea)
config.pop()
widget = config.retrieve('widget', bound_field=form['short_biography'])
self.assertEqual(widget.__class__, widgets.TextInput)
示例9: test_default_retrieve
def test_default_retrieve(self):
"""
Test if FormConfig returns the correct default values if no
configuration was made.
"""
form = RegistrationForm()
config = FormConfig()
# retrieve widget
widget = config.retrieve("widget", bound_field=form["name"])
self.assertTrue(isinstance(widget, widgets.TextInput))
self.assertEqual(widget, form.fields["name"].widget)
widget = config.retrieve("widget", bound_field=form["comment"])
self.assertTrue(isinstance(widget, widgets.Textarea))
self.assertEqual(widget, form.fields["comment"].widget)
# retrieve widget template
template_name = config.retrieve("widget_template", bound_field=form["name"])
self.assertEqual(template_name, "floppyforms/text.html")
template_name = config.retrieve("widget_template", bound_field=form["comment"])
self.assertEqual(template_name, "floppyforms/textarea.html")
# retrieve label
label = config.retrieve("label", bound_field=form["email"])
self.assertEqual(label, "Email")
label = config.retrieve("label", bound_field=form["name"])
self.assertEqual(label, "First- and Lastname")
# retrieve help text
help_text = config.retrieve("help_text", bound_field=form["name"])
self.assertFalse(help_text)
help_text = config.retrieve("help_text", bound_field=form["email"])
self.assertEqual(help_text, "Please enter a valid email.")
# retrieve row template
template = config.retrieve("row_template", fields=(form["name"], form["email"]))
self.assertEqual(template, "floppyforms/rows/default.html")
# retrieve form layout
template = config.retrieve("layout", forms=(form,))
self.assertEqual(template, "floppyforms/layouts/default.html")