Adding a TemporaryFolder inside a factory method of a Zope class
Hi all. The scenario We would like to setup a Zope Class, subclassing the OFS.Folder, which has inside a cache. The structure would be something like: MyFolder TemporaryFolder MyFolderCache Therefore, the MyFolderCache cache is inside a temporary folder inside the MyFolder. I've no problem in manually creating this structure. However, we do have problems when we try to do this in a factory method. The factory method is something like: from Products.TemporaryFolder.TemporaryFolder import constructTemporaryFolder def manage_addMyFolderCache(container, id, title='') mfc = MyFolderCache(id, title) container._setObject(id, mfc) def manage_addMyFolder(container, id, title='') mf = MyFolder(id, title) container._setObject(id, mf) constructTemporaryFolder(mf, id='tmp', title='') manage_addMyFolderCache(mf.tmp, id='cache', title='cache') The Problem The problems occur inside manage_addMyFolderCache, when it tries the container._setObject. The error is always an AttributeError, because there is no _setObject. After a brief look at the MountedTemporaryFolder class, I can understand that there is still no folder inside mf.tmp, because the populate has not been called yet. Now the questions: 1)what is the problem which is occuring? 2) how can I do what I want to do in a single transaction? Thanks all for the support Regards Paolo -- Paolo Bizzarri - President - Icube S.r.l. Address: Via Ridolfi 15 - 56124 Pisa (PI), Italy E-mail: p.bizzarri@icube.it Web: http://www.icube.it Phone: (+39) 050 97 02 07 Fax: (+39) 050 31 36 588
Paolo Bizzarri wrote at 2004-8-10 09:44 +0200:
... from Products.TemporaryFolder.TemporaryFolder import constructTemporaryFolder
def manage_addMyFolderCache(container, id, title='') mfc = MyFolderCache(id, title) container._setObject(id, mfc)
The standard way is: destination.manage_addProduct[product_name].constructor(...). When you follow the standard way, you avoid FMEs (Frequently Made Errors) such as the above: "mfc" is not acquisition wrapped!
def manage_addMyFolder(container, id, title='') mf = MyFolder(id, title) container._setObject(id, mf)
constructTemporaryFolder(mf, id='tmp', title='') manage_addMyFolderCache(mf.tmp, id='cache', title='cache')
The Problem
The problems occur inside manage_addMyFolderCache, when it tries the container._setObject. The error is always an AttributeError, because there is no _setObject.
After a brief look at the MountedTemporaryFolder class, I can understand that there is still no folder inside mf.tmp, because the populate has not been called yet.
Now the questions:
1)what is the problem which is occuring?
Did you extend the Zope configuration? Such that you have a second temporary storage that can be mounted at your place?
2) how can I do what I want to do in a single transaction?
I fear you will need your own MountPoint logic that does not depend an preconfigured storages in Zope's configuration file. -- Dieter
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dieter Maurer wrote: | Paolo Bizzarri wrote at 2004-8-10 09:44 +0200: | |>... | |>from Products.TemporaryFolder.TemporaryFolder import constructTemporaryFolder | |>def manage_addMyFolderCache(container, id, title='') |> mfc = MyFolderCache(id, title) |> container._setObject(id, mfc) | | | The standard way is: | | destination.manage_addProduct[product_name].constructor(...). This is part of the problem, but I don't thik is the whole problem. Please take time to review the example I'm including in this mail. You can find the TFProduct, which creates a Folderish object, puts a temporary folder named alfa inside it, and then another folder called cache inside alfa temporary folder. Note that in order to create a TFProduct you've to pass the id argument on the URL... As you can see, I'm using all manage_addProduct calls. However, when I review the result from the ZMI (or whatever) you end up with: tf ~ | ~ +- alfa ~ | ~ +- cache instead of: tf | +- alfa ~ | ~ +- cache which is what I wanted. | When you follow the standard way, you avoid FMEs (Frequently Made Errors) | such as the above: "mfc" is not acquisition wrapped! Shame on *me* for doing a FME and posting on the list :). However, it is also the way to really undestand why things have to be done that way. | | |>2) how can I do what I want to do in a single transaction? | | | I fear you will need your own MountPoint logic that | does not depend an preconfigured storages in Zope's configuration | file. | I don't think so. You can add a temporary folder wherever you want in a Zope installation without any configuration. Also, I'm using Zope 2.6.4, which has not any configuration for the storage (no DBTab here). Thanks for your support. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBHJW4XhfyAQQVoaIRAk0oAJ952Unm3RCzO2dRwR+n21euztiCgwCeKeC9 qg6yNFxZiBJFB16BGfJFWaw= =blqE -----END PGP SIGNATURE-----
Marco Bizzarri wrote at 2004-8-13 12:19 +0200:
... |>2) how can I do what I want to do in a single transaction? | | | I fear you will need your own MountPoint logic that | does not depend an preconfigured storages in Zope's configuration | file. |
I don't think so. You can add a temporary folder wherever you want in a Zope installation without any configuration.
You may be right. However, I see in Zope 2.7: context.registerClass( TemporaryFolder.MountedTemporaryFolder, permission=TemporaryFolder.ADD_TEMPORARY_FOLDER_PERM, icon='www/tempfolder.gif', meta_type='Temporary Folder', constructors=(TemporaryFolder.constructTemporaryFolderForm, TemporaryFolder.constructTemporaryFolder), visibility=0 # dont show this in the add list for 2.7+ (use dbtab) ) Thus, at least Zope 2.7 wants that you use DBTab.
Also, I'm using Zope 2.6.4, which has not any configuration for the storage (no DBTab here).
I no longer have Zope 2.6 and therefore cannot help you further. -- Dieter
participants (3)
-
Dieter Maurer -
Marco Bizzarri -
Paolo Bizzarri