import zope.interface import zope.component from zope.component.factory import Factory from zope.size.interfaces import ISized from zope.i18nmessageid import MessageFactory _ = MessageFactory('sfive') try: from OFS.SimpleItem import SimpleItem except ImportError: from persistent import Persistent as SimpleItem from sfive.interfaces import IPresentation class Presentation(SimpleItem): zope.interface.implements(IPresentation) title = u'' presenter = u'' affiliation = u'' location = u'' text = u'' PresentationFactory = Factory(Presentation) class PresentationSize(object): """Size adapter for `Presentation`. Size for sorting: >>> presentation = Presentation() >>> presentation.text = u'Bla bla bla' >>> size = PresentationSize(presentation) >>> size.sizeForSorting() ('byte', 11) Size for display: >>> from zope.app.tests.placelesssetup import setUp, tearDown >>> from zope.i18n import translate >>> setUp() >>> translate(size.sizeForDisplay()) u'11 characters' >>> tearDown() """ zope.interface.implements(ISized) zope.component.adapts(IPresentation) def __init__(self, context): self.context = context def sizeForSorting(self): return ('byte', len(self.context.text)) def sizeForDisplay(self): unit, chars = self.sizeForSorting() return _('${chars} characters', mapping={'chars': chars})