本文整理汇总了Python中floppyforms.templatetags.floppyforms.FormConfig.retrieve方法的典型用法代码示例。如果您正苦于以下问题:Python FormConfig.retrieve方法的具体用法?Python FormConfig.retrieve怎么用?Python FormConfig.retrieve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类floppyforms.templatetags.floppyforms.FormConfig
的用法示例。
在下文中一共展示了FormConfig.retrieve方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stacked_config
# 需要导入模块: from floppyforms.templatetags.floppyforms import FormConfig [as 别名]
# 或者: from floppyforms.templatetags.floppyforms.FormConfig import retrieve [as 别名]
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)
示例2: test_filter_for_field_class_name
# 需要导入模块: from floppyforms.templatetags.floppyforms import FormConfig [as 别名]
# 或者: from floppyforms.templatetags.floppyforms.FormConfig import retrieve [as 别名]
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)
示例3: test_default_retrieve
# 需要导入模块: from floppyforms.templatetags.floppyforms import FormConfig [as 别名]
# 或者: from floppyforms.templatetags.floppyforms.FormConfig import retrieve [as 别名]
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')
示例4: test_default_retrieve
# 需要导入模块: from floppyforms.templatetags.floppyforms import FormConfig [as 别名]
# 或者: from floppyforms.templatetags.floppyforms.FormConfig import retrieve [as 别名]
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")
示例5: test_filter_for_name_object
# 需要导入模块: from floppyforms.templatetags.floppyforms import FormConfig [as 别名]
# 或者: from floppyforms.templatetags.floppyforms.FormConfig import retrieve [as 别名]
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_retrieve_for_multiple_valid_values
# 需要导入模块: from floppyforms.templatetags.floppyforms import FormConfig [as 别名]
# 或者: from floppyforms.templatetags.floppyforms.FormConfig import retrieve [as 别名]
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)
示例7: test_field_filter_works_on_subclasses
# 需要导入模块: from floppyforms.templatetags.floppyforms import FormConfig [as 别名]
# 或者: from floppyforms.templatetags.floppyforms.FormConfig import retrieve [as 别名]
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)