[Zope] Python/TAL Problem

Peter Bengtsson peter at fry-it.com
Tue Jul 25 13:05:27 EDT 2006


Guess guess, do all objects have the 'KW1' property? I don't think so.
Try this:

   <div tal:define="blankstring string:">
      <input type="text" name="rows.title:records" size="50"
             tal:attributes="value python:item/KW1|blankstring" />
      <input type="hidden" name="prev_rows.title:records"
             tal:attributes="value item/KW1|blankstring" />
   </div>

beno wrote:
> Hi;
> I'm trying to tweak someone else' script to get it to do what I want. 
> The script reads from and writes to the "Properties" tab of pages and 
> folders, enabling one to change the titles of many pages/folders from 
> one single script-generated page. I want to be able to do the same thing 
> with another field I created called "KW1" (string) in the Properties 
> tab. The following is a snip of the code that needs to be altered (the 
> only code where "title" appears):
> 
>      <input type="text" name="rows.title:records" size="50"
>             tal:attributes="value python:item['title']" />
>      <input type="hidden" name="prev_rows.title:records"
>             tal:attributes="value item/title" />
> 
> If I alter line #2 and change "title" to "KW1" I get the following error 
> snippet:
> 
>    * Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__
>      __traceback_info__: item['KW1']
>    * Module Python expression "item['KW1']", line 1, in <expression>
>    * Module AccessControl.ZopeGuards, line 67, in guarded_getitem
> 
> If I alter line #4 and change "title" to "KW1" I get this error snippet:
> 
>    * Module Products.PageTemplates.Expressions, line 174, in __call__
>    * Module Products.PageTemplates.Expressions, line 162, in _eval
>    * Module Products.PageTemplates.Expressions, line 116, in _eval
>      __traceback_info__: item
>    * Module Products.PageTemplates.Expressions, line 320, in
>      restrictedTraverse
>      __traceback_info__: {'path': ['KW1'], 'TraversalRequestNameStack': []}
> 
> I have added KW1 as a string property to many of the pages in the target 
> folder. What am I doing wrong? Complete code and complete errors follow.
> Thanks.
> 
> 
> 
> 
> 
> 
> 
> 
> COMPLETE SCRIPT
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html tal:condition="here/formHandler">
> 
> <!--
> <script type="text/javascript" src="main.js"></script>
> -->
> 
> <body>
> 
> <h1>Manage Hierarchy</h1>
> 
> 
> <form action="" method="post" name="form" id="form"
>      tal:define="root python:request.fields['root'];
>                  items python:root['value'] and 
> sequence.sort(here.getEntries(root['value'], all=1), (('id', 'cmp', 
> 'desc'),))">
> 
> 
> <div id="filter">
>  <select name="root"
>          tal:define="items python:here.getEntries('en-us', 2)">
>             <option value="">&#8212;&#8212;Select 
> Folder&#8212;&#8212;</option>
>    <option tal:repeat="item items"
>            tal:content="structure python:'%s\--%s' % 
> ('&nbsp;'*5*item['level'], item['id'])"
>            tal:attributes="value python:item['url'];
>                            selected python:item['url'] == root['value']">
>    </option>
>  </select>
>  <input type="submit" name="onOk" value="Ok" />
> </div>
> 
> 
> 
> <div id="resultSet">
>  <table cellspacing="0" cellpadding="3" border="1"
>         tal:condition="items">
>  <tr>
>    <th>ID</th>
>    <th>KW1</th>
>  </tr>
>  <tr valign="top"
>      tal:repeat="item items">
>    <td>
>      <span tal:replace="structure python:'&nbsp;' * (8 * item['level']) 
> + item['id']">ID</span>
>      <input type="hidden" name="rows.id:records"
>             tal:attributes="value python:item['url']" />
>    </td>
>    <td>
>      <input type="text" name="rows.title:records" size="50"
>             tal:attributes="value python:item['title']" />
>      <input type="hidden" name="prev_rows.title:records"
>             tal:attributes="value item/title" />
>    </td>
>  </tr>
>  </table>
> 
>  <div tal:condition="python:not items">
>    Sorry... no items to manage.<br />
>  </div>
> </div>
> 
> 
> 
> 
> <div id="buttons">
>  <input type="submit" name="onSaveChanges" value=" Save Changes "
>         tal:condition="items" />
> </div>
> 
> </form>
> 
> 
> </body>
> </html>
> 
> 
> 
> 
> 
> FIRST ERROR MESSAGE
> from changing              tal:attributes="value python:item['title']" 
> />  to                tal:attributes="value python:item['KW1']" />
> 
> 
>    Site Error
> 
> An error was encountered while publishing this resource.
> 
> *KeyError*
> 
> Sorry, a site error occurred.
> 
> Traceback (innermost last):
> 
>    * Module ZPublisher.Publish, line 175, in publish_module_standard
>    * Module ZPublisher.Publish, line 132, in publish
>    * Module Zope.App.startup, line 204, in zpublisher_exception_hook
>    * Module ZPublisher.Publish, line 101, in publish
>    * Module ZPublisher.mapply, line 88, in mapply
>    * Module ZPublisher.Publish, line 39, in call_object
>    * Module Shared.DC.Scripts.Bindings, line 306, in __call__
>    * Module Shared.DC.Scripts.Bindings, line 343, in _bindAndExec
>    * Module Products.PageTemplates.ZopePageTemplate, line 222, in _exec
>    * Module Products.PageTemplates.PageTemplate, line 96, in pt_render
>      *<ZopePageTemplate at /footprints.2012.vi/test_kw/main/index_html>*
>    * Module TAL.TALInterpreter, line 190, in __call__
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 637, in do_condition
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 637, in do_condition
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 613, in do_loop_tal
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 263, in do_startEndTag
>    * Module TAL.TALInterpreter, line 291, in do_startTag
>    * Module TAL.TALInterpreter, line 357, in attrAction_tal
>    * Module Products.PageTemplates.TALES, line 227, in evaluateText
>    * Module Products.PageTemplates.TALES, line 221, in evaluate
>      *URL: /footprints.2012.vi/test_kw/main/index_html*
>      *Line 50, Column 6*
>      *Expression: <PythonExpr item['KW1']>*
>      *Names:*
> 
>      {'container': <Folder instance at 14c7e500>,
>       'context': <Folder instance at 14c7e500>,
>       'default': <Products.PageTemplates.TALES.Default instance at 
> 0x8a1d62c>,
>       'here': <Folder instance at 14c7e500>,
>       'loop': <SafeMapping instance at 14ce4460>,
>       'modules': 
> <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 
> 0x8a1d06c>,
>       'nothing': None,
>       'options': {'args': ()},
>       'repeat': <SafeMapping instance at 14ce4460>,
>       'request': <HTTPRequest, 
> URL=http://2012.vi:7080/footprints.2012.vi/test_kw/main/index_html>,
>       'root': <Application instance at c899170>,
>       'template': <ZopePageTemplate at 
> /footprints.2012.vi/test_kw/main/index_html>,
>       'traverse_subpath': [],
>       'user': tick}
> 
>    * Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__
>      __traceback_info__: item['KW1']
>    * Module Python expression "item['KW1']", line 1, in <expression>
>    * Module AccessControl.ZopeGuards, line 67, in guarded_getitem
> 
> KeyError: 'KW1' (Also, an error occurred while attempting to render the 
> standard error message.)
> 
> 
> 
> 
> 
> 
> 
> 
> SECOND ERROR MESSAGE
> from replacing              tal:attributes="value item/title" />   with 
>             tal:attributes="value item/KW1" />
> 
> 
>    Site Error
> 
> An error was encountered while publishing this resource.
> 
> *KeyError*
> 
> Sorry, a site error occurred.
> 
> Traceback (innermost last):
> 
>    * Module ZPublisher.Publish, line 175, in publish_module_standard
>    * Module ZPublisher.Publish, line 132, in publish
>    * Module Zope.App.startup, line 204, in zpublisher_exception_hook
>    * Module ZPublisher.Publish, line 101, in publish
>    * Module ZPublisher.mapply, line 88, in mapply
>    * Module ZPublisher.Publish, line 39, in call_object
>    * Module Shared.DC.Scripts.Bindings, line 306, in __call__
>    * Module Shared.DC.Scripts.Bindings, line 343, in _bindAndExec
>    * Module Products.PageTemplates.ZopePageTemplate, line 222, in _exec
>    * Module Products.PageTemplates.PageTemplate, line 96, in pt_render
>      *<ZopePageTemplate at /footprints.2012.vi/test_kw/main/index_html>*
>    * Module TAL.TALInterpreter, line 190, in __call__
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 637, in do_condition
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 637, in do_condition
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 613, in do_loop_tal
>    * Module TAL.TALInterpreter, line 234, in interpret
>    * Module TAL.TALInterpreter, line 263, in do_startEndTag
>    * Module TAL.TALInterpreter, line 291, in do_startTag
>    * Module TAL.TALInterpreter, line 357, in attrAction_tal
>    * Module Products.PageTemplates.TALES, line 227, in evaluateText
>    * Module Products.PageTemplates.TALES, line 221, in evaluate
>      *URL: /footprints.2012.vi/test_kw/main/index_html*
>      *Line 52, Column 6*
>      *Expression: standard:'item/KW1'*
>      *Names:*
> 
>      {'container': <Folder instance at 14c7e500>,
>       'context': <Folder instance at 14c7e500>,
>       'default': <Products.PageTemplates.TALES.Default instance at 
> 0x8a1d62c>,
>       'here': <Folder instance at 14c7e500>,
>       'loop': <SafeMapping instance at 14ce4280>,
>       'modules': 
> <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 
> 0x8a1d06c>,
>       'nothing': None,
>       'options': {'args': ()},
>       'repeat': <SafeMapping instance at 14ce4280>,
>       'request': <HTTPRequest, 
> URL=http://2012.vi:7080/footprints.2012.vi/test_kw/main/index_html>,
>       'root': <Application instance at c899170>,
>       'template': <ZopePageTemplate at 
> /footprints.2012.vi/test_kw/main/index_html>,
>       'traverse_subpath': [],
>       'user': tick}
> 
>    * Module Products.PageTemplates.Expressions, line 174, in __call__
>    * Module Products.PageTemplates.Expressions, line 162, in _eval
>    * Module Products.PageTemplates.Expressions, line 116, in _eval
>      __traceback_info__: item
>    * Module Products.PageTemplates.Expressions, line 320, in
>      restrictedTraverse
>      __traceback_info__: {'path': ['KW1'], 'TraversalRequestNameStack': []}
> 
> KeyError: 'KW1' (Also, an error occurred while attempting to render the 
> standard error message.)
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
> 

-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list