[Zope-dev] Put an adapted object in context
Martijn Faassen
faassen at infrae.com
Thu Feb 12 14:09:13 EST 2004
Santi Camps wrote:
> My problem is that the adapter object, and also the adapted object
> contained in it, are out of publisher context or something like this.
> For instance, absolute_url() methods doesn't work becouse REQUEST is not
> defined.
I'm not sure I understand what you mean; I don't understand why your
adapted object would become detached from the original context.
It looks like you're losing acquisition context. You put an object into
acquisition context explicitly. Something along these lines:
import Acquisition
class MyAdapter(Acquisition.Explicit):
def __init__(self, context):
self.context = context
def getAdapter(context):
# create adapter for context, and wrap it explicitly in the acquisition
# context
return MyAdapter(context).__of__(context)
This works to give the adapter among other things a security context,
so you can call methods on the adapter from a page template, for instance.
You can also get to REQUEST and such, though in this case I used explicit
acquisition so you'll have to use self.aq_acquire.REQUEST, if I recall
the syntax correctly.
Regards,
Martijn
P.S. In the course of the coming weeks I'll be backporting parts of Zope 3's
component architecture, especially adapters, into Zope 2. Contact me if
you're interested. I also expect I'll be making more noise about this in
a few weeks.
More information about the Zope-Dev
mailing list