[Zope] acquisition context within product method

Richard Rosenberg richrosenberg at earthlink.net
Wed Sep 22 19:07:26 EDT 2004


Hello All:

Do any of you have an idea about how to solve the followong problem:

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.

Using this approach, I get through Step1Form and Step1Func OK, but when  
Step1Func attempts to return Step2Form, it appears to have no  
acquisition context and returns KeyErrors like:

Error Type: KeyError
Error Value: standard_html_header

. . .or AttributeErrors like:

Error Type: AttributeError
Error Value: aq_parent

For example:

#This is a module to create an object in steps
from OFS.SimpleItem import SimpleItem
from Globals import DTMLFile

Step1Form = DTMLFile("dtml/Step1Form", globals())
Step2Form = DTMLFile("dtml/Step2Form", globals())
StepFinalForm = DTMLFile("dtml/StepFinalForm", globals())

def Step1Func(self, REQUEST):
	"""This is the doc string"""
	request = REQUEST

	. . .more code in here. . .

	return Step2Form(self, request)

def Step2Func(self, REQUEST):
	"""This is the doc string"""
	request = REQUEST

	. . .yet more code. . .

	return StepFinalForm(self, request)

def StepFinalFunc(self, REQUEST):
	"""This is the doc string"""
	request = REQUEST

	. . .and yet more code. .

	newClass=someClass(id, title, moreArgs)
	self._setObject(id, newClass)

	return self.manage_main(self, request)


To make a long story even longer. . .is there a way to wrap a returned  
DTML document in an intact acquisition context?
I've tried .__of__(self) tacked on to the return statement but it seems  
as if it is the 'self' object that lacks an acquisition context. I've  
also tried making the DTML an attribute of a class that inherits from  
SimpleItem, which gives the KeyError on standard_html_header  
(incidentally, none of the DTML includes references to  
standard_html_anything).

If anyone knows of a product that uses a multi-step construction  
process prior to instantiation and ZODB storage I'd love to see how it  
works.

Thanks for any thoughts.

Richard








More information about the Zope mailing list