
y.2008 at wcm-solutions
Mar 3, 2008, 2:45 PM
Post #2 of 5
(353 views)
Permalink
|
Hi Charlie! Charlie Clark wrote: > I've been working on some very lightweight content types that differ > minimally from each other so I'd like to use attributes rather than > different classes. I've come across a couple of problems while working > on this: if I put the attributes into the factory I need to make my > basic object into a callable because it gets called when the factory > gets registered. > > Currently I have something like this: > > class SpecialDocument: > def __init__(self, **kw): > pass > > def __call__(self, text_type=None): > self.text_type = text_type > > HTMLDocFactory = Factory(SpecialDocument(text_type='text/html') > PlainTextDocFactory = Factory(SpecialDocument(text_type='text/plain') > > This is extended with additional registrations of the content class with > additional meta_types. Do you mean you use different meta types for one class? There should not be a need for that. One meta type can be used for several portal types. I attached a custom factory for plain CMF documents that sets the initial text format to 'html'. Maybe that code helps you. Cheers, Yuppie ----------------------------------------------------- from zope.interface import implementedBy from zope.interface import implements from zope.component.interfaces import IFactory from Products.CMFDefault.Document import Document class _HTMLDocumentFactory(object): """Creates an HTML document. """ implements(IFactory) title = u'HTML document' description = u'An HTML document.' def __call__(self, *args, **kw): item = Document(*args, **kw) item.setFormat('html') return item def getInterfaces(self): return implementedBy(Document) HTMLDocumentFactory = _HTMLDocumentFactory() _______________________________________________ Zope-CMF maillist - Zope-CMF[at]lists.zope.org http://mail.zope.org/mailman/listinfo/zope-cmf See http://collector.zope.org/CMF for bug reports and feature requests
|