[Zope] Why isn't my Python script updating my properties? (code included)
A M Thomas
am@virtueofthesmall.com
Thu, 21 Mar 2002 12:44:45 -0500
Hi there and thanks much for reading this. I'm sure I'm missing some
fundamental point, but I've looked and haven't been able to find help in
the documentation I have. A good example would be helpful, if anyone
can recommend one.
Basically, I've made a ZClass, called SiteSection, in my product. It
has base classes of Folder, CatalogAware, and DTML Document. In a later
version, I'll probably remove the DTML Document base class - I'm not
sure why I included it.
The ZClass has a property sheet (also called SiteSection) with these
properties: title, LastModifiedBy, InSite, MainTextIsDTML,
ContainedObjectsArePages, NavOrder, NavShortDescription, and
NewMenuSection. (Please let me know if I shouldn't define title here).
Also, creating an instance of SiteSection also creates a DTML Document
inside the new instance with the ID of MainText.
I have created a custom management view, currently called
SiteSection_edit, which should allow the user to set most of the
properties in the PropertySheet, as well as update the text in the
MainText object. The form calls a Python script, included below, which
should actually do the updating.
I'm able to update the contents MainText successfully using these
commands:
try: # in case MainText doesn't exist - is there another way?
context.manage_addDTMLMethod('MainText','')
except:
nop = 0;
context.MainText.manage_edit(request['MainText'], '')
I'm trying to set the other properties individually using
manage_changeProperties, for example:
context.manage_changeProperties(NavShortDescription=request['NavShortDescription'])
I think I can do multiple properties at once, but was trying this form
first.
Oddly, the title property (and MainText) are the only properties that
are being set. In its current form (more below on that), the script
doesn't give an error, but neither does it update any of the other
properties. I'm sure I'm doing several things wrong - can someone
please correct me?
Here's the complete Python script:
==================== SiteSection_edit_general =====================
# Import a standard function, and get the HTML request and response
objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE = request.RESPONSE
# ----- update MainText object; create it if it doesn't exist
try:
context.manage_addDTMLMethod('MainText','')
except:
nop = 0;
context.MainText.manage_edit(request['MainText'], '')
# ----- ContainedObjectsArePages
context.manage_changeProperties(ContainedObjectsArePages=request['ContainedObjectsArePages'])
# ----- NavShortDescription
context.manage_changeProperties(NavShortDescription=request['NavShortDescription'])
# ----- NewMenuSection
# why is it failing here?
#
context.manage_changeProperties(NewMenuSection=request['NewMenuSection'])
# ----- title
context.manage_changeProperties(title=request['title'])
RESPONSE.redirect(context.absolute_url() +
'/SiteSection_editform_general')
return
===================== end Python script ============================
Also, for the sake of completeness and in case the problem is in the
form, here is the pertinent section of SiteSection_editform_general,
which invokes the above Python script:
=================== SiteSection_editform_general ===================
<Form action="<dtml-var absolute_url>/" method="post">
<table border="0" cellpadding="1" cellspacing="0" width="100%"><TR><td>
<dtml-var body_font_tag>
Title: <input type="text" name="title:string" size="35"
value="<dtml-if title><dtml-var title></dtml-if>">
<p><dtml-if MainTextIsDTML>DTML Code:<dtml-else>Structured Text (<a
href="<dtml-var
"structured_text_help.absolute_url()">">help</a>)</dtml-if>
<br><textarea name="MainText:text" rows="6" cols="50"
wrap="virtual"><dtml-if MainText><dtml-var
MainText></dtml-if></textarea>
<br>Contents (at right) display: <input type="radio"
name="ContainedObjectsArePages:boolean"<dtml-if
ContainedObjectsArePages> checked="1"</dtml-if>>as Pages
<input type="radio"
name="ContainedObjectsArePages:boolean"<dtml-unless
ContainedObjectsArePages>
checked="1"</dtml-unless>>as Page Sections
<p>Menu Description:
<br><textarea name="NavShortDescription:text" rows="3" cols="50"
wrap="virtual"><dtml-if NavShortDescription><dtml-var
NavShortDescription></dtml-if></textarea>
<br><input type="checkbox" name="NewMenuSection:boolean" <dtml-if
NewMenuSection>
checked="1"</dtml-if>>Starts New Menu Section
<input name="SiteSection_edit_general:method" type="submit"
class="form-element" value="Save Changes">
</form>
======================== end DTML code =============================
Any help would be most appreciated!
Many thanks,
Am Thomas
---
Virtue of the Small
http://virtueofthesmall.com