[Zope] Python Script problem

Ronald L. Chichester complaw@hal-pc.org
Sun, 25 Mar 2001 17:00:28 -0600


Okay, I think there is a context problem here, but I'm not sure.  So I
turn to the experts...

What I'm trying to do is allow users to create folders in some root
folder.

There are two DTML Methods and one Python script:

1.    The first DTML Method is a form to gather certain information from
the user.
2.    The second DTML Method is an "action" method which accepts the
"post" form data from (1.) and where I have some DTML code to assign a
unique ID before I call the script.
3.    Is a Python script that is called by (2.) and which is supposed to
create a Folder, assign some properties to it, and create an index_html
DTML method within that new folder.

Here is the code for the first DTML method (1. addClientForm)...

<dtml-var standard_html_header>
<h2 align="center">Add a client.</h2>
<form action="addClientAction" method="post">
  <table border="0" width="95%" cellspacing="8" align="center">
    <tr>
      <td width="25%" align="right">Name:</td>
      <td width="75%" align="left"><input type="text" name="client_name"
value="" size="40"></td>
    </td>
    <tr>
      <td width="25%" align="right">City/State:</td>
      <td width="75%" align="left"><input type="text"
name="client_location" value="" size="40"></td>
    </td>
    <tr>
      <td width="25%" align="right">Main Telephone:</td>
      <td width="75%" align="left"><input type="text"
name="client_telephone" value="" size="40"></td>
    </td>
    <tr>
      <td width="25%" align="right">Main Facsimile:</td>
      <td width="75%" align="left"><input type="text"
name="client_facsimile" value="" size="40"></td>
    </td>
    <tr>
      <td width="25%" align="right">Main Web Site:</td>
      <td width="75%" align="left"><input type="text"
name="client_web_site" value="" size="40"></td>
    </td>
    <tr>
      <td width="25%" align="right" valign="top">Description
and<br>General Comments:</td>
      <td width="75%" align="left"><textarea cols="40" rows="10"
name="comments" wrap="virtual"></textarea></td>
    </tr>
    <tr>
      <td width="25%" align="right"></td>
      <td width="75%" align="left"><input type="submit" value="submit
client name"></td>
    </td>
  </table>
</form>
<dtml-var standard_html_footer>


Here is the code for the second DTML method (2. addClientAction)...


<dtml-var standard_html_header>
  <dtml-call "REQUEST.set('ts', ZopeTime())">
  <dtml-call "REQUEST.set('id', _.str(_.int(ts)))">
  <dtml-call expr="addClient(id=id, client_name=client_name,
client_location=client_location, client_telephone=client_telephone,
client_facsimile=client_facsimile, client_web_site=client_web_site,
comments=comments)">

<p>If you made it this far, something went right.</p>
<p><a href="<dtml-var URL1>">Return</a> to the main window</a>

<dtml-var standard_html_footer>


Here is the python script (3.  addClient)

"""
This code actually creates a folder for the client
and a default index_html file linking to the contact/incident
code.
"""

# Create the index_html template...
index_template = """<dtml-var standard_html_header>
<H2 ALIGN="center><dtml-ver title_or_id></H2>
  <P>
  <TABLE WIDTH="95%" ALIGN="center" BORDER="0" CELLSPACING="8">
    <TR>
     <TD WIDTH="25%" ALIGN="right"><EM>Contacts:</EM></TD>
     <TD WIDTH="75%" ALIGN="left">
       <dtml-in expr="objectValues('DTML Document')" sort="title">
         <dtml-if expr="document_type='Contact'">
           <a href="&dtml-absolute_url;"><dtml-var title_or_id></a><br>
         </dtml-if>
       </dtml-in>
     </TD>
    </TR>
  </TABLE>
  </P>

  <P>
  <TABLE WIDTH="95%" ALIGN="center" BORDER="0" CELLSPACING="8">
     <dtml-in expr="objectValues('DTML Document')" sort="contact_date"
reverse>
       <dtml-if contact_date>
         <TR>
           <TD WIDTH="25%" ALIGN="left" VALIGN="top"><dtml-var
contact_date></TD>
           <TD WIDTH="25%" ALIGN="left" VALIGN="top"><dtml-var
attorney></TD>
           <TD WIDTH="50%" ALIGN="left" VALIGN="top"><dtml-var
description></TD>
         </TR>
       </dtml-if>
     </dtml-in>
  </TABLE>
  </P>

  <P ALIGN="center">Add a <A HREF="addContactForm">Contact</A></P>
  <P ALIGN="center">Add an <A HREF="addIncidentForm">Incident</A>
Report</P>

<dtml-var standard_html_footer>"""

