跳转到主要内容

Zope 3的可插拔显示名称扩展。

项目描述

适配器

默认显示名称生成器

默认显示名称生成器简单地取一个Dublin Core标题或一个__name__并返回它,如果需要则截断。它使用一个辅助函数,convertName,旨在使编写其他显示名称生成器更容易。

目前还没有提供使用HTML的IBrowserDisplayNameGenerator接口的帮助。

给定一个可以被适配到zope.dublincore.interfaces.IDCDescriptiveProperties的ILocation,并且实际上具有该值,它返回DC标题;否则,它使用__name__。

>>> import zope.dublincore.interfaces
>>> import zope.location.interfaces
>>> from zc.displayname import interfaces, adapters
>>> from zope.interface import verify
>>> from zope import interface
>>> class Dummy(object):
...     interface.implements(zope.location.interfaces.ILocation)
...     def __init__(self, parent, name):
...         self.__parent__ = parent
...         self.__name__ = name
...
>>> d = Dummy('parent', 'a name')
>>> from zope.publisher.browser import TestRequest
>>> g = adapters.DefaultDisplayNameGenerator(d, TestRequest())
>>> verify.verifyObject(interfaces.IDisplayNameGenerator, g)
True
>>> g()
'a name'
>>> g('foo')
Traceback (most recent call last):
...
TypeError: ('maxlength must be int', 'foo')
>>> g(-1)
Traceback (most recent call last):
...
ValueError: ('maxlength must be 0 or greater', -1)
>>> g(4)
'a...'
>>> g(6)
'a name'
>>> g(2)
'??'
>>> interface.directlyProvides(
...     d, zope.dublincore.interfaces.IDCDescriptiveProperties)
>>> d.title = 'My Special Dummy'
>>> d.description = 'My interface said I had to have this'
>>> verify.verifyObject(
...     zope.dublincore.interfaces.IDCDescriptiveProperties, d)
True
>>> g()
'My Special Dummy'
>>> g(0)
''
>>> g(100)
'My Special Dummy'
>>> g(16)
'My Special Dummy'
>>> g(15)
'My Special D...'

由以下支持