为z3c.form提供的optgroup小部件。
项目描述
介绍
此包实现了一个将选择值分组到optgroups的小部件。
用法
想象你有一个以下架构
class IMySchema(Interface): country = schema.Choice( required=True, title=u"Country", vocabulary='countries', ) subdivision = schema.Choice( required=True, title=u"State", vocabulary='subdivisions', ) region = schema.Choice( required=True, title=u"County", vocabulary='regions', )
当你创建你的词汇表(例如,使用SimpleVocabulary)时,而不是添加SimpleTerm项
... for country in pycountry.countries: terms.append(SimpleTerm(value=country.alpha2, token=country.alpha2, title=country.name)) ...
你添加OptgroupTerm项
from z3c.formwidget.optgroup.widget import OptgroupTerm ... country_list = countries(context) for item in pycountry.subdivisions: parent = country_list.getTermByToken(item.country_code).title terms.append(OptgroupTerm(value=item.code, token=item.code, title=item.name, optgroup=parent)) ...
在您的表单中,只需分配OptgroupFieldWidget。
from z3c.formwidget.optgroup.widget import OptgroupFieldWidget class MyForm(form.Form): fields = field.Fields(IMySchema) fields['subdivision'].widgetFactory = OptgroupFieldWidget fields['region'].widgetFactory = OptgroupFieldWidget
贡献者
托马斯·马斯曼,作者
变更日志
1.2 (2012-05-01)
修复了显示模式模板中错误的HTML标签。[托马斯·马斯曼]
1.1 (2012-04-26)
始终将无值消息作为第一条显示。[托马斯·马斯曼]
1.0.1 (2012-04-14)
MANIFEST.in缺少一些条目。[托马斯·马斯曼]
1.0 (2012-04-14)
首次发布。[托马斯·马斯曼]
项目详情
关闭
z3c.formwidget.optgroup-1.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f1de0a23bb87d4aa0661eba563052be399884ea46cdffc7663b62594f146d146 |
|
MD5 | 4e40890d4a1ebf930b2078889a69749c |
|
BLAKE2b-256 | 214a871e97e3530ed010ac2ddb85dd4087105bff4773cd7bb7ff4243fcf4de74 |