[Zope] acquisition context within product method

Richard Rosenberg richrosenberg at earthlink.net
Fri Sep 24 18:21:29 EDT 2004


Thanks Dieter. . .

I've decided on a different approach, and now I am truly baffled. It  
seems like there is something incredibly obvious that I am not getting  
about how acquisition works. I've looked at the Dev Guide so much I see  
it in my sleep, but I am not getting it.

I am now creating a class that has among other things) zSQL methods as  
attributes. That part works fine. Next I thought I'd also make my life  
easier (hah!) by using some functionality that seems to be built in to  
the sql DAs (gadfly, postgresql) themselves, namely the tables()  
method.

Like so:

class zBusView(SimpleItem):
	"""A Business View Object"""
	meta_type = "zBusView"
	def __init__(self, id, title, connectionID):
		self.id = id
		self.title = title
		self.connectionID = cID = connectionID
		gf = 'GetFields'
		sql="""select * from <dtml-var tablename> where 1=0"""
		setattr(self, gf, SQL(gf, '', cID, 'tablename', sql))
		conn = getattr(self, cID)
		setattr(self, 'GetTables', conn.tables)

I initially thought the getattr() call would resolve upward in the  
object hierarchy, but as you probably know, it is only looking inside  
the attributes of the class. Is there any way to do this? Do I need to  
inherit from another class or two? Later I would like to put that  
getattr() in a separate class method that resolves the reference in  
real time, but I'm trying it here first. What is most puzzling to me is  
that the first setattr creating the zsql method resolves to a database  
connection without difficulty, but the getattr() fails. Thanks very  
much for your help thus far.

Truly vexed,

Richard


















On 09/24/2004 12:14:26 PM, Dieter Maurer wrote:
> Richard Rosenberg wrote at 2004-9-22 23:07 +0000:
> > ...
> >I am working on creating a zope product that uses multiple DTML  
> pages
> 
> >to gather information from the user before actually constructing the
> 
> >product class, sort of like a 'wizard' interface. I am pretty new to
> 
> >this, so please bear with me.
> >
> >The idea is that __init__.py exposes the appropriate DTML form for
> step
> >1 in the process, as well as the relevant module level function,
> e.g.,
> >
> >def initialize(context):
> >    context.registerClass(module.class,
> >    permission="Add class_name",
> >    constructors=(module.Step1Form, module.Step1Func))
> >
> >Step1Func would then return another DTML page/form called Step2Form
> >
> >Step2Form gets more info from the user and calls Step2Func
> >
> >Step2Func processes the returned info and in turn returns
> StepFinalForm
> >StepFinalForm calls StepFinalFunc which actually instantiates the
> class
> >and does self._setObject and all of that good stuff.
> 
> You must declare all your "Step<i>{Form|Func}" as constructors
> (like you did for "i==1"). This declarations makes them
> available via the "product context" (where you are when you
> are creating a new object in the standard way).
> 
> --
> Dieter
> 
> 
> 
> 




More information about the Zope mailing list