[Zope] ObjectManager problem
Max Møller Rasmussen
maxm@normik.dk
Wed, 30 May 2001 13:33:50 +0200
I am making a product that draws a graph in PIL and then saves the image as
a GIF in a Zope ObjectManager.
If the image doesn't exist it will be rendered and saved in the
objectManager.
When I run it the first time the image renders just nicely in a dmtl page.
If I try to reload it, I get an error that says::
Error Type: Bad Request
Error Value: The id "laeringsGraf" is invalid--it is already in use.
...
File C:\zope23\lib\python\Products\ots_laering\ots_laeringLogic.py, line
207, in updateGraph
(Object: laering)
File C:\zope23\lib\python\Products\ots_laering\ots_laeringLogic.py, line
196, in _drawTriangle
(Object: laering)
File C:\zope23\lib\python\OFS\ObjectManager.py, line 272, in _setObject
(Object: laering)
File C:\zope23\lib\python\OFS\ObjectManager.py, line 147, in checkValidId
(Object: laering)
So it seems that the Image gets saved OK ... somewhere, but I cannot se the
id via self.objectIds() which simply returns an empty tuple ().
My object inherits ObjectManager, but it doesn't seem like the Image gets
saved in it.
I can see it in a dtml page like <dtml-var laeringsGraf> but apparantly it's
saved somewhere else .... I'm completely baffled.
I check for existance of the image like so::
def updateGraph(self):
"Render graf if it doesn't exist"
imageID = 'laeringsGraf'
print 'objects:', self.objectIds()
if imageID in self.objectIds(): # allready exists
pass
else: # doesnt exist, so render first time
self._drawTriangle([150, 0, 0, 0], 10, 10)
The following is the snippet of code that saves the image from PIL into the
ObjectManager
# save it in the ZODB
outf = StringIO()
im.save(outf, 'GIF')
del im
data = outf.getvalue()
outf.close()
imageID = 'laeringsGraf'
self._setObject(imageID, OFS.Image.Image(imageID,'Lærings graf',''))
self._getOb(imageID).update_data(data)
Anybody's got a clue??? Please.
Regard Max M