[Zope-CMF] how to get the object created by invokeFactory
seb bacon
seb@jamkit.com
Tue, 3 Jul 2001 15:47:12 +0100
* Chris Withers <chrisw@nipltd.com> [010703 15:06]:
> seb bacon wrote:
> >
> > Really? It's a useful feature, and it only takes a couple of lines of
> > code (some keyword arguments in the class constructor, and the factory
> > method). It should stay, IMO - I use it a bit. Why would you *not*
> > want it?
>
> Because it leads to lots of unneccessary code duplication, which means an
> increased chance of bugs...
>
> What you really want is a constructor that does nothing but build the object and
> an edit methdo which fills in all the details.
> That way, you don't have 'editing' code in both the __init__ and edit methods.
OK, that makes sense :-)
The reason I find it useful is because I'm munging the the id in
invokeFactory to make sure it's a valid ZopeId, then passing the id in
as the title, intact. (we were discussing this a while ago).
So, if I call invokeFactory(id), I can't necessarily know what the id
actually was, so I can't grab the object to edit it. Wouldn't
something like this avoid the code duplication problem you mention:
def __init__(self, id, **kw):
# blah
self._getOb(id).edit(**kw)
seb