[Zope] I can't find a way to give parameters to the getDtmlData of a ZGDChart object object

Steve Spicklemire steve@spvi.com
Wed, 8 Nov 2000 11:08:13 -0500 (EST)


Hi Fred,

   I experimented a bit with the ZGDChart product. You can might try the following patch:

*** lib/python/Products/ZGDChart/ZGDChart.py	Tue Sep 12 21:44:09 2000
--- /usr/local/etc/Zope2Test/pr/ZGDChart/ZGDChart.py	Wed Oct  4 10:41:51 2000
***************
*** 64,73 ****
--- 64,74 ----
  from Globals import HTMLFile, MessageDialog, Persistent
  from Globals import package_home
  from DocumentTemplate.DT_Util import *
  from DocumentTemplate.DT_String import String
  from maybe_lock import allocate_lock
+ import traceback
  
  #
  # In this module, extend gdchart so
  # that it can render itself
  #
***************
*** 133,142 ****
--- 134,144 ----
  	manage_options=(
  		{'label':'Properties' , 'icon':icon, 'action':'manage_main',        'target':'_self'},
  		{'label':'Colors'     , 'icon':icon, 'action':'manage_mainColor',   'target':'_self'},
  		{'label':'Scale',       'icon':icon, 'action':'manage_mainScale',   'target':'_self'},
  		{'label':'Data Method', 'icon':icon, 'action':'manage_mainGetData', 'target':'_self'},
+ 		{'label':'DTML Data',   'icon':icon, 'action':'getDtmlData/manage_main', 'target':'_self'},
  		{'label':'Security'   , 'icon':icon, 'action':'manage_access',      'target':'_self'},
  		{'label':'View'       , 'icon':icon, 'action':'manage_mainView',    'target':'_self'},
  		)
  
  	__ac_permissions__=(
***************
*** 281,291 ****
  		self.id 	    	= id
  		self.title  	   	= title
  		self.height 	   	= height
  		self.width  	   	= width
  		self.SQL    	   	= SQL
! 		self.content_type	= 'image/gif'
  		self.tempfile		= self.home() + '/temp.gif'
  			
  		# Set the chart options
  		self.bg_transparent	= 'bg_transparent' in option
  		self.xaxis    		= 'xaxis' in option
--- 283,293 ----
  		self.id 	    	= id
  		self.title  	   	= title
  		self.height 	   	= height
  		self.width  	   	= width
  		self.SQL    	   	= SQL
! 		self.content_type	= 'image/png'
  		self.tempfile		= self.home() + '/temp.gif'
  			
  		# Set the chart options
  		self.bg_transparent	= 'bg_transparent' in option
  		self.xaxis    		= 'xaxis' in option
***************
*** 372,386 ****
  		self.threed_angle		=	0
  		self.threed_depth		=	0
  
  		# Set the data gathering method
  		self.selected_data_method = 'dtml'
! 		f = open(os.path.join(self.home(),'manage', 'getDtmlData.dtml'), 'r')
! 		getDtmlData_dtml = f.read()
! 		f.close()
! 		ob = OFS.DTMLMethod.DTMLMethod(getDtmlData_dtml, __name__='getDtmlData')
! 		self._setObject('getDtmlData', ob)
  						
  	def manage_edit(self, title, xtitle, ytitle, width, height, chart_type, option=[], REQUEST=None):
  		"""edit ZGDChart"""
  		self.title      	= title
  		self.xtitle     	= xtitle
--- 374,384 ----
  		self.threed_angle		=	0
  		self.threed_depth		=	0
  
  		# Set the data gathering method
  		self.selected_data_method = 'dtml'
! 		self.manage_addDTMLMethod('getDtmlData', 'DTML Data Method', open(HTMLFile('manage/getDtmlData',globals()).raw).read())
  						
  	def manage_edit(self, title, xtitle, ytitle, width, height, chart_type, option=[], REQUEST=None):
  		"""edit ZGDChart"""
  		self.title      	= title
  		self.xtitle     	= xtitle
***************
*** 687,704 ****
  			#
  			# requires GDChart 0.4
  			#
  			tempfile = cStringIO.StringIO() 
  			apply(chart, (GDC_TYPE, (self.width, self.height), tempfile) + tuple(chartdata))
! 			if RESPONSE: RESPONSE['content-type']=self.content_type
  			output = tempfile.getvalue()
- 			#
- 			# requires GDChart 0.3
- 			# apply(chart, (GDC_TYPE, (self.width, self.height), self.tempfile) + tuple(chartdata))
- 			# if RESPONSE: RESPONSE['content-type']=self.content_type
- 			# output = open(self.tempfile,'rb').read()
- 			#
  		finally:
  			_chart_lock.release()			
  		return  output
  		
  	def _setOption(self):
--- 685,697 ----
  			#
  			# requires GDChart 0.4
  			#
  			tempfile = cStringIO.StringIO() 
  			apply(chart, (GDC_TYPE, (self.width, self.height), tempfile) + tuple(chartdata))
! 			if RESPONSE:
! 				RESPONSE.setHeader('content-type',self.content_type)
  			output = tempfile.getvalue()
  		finally:
  			_chart_lock.release()			
  		return  output
  		
  	def _setOption(self):
***************
*** 768,786 ****
  		#  other attributes in the following block may be a None
  		#
  		try:
  			for s in params.keys():
  				eval("option(%s = params['%s'])" % (s,s))
! 		except error:
  			#
  			#  probably haven't got a patched gdchart.pyd
  			#  will try to run gdchart using previous scale settings
  			#  it will be ugly but at least won't give an error page
  			#
  			#  XXX log this to a file?
  			#
! 			print "GDChart setscale error"
  			pass
  			
  		params = {}
  		p = self.runtime_prefix
  		
--- 761,781 ----
  		#  other attributes in the following block may be a None
  		#
  		try:
  			for s in params.keys():
  				eval("option(%s = params['%s'])" % (s,s))
! 		except error, msg:
  			#
  			#  probably haven't got a patched gdchart.pyd
  			#  will try to run gdchart using previous scale settings
  			#  it will be ugly but at least won't give an error page
  			#
  			#  XXX log this to a file?
  			#
! 			#print "GDChart setscale error"
! 			#print error, msg
! 			#traceback.print_exc()
  			pass
  			
  		params = {}
  		p = self.runtime_prefix