# Create the folder...
newfolder = context.manage_addProduct['OFSP'].manage_addFolder(id=id,
title=client_name)

# Add the various properties...
newfolder.manage_addProperty('client_name', client_name, 'string')
newfolder.manage_addProperty('client_location', client_location,
'string')
newfolder.manage_addProperty('telephone', client_telephone, 'string')
newfolder.manage_addProperty('facsimile', client_facsimile, 'string')
newfolder.manage_addProperty('web_site', client_web_site, 'string')
newfolder.manage_addProperty('description', description, 'string')

# Create the index_html file...
newdoc    =
newfolder.manage_addProduct['OFSP'].manage_addDTMLMethod("index_html","",index_template)



Here is the error message when I added some test information...

           Zope Error

           Zope has encountered an error while publishing this resource.

           Error Type: AttributeError
           Error Value: 'None' object has no attribute
'manage_addProperty'



           Troubleshooting Suggestions

                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 C:\Program Files\ZopeSite\lib\python\ZPublisher\Publish.py, line
222, in publish_module
  File C:\Program Files\ZopeSite\lib\python\ZPublisher\Publish.py, line
187, in publish
  File C:\Program Files\ZopeSite\lib\python\Zope\__init__.py, line 221,
in zpublisher_exception_hook
    (Object: Traversable)
  File C:\Program Files\ZopeSite\lib\python\ZPublisher\Publish.py, line
171, in publish
  File C:\Program Files\ZopeSite\lib\python\ZPublisher\mapply.py, line
160, in mapply
    (Object: addClientAction)
  File C:\Program Files\ZopeSite\lib\python\ZPublisher\Publish.py, line
112, in call_object
    (Object: addClientAction)
  File C:\Program Files\ZopeSite\lib\python\OFS\DTMLMethod.py, line 189,
in __call__
    (Object: addClientAction)
  File C:\Program
Files\ZopeSite\lib\python\DocumentTemplate\DT_String.py, line 538, in
__call__
    (Object: addClientAction)
  File C:\Program Files\ZopeSite\lib\python\DocumentTemplate\DT_Util.py,
line 334, in eval
    (Object: addClient(id=id, client_name=client_name,
client_location=client_location, client_telephone=client_telephone,
client_facsimile=client_facsimile, client_web_site=client_web_site,
comments=comments))
    (Info: client_location)
  File <string>, line 0, in ?
  File C:\Program
Files\ZopeSite\lib\python\Shared\DC\Scripts\Bindings.py, line 324, in
__call__
    (Object: addClient)
  File C:\Program
Files\ZopeSite\lib\python\Shared\DC\Scripts\Bindings.py, line 353, in
_bindAndExec
    (Object: addClient)
  File C:\Program
Files\ZopeSite\lib\python\Products\PythonScripts\PythonScript.py, line
330, in _exec
    (Object: addClient)
    (Info: ({'script': <PythonScript instance at 012D7180>, 'context':
<Folder instance at 012C7480>, 'container': <Folder instance at
012C7480>, 'traverse_subpath': []}, (), {'client_web_site':
'http://slashdot.org', 'comments': 'This is it.\015\012\015\012I know
that this is it!!', 'client_facsimile': '713-229-7741', 'client_name':
'New Test, Inc.', 'client_telephone': '713-229-1341', 'client_location':
'Kingwood, TX', 'id': 'client_dev'}, None))
  File Script (Python), line 49, in addClient
  File C:\Program
Files\ZopeSite\lib\python\Products\PythonScripts\Guarded.py, line 273,
in __getattr__
  File C:\Program
Files\ZopeSite\lib\python\Products\PythonScripts\Guarded.py, line 145,
in __careful_getattr__
AttributeError: (see above)


I think the problem is somewhere around "client_location" but everything
looks right to my eye.

Can anyone give me a gentle hint?

Thanks,

Ron