[Zope] ZClass edit with a PythonScript

Tim Wilson wilson@isis.visi.com
Mon, 22 Apr 2002 22:08:40 -0500 (CDT)


On Mon, 22 Apr 2002, Tim Wilson wrote:

> I've built a more user-friendly edit form for a ZClass-based product.
> Now I'd like to use a PythonScript as the action of the form to actually
> process the changes. I think I'm 90% there, but I can't figure out how
> to refer to the object that needs to be changed in the Script. In the
> current version (included below), I'm referring to the object as
> 'newsitem', but how to I connect that name with the object itself?

Doh! It never fails. If you can't figure something out, just post the
question to the Zope list. The answer will come to you within 10 minutes
of posting. :-)

For the record, here's a PythonScript that you can use as the action of
an edit form that will modify a ZClass's properties based on the
contents of the edit form. It also reindexes the object.

-Tim

## Script (Python) "doEdit"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Edit a NewsClass instance
##
"""Modify a ZClass instance based on form input."""
REQUEST = container.REQUEST
context.propertysheets.Basic.manage_changeProperties(REQUEST)
context.reindex_object()

RESPONSE = REQUEST.RESPONSE
if REQUEST.has_key('DestinationURL'):
  return
RESPONSE.redirect(REQUEST['DestinationURL']+'/manage_workspace')
return RESPONSE.redirect(REQUEST['URL2']+'/manage_workspace')

--
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com