[Zope3-Users] Re: NotYet error when creating content during container creation
Jürgen Kartnaller wrote: I've also tried to create the subfolders in a subscriber on IObjectCreatedEvent, but this is equivalent to the previous attempt : NotYet error. What I've understood is that the transaction that manages the folder is not finished, and the IntId utility is not yet able to get a connection on the ZODB. So I've tried to create an adapter to IConnection for my subfolder, so that it can use the same connection as the folder. But I couldn't. (however it might be possible?). 'NotYet' happens if the object in not connected to a database. The connection to the database exists as soon as your object is added to the object tree in zope. It is not related to a finished transaction. That's not entirely true. The problem's origin is in zope.app.keyreference. In order to give newly created objects an integer id, the objects need to be adaptable to IKeyReference. The IKeyReference adapter for persistnet objects wants access to the object's database ("pickle jar"). Now, if the object has already been persisted before in an *already committed transaction*, it will have a _p_jar attribute. So, if the transaction were in fact finished, the IKeyReference adapter could take the object's _p_jar attribute right away. But since the transaction isn't over yet and the object was just created, it has no _p_jar attribute, so the IKeyReference adapter does a bit of guessing. It walks up the __parent__ hierarchy and figures that if the newly created object is part of a container somewhere, it will be persisted in the same database. So it takes the container's _p_jar. This is the reason why IKeyReference wants an intact __parent__ hierarchy for newly created objects. The simple solution is to create the subfolders AFTER the folder has been eventually ADDED with the add method. So in the AddForm, I've replaced the create() method with a createAndAdd method. In this method, I've just created my folder, called add to add it, then only I could create the subfolders and add them to the folder. You can also do this using an event handler for ObjectAddedEvent on your Folder. In this case you do not need to touch any code in your form. Yes, this is what I'd recommend. A handler for an ObjectAddedEvent will always see the object already as part of the object hierarchy (which is, after all, what ObjectAddedEvent is about). -- http://worldcookery.com -- Professional Zope documentation and training Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: NotYet error when creating content during container creation
Jürgen Kartnaller a écrit : Christophe Combelles wrote: Hello, I've been spending several hours on a problem which is probably trivial for advanced zope3ers, but it was not for me, so I'm posting the solution in case it's useful for someone (I've not found anything on it). http://mail.zope.org/pipermail/zope3-users/2005-November/001494.html The problem: I want to create a folder, and when this folder is created, several subfolders should be automatically created. And I have a IntId utility. (this is part of the problem). First, I've tried to create the subfolders in the __init__ method of the folder being created. It does not work and fails with a NotYet error. Then, I've tried to create the subfolders in the create method of the AddForm, after the folder has been eventually created. Still too early: NotYet error. I've also tried to create the subfolders in a subscriber on IObjectCreatedEvent, but this is equivalent to the previous attempt : NotYet error. What I've understood is that the transaction that manages the folder is not finished, and the IntId utility is not yet able to get a connection on the ZODB. So I've tried to create an adapter to IConnection for my subfolder, so that it can use the same connection as the folder. But I couldn't. (however it might be possible?). 'NotYet' happens if the object in not connected to a database. The connection to the database exists as soon as your object is added to the object tree in zope. It is not related to a finished transaction. The simple solution is to create the subfolders AFTER the folder has been eventually ADDED with the add method. So in the AddForm, I've replaced the create() method with a createAndAdd method. In this method, I've just created my folder, called add to add it, then only I could create the subfolders and add them to the folder. You can also do this using an event handler for ObjectAddedEvent on your Folder. In this case you do not need to touch any code in your form. ah of course yes, thanks! I've been looking for any ObjectAddedEvent in livecycleevent, but this event is obviously notified by containers, so it's in the container package. And this is much better to have an event, since I won't have to duplicate the subfolders creation if I have several add forms. Jürgen ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Re: NotYet error when creating content during container creation
Christophe Combelles wrote: Hello, I've been spending several hours on a problem which is probably trivial for advanced zope3ers, but it was not for me, so I'm posting the solution in case it's useful for someone (I've not found anything on it). http://mail.zope.org/pipermail/zope3-users/2005-November/001494.html The problem: I want to create a folder, and when this folder is created, several subfolders should be automatically created. And I have a IntId utility. (this is part of the problem). First, I've tried to create the subfolders in the __init__ method of the folder being created. It does not work and fails with a NotYet error. Then, I've tried to create the subfolders in the create method of the AddForm, after the folder has been eventually created. Still too early: NotYet error. I've also tried to create the subfolders in a subscriber on IObjectCreatedEvent, but this is equivalent to the previous attempt : NotYet error. What I've understood is that the transaction that manages the folder is not finished, and the IntId utility is not yet able to get a connection on the ZODB. So I've tried to create an adapter to IConnection for my subfolder, so that it can use the same connection as the folder. But I couldn't. (however it might be possible?). 'NotYet' happens if the object in not connected to a database. The connection to the database exists as soon as your object is added to the object tree in zope. It is not related to a finished transaction. The simple solution is to create the subfolders AFTER the folder has been eventually ADDED with the add method. So in the AddForm, I've replaced the create() method with a createAndAdd method. In this method, I've just created my folder, called add to add it, then only I could create the subfolders and add them to the folder. You can also do this using an event handler for ObjectAddedEvent on your Folder. In this case you do not need to touch any code in your form. Jürgen ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] NotYet error when creating content during container creation
Hello, I've been spending several hours on a problem which is probably trivial for advanced zope3ers, but it was not for me, so I'm posting the solution in case it's useful for someone (I've not found anything on it). The problem: I want to create a folder, and when this folder is created, several subfolders should be automatically created. And I have a IntId utility. (this is part of the problem). First, I've tried to create the subfolders in the __init__ method of the folder being created. It does not work and fails with a NotYet error. Then, I've tried to create the subfolders in the create method of the AddForm, after the folder has been eventually created. Still too early: NotYet error. I've also tried to create the subfolders in a subscriber on IObjectCreatedEvent, but this is equivalent to the previous attempt : NotYet error. What I've understood is that the transaction that manages the folder is not finished, and the IntId utility is not yet able to get a connection on the ZODB. So I've tried to create an adapter to IConnection for my subfolder, so that it can use the same connection as the folder. But I couldn't. (however it might be possible?). The simple solution is to create the subfolders AFTER the folder has been eventually ADDED with the add method. So in the AddForm, I've replaced the create() method with a createAndAdd method. In this method, I've just created my folder, called add to add it, then only I could create the subfolders and add them to the folder. All logic and no magic makes zope3 a great toy :) Christophe ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Problem with macro
On Sun, Feb 25, 2007 at 02:02:43PM +0100, Florian Lindner wrote: > I have a simple problem. A template: > > > > > > > > [...] > > > > > > > > That is registered as view.html. How? ? > Now I want to use the macro in another page: > > div metal:use-macro="context/Blog/@@view.html/Blog" /> > > (tried different variations) Ah, but did you try metal:use-macro="context/Blog/@@view.html/index/macros/Blog" /> ? When you attach a page template to a view with ZCML, it defines a view attribute 'index' behind the scenes. So, @@view.html refers to the view, @@view.html/index revers to the template, and @@view.html/index/macros refers to the macros defined in that template. Marius Gedminas -- For every complex problem, there is a solution that is simple, neat, and wrong signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Problem with macro
Florian Lindner a écrit : Hello, I have a simple problem. A template: [...] I'm not good with METAL (I'm trying to mainly use viewlets), but is it really valid to have use-macro and define-macro in the same template? I'm only using define-macro followed by define-slot, or use-macro followed by fill-slot. Is it possible to mix all this? Christophe That is registered as view.html. Now I want to use the macro in another page: div metal:use-macro="context/Blog/@@view.html/Blog" /> (tried different variations) but that always causes a system error because the macro could not be found. Thanks, Florian ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Problem with macro
Hello, I have a simple problem. A template: [...] That is registered as view.html. Now I want to use the macro in another page: div metal:use-macro="context/Blog/@@view.html/Blog" /> (tried different variations) but that always causes a system error because the macro could not be found. Thanks, Florian ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users