Skip to main content

A Zope 3 extension for pluggable display names.

Project description

Adapters

Default Display Name Generator

The default display name generator simply takes a Dublin Core title or a __name__ and returns it, truncated if desired. It uses a helper function intended to make writing other display name generators easier, convertName.

No help is offered yet for using HTML with the IBrowserDisplayNameGenerator interface.

Given an ILocation that can be adapted to zope.dublincore.interfaces.IDCDescriptiveProperties, and that actually has a value for it, it returns the DC title; otherwise, it uses __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...'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zc.displayname-1.1.tar.gz (8.4 kB view details)

Uploaded Source

File details

Details for the file zc.displayname-1.1.tar.gz.

File metadata

File hashes

Hashes for zc.displayname-1.1.tar.gz
Algorithm Hash digest
SHA256 146cd8bacd9215d6c27a78ccfe4eef1df3b9c66e456c1e458afed83a805c33c3
MD5 68bf950b0c2e7e8d4bd890b57e034f62
BLAKE2b-256 cf3fd70c09ded3ffa3019a0d82aa3ba2bd98b77605e6e8fbce70631542f3e0a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page