Re: [Zope3-Users] Two content objects' simultaneous adding
Ron Bickers wrote: On Sat May 20 2006 17:09, Ron Bickers wrote: I have two content objects (both are containers) but I cannot add one to another as give here : def create(self, data): square = Square() square.name = data['name'] square.description = data['description'] company = Company() company.name = data['companyname'] company.description = data['companydescription'] square['Comp1'] = company ... return square I did this very thing a couple days ago in 3.3 and it works for me, except that I'm using zope.app.zapi.createObject to create the instances of my content objects. Ok. So now I'm wondering... what's the point in using createObject if I can just create an object the Python way? I guess createObject could be useful in an example such as a generic add-objects menu. In this scenario it's probably be easier to deal with factory names. Otherwise I can't see why you shouldn't do it the python way if it's more direct/explicit. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Two content objects' simultaneous adding
On Mon May 22 2006 20:11, Tom Dossis wrote: Ok. So now I'm wondering... what's the point in using createObject if I can just create an object the Python way? I guess createObject could be useful in an example such as a generic add-objects menu. In this scenario it's probably be easier to deal with factory names. Otherwise I can't see why you shouldn't do it the python way if it's more direct/explicit. So is it true then, if I have a class: class MyObject(object): ... And a factory defined in ZCML: class class=.MyObject factory id=me.MyObject description=Create a new MyObject / /class MyObject() and createObject(me.MyObject) will do the same thing and create the same object? If I recall from Zope 2 development, you couldn't just do the former, but it's been awhile and I remember just enough to taint my mind when working in Zope 3. Thanks! -- Ron ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Two content objects' simultaneous adding
Jonathan wrote: - Original Message - From: baiju m [EMAIL PROTECTED] I have two content objects (both are containers) but I cannot add one to another as give here : ... I don't use zope 3 (yet!) but a quick look at the above code seems to indicate that this is not a zope 3 issue:... square['Comp1'] = company This line treats square as if it were a python dictionary (not an object, which it is!) but he wrote that both are containers. zope3 use __setitem__ as a way to add items to containers, see: zope.app.container.interfaces. class IWriteContainer(Interface): An interface for the write aspects of a container. def __setitem__(name, object): Add the given `object` to the container under the given name...: /JM ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Two content objects' simultaneous adding
On Sat May 20 2006 04:47, baiju m wrote: I have two content objects (both are containers) but I cannot add one to another as give here : def create(self, data): square = Square() square.name = data['name'] square.description = data['description'] company = Company() company.name = data['companyname'] company.description = data['companydescription'] square['Comp1'] = company ... return square It was working in 3.2, now NotYet error is coming in 3.3. Here is the traceback: I did this very thing a couple days ago in 3.3 and it works for me, except that I'm using zope.app.zapi.createObject to create the instances of my content objects. So, maybe this: from zope.proxy import removeAllProxies from zope.app.zapi import createObject def create(self, data): square = removeAllProxies(createObject(uname.of.your.Square.Factory)) square.name = data['name'] square.description = data['description'] company = removeAllProxies(createObject(uname.of.your.Company.Factory)) company.name = data['companyname'] company.description = data['companyanydescription'] square['Comp1'] = company ... return square I'm not sure if/why the removeAllProxies is needed as I stole this procedure from the list archives. Also, I'm about 1 week into my Zope3 development experience, so don't just take my word for it even if it works. :-) -- Ron ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Two content objects' simultaneous adding
On 5/21/06, Tom Dossis [EMAIL PROTECTED] wrote: baiju m wrote: I have two content objects (both are containers) but I cannot add one It was working in 3.2, now NotYet error is coming in 3.3. Here is the traceback: Why the different behaviour b/w versions? Did you have an active IntId utility installed in each version? Installing an IntId utility has an (unfortunate) side effect, which can break previously working code. Whether you can successfully add objects to containers which haven't been persisted yet, depends on the presence of an IntId util. Yes, I have played around with IntId before trying my application. As you said that might be the reason for the strange behaviour. To test this I simple removed my 'Data.fs' and restarted, then added my content object and it was working! Thanks to all those who replied. Regards, Baiju M ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users