本文整理汇总了Python中pyramid_simpleform.renderers.FormRenderer.select方法的典型用法代码示例。如果您正苦于以下问题:Python FormRenderer.select方法的具体用法?Python FormRenderer.select怎么用?Python FormRenderer.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_simpleform.renderers.FormRenderer
的用法示例。
在下文中一共展示了FormRenderer.select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_select_with_options_obj
# 需要导入模块: from pyramid_simpleform.renderers import FormRenderer [as 别名]
# 或者: from pyramid_simpleform.renderers.FormRenderer import select [as 别名]
def test_select_with_options_obj(self):
from pyramid_simpleform import Form
from pyramid_simpleform.renderers import FormRenderer
request = testing.DummyRequest()
form = Form(request, SimpleFESchema, defaults={"name": "ValueFred"})
renderer = FormRenderer(form)
options = Options(
[
OptGroup("OptGroup", [Option(value="ValueOG", label="LabelOG")]),
Option(value="ValueFred", label="LabelFred"),
Option(value="ValueBarney", label="LabelBarney"),
Option(value="ValueWilma", label="LabelWilma"),
Option(value="ValueBetty", label="LabelBetty"),
]
)
self.assertTrue(
renderer.select("name", options)
== """<select id="name" name="name">
<optgroup label="OptGroup">
<option value="ValueOG">LabelOG</option>
</optgroup>
<option selected="selected" value="ValueFred">LabelFred</option>
<option value="ValueBarney">LabelBarney</option>
<option value="ValueWilma">LabelWilma</option>
<option value="ValueBetty">LabelBetty</option>
</select>"""
)
示例2: test_select
# 需要导入模块: from pyramid_simpleform.renderers import FormRenderer [as 别名]
# 或者: from pyramid_simpleform.renderers.FormRenderer import select [as 别名]
def test_select(self):
from pyramid_simpleform import Form
from pyramid_simpleform.renderers import FormRenderer
request = testing.DummyRequest()
form = Form(request, SimpleFESchema, defaults={"name": "Fred"})
renderer = FormRenderer(form)
options = [("Fred", "Fred"), ("Barney", "Barney"), ("Wilma", "Wilma"), ("Betty", "Betty")]
self.assert_(
renderer.select("name", options)
== """<select id="name" name="name">
<option selected="selected" value="Fred">Fred</option>
<option value="Barney">Barney</option>
<option value="Wilma">Wilma</option>
<option value="Betty">Betty</option>
</select>"""
)
示例3: test_select_webhelpers1_compatible
# 需要导入模块: from pyramid_simpleform.renderers import FormRenderer [as 别名]
# 或者: from pyramid_simpleform.renderers.FormRenderer import select [as 别名]
def test_select_webhelpers1_compatible(self):
from pyramid_simpleform import Form
from pyramid_simpleform.renderers import FormRenderer
request = testing.DummyRequest()
form = Form(request, SimpleFESchema, defaults={"name": "Fred"})
renderer = FormRenderer(form)
self.assertTrue(
renderer.select("currency", [["$", "Dollar"], ["DKK", "Kroner"]], "$")
== """<select id="currency" name="currency">
<option selected="selected" value="$">Dollar</option>
<option value="DKK">Kroner</option>
</select>"""
)
self.assertTrue(
renderer.select("cc", ["VISA", "MasterCard"], "MasterCard", id="cc", class_="blue")
== """<select class="blue" id="cc" name="cc">
<option value="VISA">VISA</option>
<option selected="selected" value="MasterCard">MasterCard</option>
</select>"""
)
self.assertTrue(
renderer.select("cc", ["VISA", "MasterCard", "Discover"], ["VISA", "Discover"])
== """<select id="cc" name="cc">
<option selected="selected" value="VISA">VISA</option>
<option value="MasterCard">MasterCard</option>
<option selected="selected" value="Discover">Discover</option>
</select>"""
)
self.assertTrue(
renderer.select("currency", [["$", "Dollar"], ["DKK", "Kroner"]], None, prompt="Please choose ...")
== """<select id="currency" name="currency">
<option selected="selected" value="">Please choose ...</option>
<option value="$">Dollar</option>
<option value="DKK">Kroner</option>
</select>"""
)
try:
if isinstance(long, type):
self.assertTrue(
renderer.select("privacy", [(1, "Private"), (2, "Semi-public"), (3, "Public")], long(3))
== """<select id="privacy" name="privacy">
<option value="1">Private</option>
<option value="2">Semi-public</option>
<option selected="selected" value="3">Public</option>
</select>"""
)
except NameError:
self.assertTrue(
renderer.select("privacy", [(1, "Private"), (2, "Semi-public"), (3, "Public")], 3)
== """<select id="privacy" name="privacy">
<option value="1">Private</option>
<option value="2">Semi-public</option>
<option selected="selected" value="3">Public</option>
</select>"""
)
self.assertTrue(
renderer.select(
"recipients",
[([("u1", "User1"), ("u2", "User2")], "Users"), ([("g1", "Group1"), ("g2", "Group2")], "Groups")],
None,
)
== """<select id="recipients" name="recipients">
<optgroup label="Users">
<option value="u1">User1</option>
<option value="u2">User2</option>
</optgroup>
<optgroup label="Groups">
<option value="g1">Group1</option>
<option value="g2">Group2</option>
</optgroup>
</select>"""
)