[Zope-CMF] Custom factories?

Charlie Clark charlie at begeistert.org
Mon Mar 3 16:48:57 EST 2008


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):

	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.

This seems to be the most minimal configuration I can use and seems  
reasonably Pythonic but I'm worried about unexpected side effects and  
whether there is a different way of doing this, ie. using local  
utilities as these content types are going to be site specific. I was  
going to try this approach (similar to the KitchenTools example in  
Philip's book) but wasn't sure about some of the other things I was  
going to need.

Comments much appreciated.

On a personal note: over this last month, thanks to the list but also  
to Philip's and Martin's books I've really started to understand and  
appreciate the Zope 3 approach to stuff: it has a great deal of  
elegance even if it takes a while to get used to!

Charlie Clark
Helmholtzstr. 20
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226

More information about the Zope-CMF mailing list