用户偏好框架 ZMI UI
项目描述
此包提供了一个UI,用于在ZMI中维护分层用户偏好。
zope.app.preference
此包在ZMI中提供了一个用户界面,用户可以编辑偏好。
设置
为了显示用户界面功能,我们需要先进行一些设置
>>> from zope.testbrowser.wsgi import Browser >>> browser = Browser() >>> browser.handleErrors = False
由于偏好不能通过网页定义,我们必须在Python代码中定义它们
>>> import zope.interface >>> import zope.schema >>> class IZMIUserSettings(zope.interface.Interface): ... """Basic User Preferences""" ... ... email = zope.schema.TextLine( ... title=u"E-mail Address", ... description=u"E-mail Address used to send notifications") ... ... skin = zope.schema.Choice( ... title=u"Skin", ... description=u"The skin that should be used for the ZMI.", ... values=['Rotterdam', 'ZopeTop', 'Basic'], ... default='Rotterdam') ... ... showZopeLogo = zope.schema.Bool( ... title=u"Show Zope Logo", ... description=u"Specifies whether Zope logo should be displayed " ... u"at the top of the screen.", ... default=True) >>> class INotCategorySettings(zope.interface.Interface): ... """An example that's not a categary""" ... comment = zope.schema.TextLine( ... title=u'A comment', ... description=u'A description')
偏好模式通常使用ZCML语句进行注册
>>> from zope.configuration import xmlconfig >>> import zope.preference >>> context = xmlconfig.file('meta.zcml', zope.preference)>>> context = xmlconfig.string(''' ... <configure ... xmlns="http://namespaces.zope.org/zope" ... i18n_domain="test"> ... ... <preferenceGroup ... id="ZMISettings" ... title="ZMI Settings" ... schema="zope.app.preference.README.IZMIUserSettings" ... category="true" ... /> ... ... <preferenceGroup ... id="NotCategory" ... title="Not Category" ... schema="zope.app.preference.README.INotCategorySettings" ... category="false" ... /> ... ... </configure>''', context)
编辑偏好
偏好可在++preferences++命名空间中访问
>>> browser.open('https://127.0.0.1/++preferences++')
页面显示一个表单,允许编辑偏好值
>>> browser.getControl("comment").value = "A comment" >>> browser.getControl('E-mail').value = 'hans@example.com' >>> browser.getControl('Skin').displayOptions ['Rotterdam', 'ZopeTop', 'Basic'] >>> browser.getControl('Skin').displayValue = ['ZopeTop'] >>> browser.getControl('Show Zope Logo').selected True >>> browser.getControl('Show Zope Logo').click()
选择“更改”后,值将被保存
>>> browser.getControl('Change').click() >>> browser.url 'https://127.0.0.1/++preferences++/@@index.html' >>> browser.getControl('E-mail').value 'hans@example.com' >>> browser.getControl('Skin').displayValue ['ZopeTop'] >>> browser.getControl('Show Zope Logo').selected False
偏好分组以树形结构显示。它有一个到表单的链接
>>> browser.getLink('ZMISettings').click() >>> browser.url 'https://127.0.0.1/++preferences++/ZMISettings/@@index.html' >>> browser.getControl('E-mail').value 'hans@example.com'
偏好分组树
如果可以创建完整的偏好,那么偏好将不会很有力。因此,让我们为ZMI用户设置创建一个子组,我们可以在其中调整文件夹内容视图的外观和感觉
>>> class IFolderSettings(zope.interface.Interface): ... """Basic Folder Settings""" ... ... shownFields = zope.schema.Set( ... title=u"Shown Fields", ... description=u"Fields shown in the table.", ... value_type=zope.schema.Choice(['name', 'size', 'creator']), ... default=set(['name', 'size'])) ... ... sortedBy = zope.schema.Choice( ... title=u"Sorted By", ... description=u"Data field to sort by.", ... values=['name', 'size', 'creator'], ... default='name')
并注册它
>>> context = xmlconfig.string(''' ... <configure ... xmlns="http://namespaces.zope.org/zope" ... i18n_domain="test"> ... ... <preferenceGroup ... id="ZMISettings.Folder" ... title="Folder Content View Settings" ... schema="zope.app.preference.README.IFolderSettings" ... /> ... ... </configure>''', context)
子组在父组内部以表单的形式显示
>>> browser.reload() >>> browser.getControl('Shown Fields').displayOptions ['name', 'size', 'creator'] >>> browser.getControl('Shown Fields').displayValue ['name', 'size'] >>> browser.getControl('Shown Fields').displayValue = ['size', 'creator'] >>> browser.getControl('Sorted By').displayOptions ['name', 'size', 'creator'] >>> browser.getControl('Sorted By').displayValue = ['creator']
选择 更改 也会保留这些值。
>>> browser.getControl('Change').click() >>> browser.getControl('Shown Fields').displayValue ['size', 'creator'] >>> browser.getControl('Sorted By').displayValue ['creator'] >>> browser.open("https://127.0.0.1/++preferences++/ZMISettings.Folder/@@index.html")
变更记录
4.1.0 (2022-08-05)
添加对 Python 3.7、3.8、3.9、3.10 的支持。
取消对 Python 3.4 的支持。
4.0.0 (2017-05-17)
添加对 Python 3.4、3.5、3.6 和 PyPy 的支持。
移除了对 zope.app.zcmlfiles 和 zope.app.renderer 等的测试依赖。其中 zope.app.renderer 在运行时仍需。
通过使用 zope.app.wsgi.testlayer 取消了对 zope.app.testing 的测试依赖。
3.8.1 (2010-06-15)
修复了指向不存在的 zope.preferences 包的 BBB 导入。
3.8.0 (2010-06-12)
依赖于分离出的 zope.preference。
3.7.0 (2010-06-11)
为 ZMI 表单添加了 HTML 标签。
移除了 edit.pt,因为它似乎未被使用。
添加了对 ZMI 视图的测试。
3.6.0 (2009-02-01)
使用 zope.container 而不是 zope.app.container。
3.5.0 (2009-01-17)
移除了 zope.app.zapi 依赖,并用原始位置的直接导入替换其使用。
将邮寄地址从 zope3-dev 更改为 zope-dev,因为第一个现在已弃用。
修复了针对 python 2.6 的测试。
移除了针对基于 mkzopeinstance 的旧实例的 zpkg 东西和 zcml 包含文件。
3.4.1 (2007-10-30)
避免了对 ZopeMessageFactory 的弃用警告。
3.4.0 (2007-10-25)
首次发布独立于主 Zope 树。
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分发
构建分发
散列 for zope.app.preference-4.1.0-py2.py3-none-any.whl
算法 | 散列摘要 | |
---|---|---|
SHA256 | 97e518339dd543c8ba477e81cb6c0e4cd050d24ad7304cf7f480fdbe595aec33 |
|
MD5 | 7a9f98f18102f0022f5f6ada34049c2a |
|
BLAKE2b-256 | 4f4e1495d9d5330c103455aa248800fd7239a5b700ac3adccf88b53e60bdbce5 |