[Zope] Adding Photo instance w/ PythonScript

Timothy Wilson wilson@visi.com
Sun, 28 Jan 2001 12:41:20 -0600 (CST)


Hey everyone,

Now that I'm not trying to use string methods on a date instance anymore, I
think I'm close to a solution. I'm trying to add a Photo instance to a
folder with an HTML form and a PythonScript. Here's the script:

"""
Create a "Picture of the Day" image.
"""
import string

# create a unique object id based on the display date
dateString = str(display_date)          # convert date to string
newID = string.split(dateString, '/')
id = ''
for i in newID:
  id = id + str(i)

# create the image
context.manage_addProduct['OFSP'].manage_addPhoto(id, title=title,
file=file)

# add a display date property
#doc = getattr(context, id)
#doc.manage_addProperty('display_date', display_date, 'date')

Notice I've commented out the part that adds the display_date
property. Now the executing this script produces the following error and
traceback:

Error Type: AttributeError
Error Value: manage_addPhoto

Traceback (innermost last):
  File /var/lib/zope/2.3.0/lib/python/ZPublisher/Publish.py, line 222, in
publish_module
  File /var/lib/zope/2.3.0/lib/python/ZPublisher/Publish.py, line 187, in
publish
  File /var/lib/zope/2.3.0/lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook
    (Object: Traversable)
  File /var/lib/zope/2.3.0/lib/python/ZPublisher/Publish.py, line 171, in
publish
  File /var/lib/zope/2.3.0/lib/python/ZPublisher/mapply.py, line 160, in
mapply
    (Object: POTD_add)
  File /var/lib/zope/2.3.0/lib/python/ZPublisher/Publish.py, line 112, in
call_object
    (Object: POTD_add)
  File /var/lib/zope/2.3.0/lib/python/Shared/DC/Scripts/Bindings.py, line
324, in __call__
    (Object: POTD_add)
  File /var/lib/zope/2.3.0/lib/python/Shared/DC/Scripts/Bindings.py, line
353, in _bindAndExec
    (Object: POTD_add)
  File
/var/lib/zope/2.3.0/lib/python/Products/PythonScripts/PythonScript.py, line
330, in _exec
    (Object: POTD_add)
    (Info: ({'script': <PythonScript instance at 87874d0>,
'context': <Folder instance at 89506c0>, 'container': <Folder instance at
89506c0>, 'traverse_subpath': []}, ('Test image', DateTime('2001/01/31'),
<ZPublisher.HTTPRequest.FileUpload instance at 874a470>), {}, None))
  File Script (Python), line 15, in POTD_add
  File /var/lib/zope/2.3.0/lib/python/Products/PythonScripts/Guarded.py,
line 273, in __getattr__
  File /var/lib/zope/2.3.0/lib/python/Products/PythonScripts/Guarded.py,
line 143, in __careful_getattr__
AttributeError: (see above)

I've looked at the Photo product source and noted that the parameters it
expects are listed as self, id, file, title='', displays=None,
precondition='', content_type='', REQUEST=None. That looks OK. 

What about the line:

context.manage_addProduct['OFSP'].manage_addPhoto(id, title=title,
file=file)

What's the purpose of manage_addProduct['OFSP']? Is my error a result of not
calling the manage_addPhoto method properly?

Any more ideas?

-Tim

--
Tim Wilson      | Visit Sibley online:         | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |                              | http://slashdot.org/
wilson@visi.com |   <dtml-var pithy_quote>     | http://linux.com/