[Zope] How to add valuables into Property sheets from a form?
J. Cameron Cooper
cameron.cooper@pantellos.com
Fri, 22 Jun 2001 18:28:31 -0500
I'm replying to the list as well so that everybody can read and comment.
I don't pretend to speak with any authority wrt Zope, and need peer
review to keep from becoming a gigantic liar.
I wish there were a builtin way to integrate builtin property sheets,
both inherited and peer, because that would greatly simplify maintenance
of ZClass management stuff. But there isn't, and here's the setup when
you're making custom "property sheets":
(I'm not claiming this is the best design, but here goes...)
--You have a dtml method with the requisite HTML form for your
properties in your product folder and in your ZClass. I don't think
acquisition helps us here.
--You have several property sheets, either inherited or defined, that
you want in a unified interface.
--You have a ZClass-made add method in your product folder (a constructor).
--You have an edit method in your ZClass.
In the add/edit form, the action for the Submit button should be the add
or edit method, depending on where it is. The names of the form elements
(HTML inputs) should be the names of the properties in your property
sheets you want to add/change. When you submit this form, the method it
is submitted to gets a REQUEST object with keys named for the form
elements, each associated with the value in the element when the form
was submitted. You can see these in the URL line when you submit with GET.
So it comes to the add method, which creates a new object in the
dtml-with, then works in its namespace. While in the new object's
namespace you can:
--set the properties of your property sheets. Call
"propertysheets.PROPERTYSHEETNAME.manage_changeProperties(REQUEST)" for
each property sheet. You are handing the REQUEST that your form gave you
to this method, which will then change all the attributes in its
property sheet that match keys in the REQUEST to the values that those
keys correspond to. Read the ZClass source to see exactly how. The edit
method is little less kind, and DC folks have said that it's not meant
for public consumption.
--set it to be aware of a non-default Catalog: use dtml-call with
manage_editCataloger to set it, and the call index to add it. (I think
editCataloger should do this itself. Perhaps someone could tell me why I
shouldn't patch it to index to a new catalog if the catalog actually
changes.) This should be done after the properties are changed.
Typically you then redirect to whatever page should come after clicking
submit. The ZClass constructor does this for you.
You will do the same thing in your edit method, except you will not make
a new object, and you're already in the appropriate namespace. You can
do this in a DTML method patterened after the ZClass constructor, but
this is where PythonScripts are good. One might look something like:
<pre>
# Keep in mind I'm making this up off the top of my head. I'll verify it
against my code later...
context.propertysheets.PROPERTYSHEETNAME1.manage_changeProperties(REQUEST)
context.propertysheets.PROPERTYSHEETNAME2.manage_changeProperties(REQUEST)
return REQUEST.RESPONSE.redirect(location)
</pre>
Easy huh?
So then you just go into the ZClass management interface and add your
edit method to a tab, test it out, and you're done.
Issues:
--am I wrong? It seems to work for me.
--is there a more maintainable design? Dunno, I'd have to experiment.
--jcc
(yay for objects!)
[barring errors or severe criticism, I'll probably be making this a
howto soon.]
Oops Oops wrote:
> Hello Cooper:
> Thanks been so kind to respond my post.
>
> I still have few questions if you don't mind to answer
> me? : )
>
> "ropertysheets.PROPERTYSHEETNAME.manage_changeProperties(REQUEST)"
> I understand half part of it but got lost at (REQUEST)
> Do I need to list all the valuables that I have in my
> form in (here?) or I should list properties in there??
> I try both changeProperties and editProperties and
> none of them work. ~_~
>
> Also in my DTML form
> <form method="POST" action=" ">
> where I should call in the action? My Zclass
> constructor? Or??
>
> I don't know how to write a PythonScrip, sigh
> otherwise I think it would be very easy right?
>
> Thanks again for your help
>
> -Ann