I have an 'Add Item' form which allows the user to add item information, as well as upload a file. I have a python script that processes the form, but I'm getting some weird behavior because it seems to be executing twice. I know this because it gives me an integrity error; meaning, it has executed my insert query twice. I feel there is something wrong with my script because when I comment out the block that processes the image upload (in boldface red below), I don't get the integrity error. In addition, when I test the script in the 'Test' section, it works. I would appreciate any ideas you may have. The code is pasted below.  Thank you very much.

####Python Script -- processAddItem ####

#parameters: code, description,cost_code,transfer_id=None, origin, location, remarks,itemImage

#process form with item details and image upload
from Products.PythonScripts.standard import url_quote

REQUEST=context.REQUEST

#insert try here
#call insert zsql method

context.InventoryDB.insertItem(code=code, description=description,
                               cost_code=cost_code,
                               transfer_id=transfer_id, origin=origin,
                               location=location, remarks=remarks)

#query for id so that you can name image that
results = context.InventoryDB.getByCode(code=code)
imageId = -1

for item in results:
   imageId = item.id
   break

if itemImage != None:
   content_type=itemImage.headers['Content-Type']
   if content_type.find('image')!=-1:
      context.images.inventory.manage_addProduct['OFSP'].manage_addImage(id=str(imageId), file=itemImage, title='')
   else:
      context.images.inventory.manage_addProduct['OFSP'].manage_addFile(id=str(imageId), file=itemImage, title='')


# create a success message
message="Item '%s' added successfully." % code

# redirect to main page - this is necessary to make all the URLs
# on the main page work correctly.
return context.REQUEST.RESPONSE.redirect("%s?message=%s" % (container.absolute_url(), url_quote(message)))

#### Page Template code:####

<form action="processAddItem" method="POST" enctype="multipart/form-data">

<span class="errorMessage" tal:condition="options/error_message | nothing" tal:content="options/error_message">
Error Message
</span>
<table class="text" style="font-weight:bold" cellspacing="2" cellpadding="2" border="0">
<tr>
    <td><font size="1" font-family="tahoma" color="red">*required fields</font></td>
</tr>
<tr>
    <td>Code:<font color="red">*</font></td>
    <td><input type="text" name="code:required"></td>
</tr>
<tr>
    <td>Description:</td>
    <td><input type="Text" name="description"></td>
</tr>
<tr>
    <td>Cost Code:</td>
    <td><input type="text" name="cost_code"></td>
</tr>
<tr>
    <td>Transfer Id:</td>
    <td><input type="text" name="transfer_id:int:ignore_empty"></td>
</tr>
<tr>
    <td>Origin:</td>
    <td><select name="origin" class="text">
          <option value="">None</option>
          <option tal:repeat="branch container/getBranchList" tal:content="branch"
                    tal:attributes="value branch">
           branch
          </option>
        </select>
     </td>
</tr>
<tr>
    <td>Location:</td>
    <td><select name="location" class="text">
          <option tal:repeat="branch container/getBranchList" tal:content="branch"
                    tal:attributes="value branch">
           branch
          </option>
        </select>
     </td>
</tr>
<tr>
    <td>Remarks:</td>
    <td><textarea cols="30" rows="10" name="remarks"></textarea></td>
</tr>
<tr>
    <td>Image:</td>
    <td><input type="file" name="itemImage"></td>
<tr>
    <td>&nbsp;</td>
    <td> <input type="submit" name="submit" value="Add Item"></td>
</tr>
</table>
 
</form>

 



Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!