[Zope] Changing properties of objects -- Problem solved

Ronald L. Chichester complaw@hal-pc.org
Tue, 21 May 2002 22:23:47 -0500


I solved the problem.  First, the proper use of manage_changeProperties 
requires the use of a dictionary.  So something like:


d1 = {'new_prop': item_prop}
doc=getattr(context, the_id)
doc.manage_changeProperties(d1)


where "item_prop" is the value that is passed to the python script from 
the form or whatnot.  

Next, if you will review my code below, the name error was the result of 
my missing a quote after the type=text in the form itself.

Its those little things that count.


Ron


complaw@hal-pc.org wrote:

>I'm trying to make some nice (fancy) screens so that my users can edit DTML 
>Documents without using the standard management interface.  For testing 
>purposes, I created a DTML document with a string property entitled "new_prop". 
>My view of this DTML Document looks like this:
>
>---------
><dtml-var standard_html_header>
><h2><dtml-var title_or_id></h2>
><p>
>This is the <dtml-var id> Document.
></p>
>
><P><a href="editForm?item_id=<dtml-var id>">Edit</P>
>
><dtml-var standard_html_footer>
>----------
>
>The code for the editForm DTML Method looks like:
>
>----------
><dtml-var standard_html_header>
><h2>Edit the Record</h2>
><form action="editRec" method="post">
>id: <input type=text name="the_id" value="<dtml-var item_id>"><BR>
><dtml-with expr="_.getitem(item_id)">
>new_prop: <input type="text name="new_prop" value="<dtml-var new_prop>"><BR>
><input type="submit>
></dtml-with>
></form>
><dtml-var standard_html_footer>
>----------
>
>.. and the correct values do indeed appear in the above form.  The editRecord 
>DTML Method looks like this:
>
>----------
><dtml-var standard_html_header>
>  <dtml-call expr="editRec(the_id, new_prop)">
><h2 align="center">Success!</h2>
><dtml-var standard_html_footer>
>----------
>
>.. and no, I do not get success.  The editRec method looks like this:
>
>----------
>doc=getattr(context, the_id)
>doc.manage_changeProperties(new_prop=new_prop)
>----------
>
>Upon invoking the above, I get:
>
>Zope Error
>
>Zope has encountered an error while publishing this resource.
>
>Error Type: NameError
>Error Value: global name 'new_prop' is not defined
>
>Troubleshooting Suggestions
>
>    * This resource may be trying to reference a nonexistent object or variable 
>global name 'new_prop' is not defined.
>    * The URL may be incorrect.
>    * The parameters passed to this resource may be incorrect.
>    * A resource that this resource relies on may be encountering an error.
>
>For more detailed information about the error, please refer to the HTML source 
>for this page.
>
>If the error persists please contact the site maintainer. Thank you for your 
>patience.
>
>Traceback (innermost last):
>  File /home/zope/Zope-2.4.4-src/lib/python/ZPublisher/Publish.py, line 223, in 
>publish_module
>  File /home/zope/Zope-2.4.4-src/lib/python/ZPublisher/Publish.py, line 187, in 
>publish
>  File /home/zope/Zope-2.4.4-src/lib/python/Zope/__init__.py, line 226, in 
>zpublisher_exception_hook
>    (Object: tmp)
>  File /home/zope/Zope-2.4.4-src/lib/python/ZPublisher/Publish.py, line 171, in 
>publish
>  File /home/zope/Zope-2.4.4-src/lib/python/ZPublisher/mapply.py, line 160, in 
>mapply
>    (Object: editRecord)
>  File /home/zope/Zope-2.4.4-src/lib/python/ZPublisher/Publish.py, line 112, in 
>call_object
>    (Object: editRecord)
>  File /home/zope/Zope-2.4.4-src/lib/python/OFS/DTMLMethod.py, line 200, in 
>__call__
>    (Object: editRecord)
>  File /home/zope/Zope-2.4.4-src/lib/python/DocumentTemplate/DT_String.py, line 
>546, in __call__
>    (Object: editRecord)
>  File /home/zope/Zope-2.4.4-src/lib/python/DocumentTemplate/DT_Util.py, line 
>231, in eval
>    (Object: editRec(the_id, new_prop))
>    (Info: editRec)
>  File <string>, line 2, in f
>NameError: (see above)
>
>
>Either I'm not getting the right object (which I think I am), or I'm not 
>providing the right parameters to manage_changeProperties.
>
>Can someone shed a little light on this?  I've checked Google, and there are 
>some nice examples when you are modifying values in a mySQL table, but nothing 
>for when you are "hand" modifying properties in DTML Documents.  Incidentally, 
>I think this would make a wonderful example for the Zope Book.  Hint, Hint.
>
>Thanks in advance,
>
>Ron
>
>
>
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>
>  
>