Re: [Zope] PropertySheets again (QUEST)
Oscar Picasso <picasso@videotron.ca> asks:
As I didn't receive any answer from my previous message, I guess it wasn't very clear.
How can I get a list of property.ids, property.types of a ZClass propertysheet from outside the product containing my ZClass.
Look at how Zope's management interface does it ($ZOPE_HOME/lib/python/OFS/properties.dtml). Tres. -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Palladion Software http://www.palladion.com
As I didn't receive any answer from my previous message, I guess it wasn't very clear.
How can I get a list of property.ids, property.types of a ZClass propertysheet from outside the product containing my ZClass.
Look at how Zope's management interface does it ($ZOPE_HOME/lib/python/OFS/properties.dtml).
Thanks for your input.However I'm not sure that i really understand it. I guessed that in that method the key element is popertyMap. So I tried: <dtml-var propertyMap> in my zclass_addForm. When i tried to add a myzclass instance anywhere in the ZODB hierearchy i get: ({'id': 'title', 'type': 'string'},) Not exactly what i wanted. I wanted to get the ids and types of the propertysheets properties. Here is the purpose. I found that the default method of adding ZClass instance is boring. The form asks you to type the id, then you can add your instance and after that go to the propertysheets/myproperty/manage method to fill the propertysheets properties. I think that most of the times it's better to fill these properties when you create the instance. So i began to modify each time, the addForm to include the propertysheets properties in its form. It worked fine but each time i create new ZClass i have to modify manually the addForm. So i tried to create a generic addForm that could work with any kind of ZClass no matter what are the propertysheets properties. That's why i wanted to get the ids end types of the propertysheets properties of a ZClass from outside the ZClass. I can do that by creating an instance, taking the needed information from that instance to generate automatically the addForm, creating a new instance with the addForm then deleting the instance from where i got the required information about the propertysheets. It works fine but it's not very elegant and may a source of potentiel problems. Here is a "addForm" code that works: <form action="ebook_add" method="post" enctype="multipart/form-data"> <table> <tr> <th align=right>Id</th> <td><input type=text width=25 name=id></td> </tr> <tr> <th align=right>Title</th> <td><input type=text width=25 name=title></td> </tr> <tr> <th align=right>Image</th> <td><input type=file width=25 name=file></td> </tr> <dtml-call "REQUEST.set('id', 'provisoire')"> <dtml-call "REQUEST.set('title', 'tprov')"> <dtml-call "REQUEST.set('file', '/home/oscar/zop')"> <dtml-with "ebook.createInObjectManager(REQUEST['id'], REQUEST)"> <dtml-in "propertysheets.info.propertyMap()"> <dtml-let id="_['sequence-item']['id']"> <dtml-let type="_['sequence-item']['type']"> <tr> <th align="right"><dtml-var "_.string.upper(id)[0]+id[1:]"></th> <td> <dtml-if "type=='text'"> <textarea name=<dtml-var id> cols=50 rows=15></textarea> <dtml-else> <input type=text width=25 name=<dtml-var id>:<dtml-var type>> </dtml-if> </td> </tr> </dtml-let> </dtml-let> </dtml-in> </dtml-with> <dtml-call "manage_delObjects('provisoire')"> <tr> <td></td> <td><input type=submit width=25 value=" Add "></td> </tr> </table> </form> </body> </html> ******************* Another possible solution would be to create a new instance with temporary id and title, get from that instance the propertysheets properties ids and types, make the form and from the fields of the form fill the propertysheets properties and change the temporary id and title. But as the previous solution, it's not elegant. I think it would be much better to be able to get the propertysheets properties ids and types from outside a ZClass. That's what i was looking for. As i understand it the properties.dtml method is called from inside an instance so I'm not sure it will solve the problem. And I did Sorry for being too long and thanks for your patience.
Oscar Picasso wrote:
As I didn't receive any answer from my previous message, I guess it wasn't very clear.
How can I get a list of property.ids, property.types of a ZClass propertysheet from outside the product containing my ZClass.
Look at how Zope's management interface does it ($ZOPE_HOME/lib/python/OFS/properties.dtml).
Thanks for your input.However I'm not sure that i really understand it. I guessed that in that method the key element is popertyMap. So I tried: <dtml-var propertyMap> in my zclass_addForm.
To use the propertysheet before you have an instance, you need to get the Product into the namespace stack, something like this (untested, but I do stuff like this elsewhere):: <dtml-with "manage_addProduct[ 'MyZClassProduct' ]"> <dtml-in "MyZClass.propertysheets.info.propertyMap()"> .... </dtml-in> </dtml-with> -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Now also: tseaver@digicool.com Palladion Software http://www.palladion.com
To use the propertysheet before you have an instance, you need to get the Product into the namespace stack, something like this (untested, but I do stuff like this elsewhere)::
<dtml-with "manage_addProduct[ 'MyZClassProduct' ]"> <dtml-in "MyZClass.propertysheets.info.propertyMap()"> .... </dtml-in> </dtml-with>
Thanks again, I tested it. .... <dtml-in "MyZClass.propertysheets.info.propertyMap()"> ..... gives: Error Type: AttributeError Error Value: info .... <dtml-in "MyZClass.propertysheets.common.info.propertyMap()"> ..... produces: a Netscape confirm box: ******************** Authorization failed. Retry? [ok] [cancel] ******************** Then, no matter where I click, i am prompted to enter my username and password, and if i provide the right one, i get the Unauthorized error message from Zope. That's the strange thing i don't understand. However i found a solution that seems not that bad: <dtml-in "Control_Panel.Products.CAProduct.ca.propertysheets.common.info.propertyMap()"> A little long, but it works. Thanks again
On Mon, 27 Mar 2000, Oscar Picasso wrote:
I think that most of the times it's better to fill these properties when you create the instance. So i began to modify each time, the addForm to include the propertysheets properties in its form. It worked fine but each time i create new ZClass i have to modify manually the addForm. So i tried to create a generic addForm that could work with any kind of ZClass no matter what are the propertysheets properties.
I think this would be a useful addition to the Zope core...I find myself doing the same thing and I've been thinking about developing the generic add form but haven't had time to even start it. --RDM
participants (3)
-
Oscar Picasso -
R. David Murray -
Tres Seaver