用户首选项框架zmi ui

zope.app.preference的Python项目详细描述


这个包提供了一个ui来维护分层的用户首选项 在ZMI中。

zope.app.preference

这个包在zmi中提供了一个用户界面,因此用户可以编辑 偏好。

Set up

要显示用户界面功能,我们需要事先进行一些设置:

>>> from zope.testbrowser.wsgi import Browser
>>> browser = Browser()
>>> browser.handleErrors = False

由于无法通过Web定义首选项,我们必须定义 它们在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)

Editing Preferences

可以在++preferences++命名空间中访问这些首选项:

>>> browser.open('http://localhost/++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()

选择Change后,值将被持久化:

>>> browser.getControl('Change').click()
>>> browser.url
'http://localhost/++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
'http://localhost/++preferences++/ZMISettings/@@index.html'
>>> browser.getControl('E-mail').value
'hans@example.com'

Preference Group Trees

如果您可以创建一个完整的 偏好。因此,让我们为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']

选择Change也会保持这些值:

>>> browser.getControl('Change').click()
>>> browser.getControl('Shown Fields').displayValue
['size', 'creator']
>>> browser.getControl('Sorted By').displayValue
['creator']
>>> browser.open("http://localhost/++preferences++/ZMISettings.Folder/@@index.html")

CHANGES

4.0.0 (2017-05-17)

  • 添加对python 3.4、3.5、3.6和pypy的支持。
  • 删除了对zope.app.zcmlfileszope.app.renderer,等等。zope.app.renderer仍然 运行时必需。
  • 通过使用 zope.app.wsgi.testlayer

3.8.1 (2010-06-15)

  • 固定BBB导入,指向不存在的{{CD3}} 包裹。

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依赖项,用direct替换了它的用法 从原来的地方进口。
  • 将邮件地址从zope3 dev更改为zope dev,作为第一个 现在退休了。
  • 修复Python2.6的测试。
  • 删除zpkg stuff和zcml include文件 旧的基于mkzopeinstance的实例。

3.4.1 (2007-10-30)

  • 避免对ZopeMessageFactory发出弃用警告。

3.4.0 (2007-10-25)

  • 独立于主zope树的初始发布。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java检查服务器端广告查看(php)   Java将注释的使用限制在某些类型的方法上?   java使用gson重用顶级模型   当Java Spring作为Docker容器运行时,它不会与Concur对话   通过Java在不使用新URL()的情况下加载文件   Dicom4che调用的java结果不显示umlaut字符   java Updatea使用php/codeigniter使用ajax/javascript映射标记   Java8中的javaspringboot@ExceptionHandler未被访问   java如何读取长度未知的用户输入?   EclipseJava在MacBook和OSX上的性能非常差,而在Windows下在同一个单元上的性能就不那么差了,为什么?   java在Lucene查询语法中与+有什么区别   使用Spark和Cassandra Java驱动程序时检测到番石榴问题#1635   java工具栏标题未显示在选项卡式活动中