Re: [Zope] adding objects to a ZCatalog

2007-02-24 Thread Peter Bengtsson

change

context.ImageData.manage_catalogObject(newimage_image, uid)

to
self.ImageData.manage_catalogObject(newimage_image, uid)


--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] adding objects to a ZCatalog

2007-02-23 Thread Jonathan


- Original Message - 
From: "Tom Von Lahndorff" <[EMAIL PROTECTED]>

To: "Peter Bengtsson" <[EMAIL PROTECTED]>
Cc: 
Sent: Friday, February 23, 2007 1:12 PM
Subject: Re: [Zope] adding objects to a ZCatalog

Peter Bengtsson wrote:

On 2/23/07, Tom Von Lahndorff <[EMAIL PROTECTED]> wrote:

Hi,

I have a folder called "images" and a form that to add images to that
folder. The form called an external method (../images/addImage) that
references a python script, the one I sent earlier, that creates 4
versions of the images in 4 sizes and places them in the "images"
folder. Also in the "images" folder I have a ZCatalog called
"ImageData". I'm trying to add a line to the python script to
automatically catalog any images that are added to the "images" folder.
I tried "ImageData.manage_catalogObject..." but I kept getting back:
NameError: global name 'ImageData' is not defined. Any advice? Thanks.


Perhaps you meant
context.ImageData.manage_catalogObject(...


returns: "NameError: global name 'context' is not defined"


You are either (1) doing this in an external method, in which case use 
'self' instead of 'context', or (2) the bindings in your python script are 
pooched (click on the bindings tab of the python script, the 'Context' 
binding should be set to 'context').


Jonathan 


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] adding objects to a ZCatalog

2007-02-23 Thread Tom Von Lahndorff



Peter Bengtsson wrote:

On 2/23/07, Tom Von Lahndorff <[EMAIL PROTECTED]> wrote:

Hi,

I have a folder called "images" and a form that to add images to that
folder. The form called an external method (../images/addImage) that
references a python script, the one I sent earlier, that creates 4
versions of the images in 4 sizes and places them in the "images"
folder. Also in the "images" folder I have a ZCatalog called
"ImageData". I'm trying to add a line to the python script to
automatically catalog any images that are added to the "images" folder.
I tried "ImageData.manage_catalogObject..." but I kept getting back:
NameError: global name 'ImageData' is not defined. Any advice? Thanks.


