Calling a python product with paramaters PLEASE HELP
Hi all, Here is the index_html of a product with the index_html embeded in the module source- def index_html(self,width=100, height=200,RESPONSE=None,REQUEST=None): "This is the index_html method" im=PIL.Image.new('RGB', (width,height)) draw = PIL.ImageDraw.Draw(im) draw.rectangle([0,0,0,0], fill =(0,0,0)) RESPONSE.setHeader("Content-type", "image/gif") outFile = cStringIO.StringIO() im.save(outFile, 'gif') RESPONSE.write(outFile.getvalue()) return '' If I call an instance of the product from a dtml method with <dtml-var bar> I get my picture. If I call an instance of the product from a dtml method with <dtml-var bar(100,100)">, I get- Error Type: AttributeError Error Value: __call__ Traceback (innermost last): File C:\Zope\lib\python\ZPublisher\Publish.py, line 150, in publish_module File C:\Zope\lib\python\ZPublisher\Publish.py, line 114, in publish File C:\Zope\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook (Object: Zope) File C:\Zope\lib\python\ZPublisher\Publish.py, line 98, in publish File C:\Zope\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: barcall) File C:\Zope\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: barcall) File C:\Zope\lib\python\OFS\DTMLMethod.py, line 127, in __call__ (Object: barcall) File C:\Zope\lib\python\DocumentTemplate\DT_String.py, line 473, in __call__ (Object: barcall) File C:\Zope\lib\python\DocumentTemplate\DT_Util.py, line 159, in eval (Object: bar(100,100)) (Info: bar) File <string>, line 2, in fAttributeError: (see above)I have nearly got this product working the way I want it to, so any help you can give will be greatly appreciated. Regards Sean Kemplay --------------------------------- Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now
Your instance bar is not callable, which is why you're unable to pass it arguments. There are two ways to get what you want: the DTML way and the Python way. Here's the DTML way: <dtml-with bar> <dtml-var "index_html(100,100)"> </dtml-with> I'm not sure that makes any sense from a design standpoint, but it should work anyway. The Python way (superior, IMO) adds a function to your product module: def __call__(self, width=100, height=200): return self.index_html(width, height) At which point, <dtml-var "bar(x,y)"> should yield what you're looking for. Take your pick. HTH, Dylan At 11:04 PM 11/22/2002, you wrote:
Hi all,
Here is the index_html of a product with the index_html embeded in the module source-
def index_html(self,width=100, height=200,RESPONSE=None,REQUEST=None): "This is the index_html method" im=PIL.Image.new('RGB', (width,height)) draw = PIL.ImageDraw.Draw(im) draw.rectangle([0,0,0,0], fill =(0,0,0)) RESPONSE.setHeader("Content-type", "image/gif") outFile = cStringIO.StringIO() im.save(outFile, 'gif') RESPONSE.write(outFile.getvalue()) return ''
If I call an instance of the product from a dtml method with <dtml-var bar> I get my picture.
If I call an instance of the product from a dtml method with <dtml-var bar(100,100)">, I get-
Error Type: AttributeError Error Value: __call__
Traceback (innermost last): File C:\Zope\lib\python\ZPublisher\Publish.py, line 150, in publish_module File C:\Zope\lib\python\ZPublisher\Publish.py, line 114, in publish File C:\Zope\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook (Object: Zope) File C:\Zope\lib\python\ZPublisher\Publish.py, line 98, in publish File C:\Zope\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: barcall) File C:\Zope\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: barcall) File C:\Zope\lib\python\OFS\DTMLMethod.py, line 127, in __call__ (Object: barcall) File C:\Zope\lib\python\DocumentTemplate\DT_String.py, line 473, in __call__ (Object: barcall) File C:\Zope\lib\python\DocumentTemplate\DT_Util.py, line 159, in eval (Object: bar(100,100)) (Info: bar) File <string>, line 2, in f AttributeError: (see above)
I have nearly got this product working the way I want it to, so any help you can give will be greatly appreciated. Regards Sean Kemplay
Do you Yahoo!? <http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com>Yahoo! Mail Plus - Powerful. Affordable. <http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com>Sign up now
participants (2)
-
Dylan Reinhardt -
Sean K