[Zope] PropertySheets again (QUEST)

Oscar Picasso picasso@videotron.ca
Mon, 27 Mar 2000 09:49:05 -0500


> > 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.