[Zope] DTML/Python to upload documents

complaw@hal-pc.org complaw@hal-pc.org
Fri, 25 May 2001 23:19:36 GMT


First, let me say that I'm making a site for lawyers to use to upload 
documents.  Now you know why it needs to be as simple to use as possible.  The 
easiest thing to do would be to use the Zope interface.  It doesn't always work 
out that way...

I have created a form (DTML method), an addFormAction (DTML Method), and a 
Python script to make a pretty screen for gathering information and uploading 
the file.  I would like to do something fancy with the ID (like remove blanks 
from the filename, change : and / to _, etc, and be certain that it is a unique 
id.  But that is for another day...

The problem with the following code is that it does not put a file in my 
folder.  All it does is copy the location of the file (e.g., 
G:\some\path\to\file\filename.pdf).  No document.

If I get this right, I'm going to post in on ZopeLabs.  (ZopeLabs is a really 
great idea, incidentally.)

Here is the code for the form...

<dtml-var standard_html_header>

<H3 ALIGN="center">Add a Document Associated with the <dtml-var case_style></H3>
<P ALIGN="center">Enter the information below to upload the document.</P> 

<FORM ACTION="addFileAction" METHOD="POST">

  <table border="0" cellspacing="8" width="95%" align="center">
    <tr>
      <th width="25%" align="right">Date of the document:</td>
      <td width="75%" align="left"><input type="text" size="40" 
name="document_date:date" value="<dtml-var ZopeTime fmt="%B %d, %Y">"></td>
    </tr>
    <tr>
      <th width="25%" align="right"><em>Brief</em> description of the 
document:</td>
      <td width="75%" align="left"><input type="text" size="40" 
name="description" value=""></td>
    </tr>
    <tr>
      <th width="25%" align="right">Keywords to help people find this 
document:</td>
      <td width="75%" align="left"><input type="text" size="40" name="keywords" 
value=""></td>
    </tr>
    <tr>
      <th width="25%" align="right">Unique Filename for the document (No 
blanks): </td>
      <td width="75%" align="left"><input type="text" size="40" 
name="fileid"></td>
    </tr>
    <tr>
      <th width="25%" align="right">The document to upload:</td>
      <td width="75%" align="left"><input type="file" size="40" 
name="uploaded_file"></td>
    </tr>
    <TR>
      <TD WIDTH="25%" ALIGN="right"></TD>
      <TD WIDTH="75%" ALIGN="left"><INPUT TYPE="submit" VALUE="Upload Document">
                                   <INPUT TYPE="reset" VALUE="Clear">
      </TD>
    </TR>
  </TABLE>

</form>

<dtml-var standard_html_footer>


Here is the code for the addFileAction DTML Method....

<dtml-var standard_html_header>

<dtml-call expr="addFile(document_date, description, keywords, fileid, 
uploaded_file)">

<h1 align="center">Thank you for your entry!</h1>

<p align="center"><a href="<dtml-var URL1>">Return</a> back to the documents 
page.</p>

<dtml-var standard_html_footer>


And, finally, the Python script...


# This code adds a file to the folder...

# Use the user-supplied fileid as the id...

id = fileid

# Create the document...
context.manage_addProduct['OFSP'].manage_addFile(id, title=description, 
precondition="", file=uploaded_file)

# Add the properties...
doc=getattr(context, id)
doc.manage_addProperty('document_date', document_date, 'date')
doc.manage_addProperty('description', description, 'string')
doc.manage_addProperty('keywords', keywords, 'string')


I'm sure you all guessed where I picked up this line of thought and code.

I'm probably missing some little thing.  I've gone over load_site.py, File.py 
and Image.py and sevearl HOWTO's, but still managed to miss the solution.  The 
upload page of Zope itself has many solutions, but I couldn't find the 
particular file in the source for the upload file page.

I think that somehow the contents of the file are not getting through the form, 
but haven't been able to confirm that.  

Any help would be appreciated.

Cheers,

Ron