[Zope] ZClasses meet PythonScripts, sample request

Jim Washington jwashin@vt.edu
Sun, 14 Jan 2001 23:49:49 -0500


Hi, Tim

> >
> > You will want to pass REQUEST to it so you can use it like the Zope
> > builtins:
> >
> > containerName.CDInfoName.manage_changeCDProperties(REQUEST)
> >
> > So, put REQUEST in the parameters list.
> 
> I'm afraid I'm a bit confused here. Is 'CDInfoName' the id of an instance of
> this CD class? If so, what would 'containerName' be?

Yes.  CDInfoName here would be an instance of your CD Class. 
containerName is the name of the container, whether it be a folder or a
folderish ZClass made for handling a collection of CD Class objects.  It
doesn't have to be there in the statement unless something else is
asking the folderish object to ask the CD Class object to change the
properties, which at the moment seems kind of silly.  I must have gotten
off on containers with your second question about deletion. Apologies
for the confusion.
 
> In the particular example I'm thinking about (not a CD collection), I've
> created a form that displays the current properties of the class (a job
> opening for the H.R. deparment in my case), allows the user to modify any of
> the properties in the form, and submit those changes. I suppose for the CD
> example it would something like: (ignoring everything but the form)
> 
> <form action="manage_changeCDProperties(REQUEST)">
> <table border="0">
> 
> <tr><th>Title</th>
>   <td><input type="text" name="title" value="<dtml-var title>"></td>
> </tr>
> 
> <tr><th>Artist</th>
>   <td><input type="text" name="artist" value="<dtml-var artist>"></td>
> </tr>
> 
> <tr><td>
> <input type="submit" value=" Submit Edits ">
> </td></tr>
> </table>
> </form>
> 
> I don't think I'm calling the PythonScript correctly. In fact, I suspect I'm
> quite a bit off.

I think it would work, at least as far as updating the properties, but
it would not  return anything. See below my attempt at an alternative.

> > Inside the script, you would use Zope's manage_changeProperties method:
> >
> > context.propertysheets['cd_info'].manage_changeProperties(REQUEST)
> > -or-
> > context.propertysheets.cd_info.manage_changeProperties(REQUEST)
> 
> Following Evan's advice, would this then be:
> 
> container.propertysheets['cd_info'].manage_changeProperties(REQUEST)
> 
> So that's a one-liner? Hmmm. Cool if true. :-)

Always has been, even in DTML. 
 
> Let's say that I wanted to redirect the user back to the Web page where they
> had begun this process. How would that be accomplished?

There are many ways.  I like to make it all happen at the beginning of
the DTML Method.
Hacking up the form you provided above (lines with ! have been added or
changed):

!<dtml-var standard_html_header>

!<dtml-if "REQUEST.form.has_key('editCD')">
!  <dtml-call "manage_changeCDProperties(REQUEST)">
!  <p><font color="red">Your changes have been saved</font></p>
!</dtml-if>

!<form action="replace_this_with_id_of_this_method">
 <table border="0">
 
 <tr><th>Title</th>
  <td><input type="text" name="title" value="<dtml-var title>"></td>
 </tr>
 
 <tr><th>Artist</th>
   <td><input type="text" name="artist" value="<dtml-var artist>"></td>
 </tr>
 
 <tr><td>
! <input type="submit" name="editCD" value=" Submit Edits ">
 </td></tr>
 </table>
 </form>
!<dtml-var standard_html_footer>

Hoping I have not confused further,

-- Jim Washington

> > Timothy Wilson wrote:
> > >
> > > Hi everyone,
> > >
> > > I'm looking forward to using some PythonScripts as methods of some ZClasses
> > > because it seems like a much cleaner way to do things. I wonder if one of
> > > the PythonScript gurus out there would be willing to show an example of two
> > > presumably common PythonScript/ZClass tasks: processing changes to a
> > > property sheet using form input and deleting a ZClass instance.
> > >
> > > Let's say we've got a ZClass for keeping track of a CD collection. (I recall
> > > seeing that example in a ZClass How-To.) Let's say the ZClass has a property
> > > sheet called 'cd_info' with the following properties:
> > >
> > > title (string)
> > > artist (string)
> > > date_purchased (date)
> > >
> > > (for extra credit, add a 'songs' property of type 'lines' :-)
> > >
> > > Is that enough info? Anybody want to take a crack at this? (This would
> > > surely be good info to put at zope.org somewhere.)
> > >
> > > -Tim