Perhaps you meant
context.ImageData.manage_catalogObject(...


This is the complete script:

def makeImages(self, imagefile, newkeywords, newcaption, newsource):

   import PIL.Image, ImageEnhance, ImageFilter
   import PIL
   from StringIO import StringIO
   import os.path
   import datetime
   import time

   # create the data in a new PIL Image.
   image=PIL.Image.open(imagefile)
   image=image.convert('RGB')
   image=image.filter(ImageFilter.SHARPEN)
   image=image.resize((640, 480), PIL.Image.ANTIALIAS)
   image2=image.resize((320, 240), PIL.Image.ANTIALIAS)
   image3=image.resize((160, 120), PIL.Image.ANTIALIAS)
   image4=image.resize((80, 60), PIL.Image.ANTIALIAS)

   # get the data in memory.
   newimage_file=StringIO()
   image.save(newimage_file, "JPEG")
   newimage_file.seek(0)
   newimage_file2=StringIO()
   image2.save(newimage_file2, "JPEG")
   newimage_file2.seek(0)
   newimage_file3=StringIO()
   image3.save(newimage_file3, "JPEG")
   newimage_file3.seek(0)
   newimage_file4=StringIO()
   image4.save(newimage_file4, "JPEG")
   newimage_file4.seek(0)

   # create an id for the image
   now = datetime.datetime.now()
   newimageid=now.strftime('%Y%m%d%H%M%S')
   newimage_id=newimageid + '-640.jpg'
   newimage_id2=newimageid + '-320.jpg'
   newimage_id3=newimageid + '-160.jpg'
   newimage_id4=newimageid + '-80.jpg'

   # if there's an old image, delete it
   if newimage_id in self.objectIds():
   self.manage_delObjects([newimage_id])
   if newimage_id2 in self.objectIds():
   self.manage_delObjects([newimage_id2])
   if newimage_id3 in self.objectIds():
   self.manage_delObjects([newimage_id3])
   if newimage_id4 in self.objectIds():
   self.manage_delObjects([newimage_id4])

   # create the Zope image object for the new image
   self.manage_addProduct['OFSP'].manage_addImage(newimage_id, 
newimage_file, '')
   self.manage_addProduct['OFSP'].manage_addImage(newimage_id2, 
newimage_file2, '')
   self.manage_addProduct['OFSP'].manage_addImage(newimage_id3, 
newimage_file3, '')
   self.manage_addProduct['OFSP'].manage_addImage(newimage_id4, 
newimage_file4, '')


   # now find the new zope object so we can modify
   # its properties.
   newimage_image=getattr(self, newimage_id)
   newimage_image.manage_addProperty('keywords', '', 'string')
   newimage_image.manage_addProperty('caption', '', 'string')
   newimage_image.manage_addProperty('imageid', '', 'string')
   newimage_image.manage_changeProperties(keywords=newkeywords, 
caption=newcaption, imageid=newimageid, source=newsource)

   context.ImageData.manage_catalogObject(newimage_image, uid)
   newimage_image2=getattr(self, newimage_id2)
   newimage_image2.manage_addProperty('imagefile2', '', 'string')
   newimage_image3=getattr(self, newimage_id3)
   newimage_image3.manage_addProperty('imagefile3', '', 'string')
   newimage_image4=getattr(self, newimage_id4)
   newimage_image4.manage_addProperty('imagefile4', '', 'string')




Tom
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )





___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] adding objects to a ZCatalog

2007-02-23 Thread Tom Von Lahndorff



Peter Bengtsson wrote:

On 2/23/07, Tom Von Lahndorff <[EMAIL PROTECTED]> wrote:

Hi,

I have a folder called "images" and a form that to add images to that
folder. The form called an external method (../images/addImage) that
references a python script, the one I sent earlier, that creates 4
versions of the images in 4 sizes and places them in the "images"
folder. Also in the "images" folder I have a ZCatalog called
"ImageData". I'm trying to add a line to the python script to
automatically catalog any images that are added to the "images" folder.
I tried "ImageData.manage_catalogObject..." but I kept getting back:
NameError: global name 'ImageData' is not defined. Any advice? Thanks.


Perhaps you meant
context.ImageData.manage_catalogObject(...


returns: "NameError: global name 'context' is not defined"



Tom
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )





___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] adding objects to a ZCatalog

2007-02-23 Thread Peter Bengtsson

On 2/23/07, Tom Von Lahndorff <[EMAIL PROTECTED]> wrote:

Hi,

I have a folder called "images" and a form that to add images to that
folder. The form called an external method (../images/addImage) that
references a python script, the one I sent earlier, that creates 4
versions of the images in 4 sizes and places them in the "images"
folder. Also in the "images" folder I have a ZCatalog called
"ImageData". I'm trying to add a line to the python script to
automatically catalog any images that are added to the "images" folder.
I tried "ImageData.manage_catalogObject..." but I kept getting back:
NameError: global name 'ImageData' is not defined. Any advice? Thanks.


Perhaps you meant
context.ImageData.manage_catalogObject(...



Tom
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )




--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] adding objects to a ZCatalog

2007-02-23 Thread Tom Von Lahndorff

Hi,

I have a folder called "images" and a form that to add images to that 
folder. The form called an external method (../images/addImage) that 
references a python script, the one I sent earlier, that creates 4 
versions of the images in 4 sizes and places them in the "images" 
folder. Also in the "images" folder I have a ZCatalog called 
"ImageData". I'm trying to add a line to the python script to 
automatically catalog any images that are added to the "images" folder. 
I tried "ImageData.manage_catalogObject..." but I kept getting back: 
NameError: global name 'ImageData' is not defined. Any advice? Thanks.


Tom
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )