[Zope-CMF] Re: Custom factories?

yuppie y.2008 at wcm-solutions.de
Mon Mar 3 17:45:31 EST 2008

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.




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.

     title = u'HTML document'
     description = u'An HTML document.'

     def __call__(self, *args, **kw):
         item = Document(*args, **kw)


         return item

     def getInterfaces(self):
         return implementedBy(Document)

HTMLDocumentFactory = _HTMLDocumentFactory()

More information about the Zope-CMF mailing list