[Zope-CMF] Accessing the "context"

Wichert Akkerman wichert at wiggy.net
Tue Oct 30 12:40:50 EDT 2007


Previously Charlie Clark wrote:
> 
> Am 30.10.2007 um 17:04 schrieb Andrew Sawyers:
> 
> >If it's in a content type's class, why not:
> >id = getattr(self, 'da_id', None)
> >Just using self as the context should be fine.
> >-- that of course presumes that the type is wrapped properly when  
> >you call that within your method.
> 
> mm, currently getting None back so I guess I'm not wrapping things  
> properly.
> 
> This is a skeleton bit of code:
> 
> class ContentType(PortalContent):
>     """A content type with access to an external database"""
> 
>     def __init__(self, id):
> 	self.id = id
>         DA = getattr(self, 'MyDA', None)
> 	#self.conn = DA() # not working at the moment because DA is None
> 
> Is it wrong to try and do this in my __init__ ? Regarding your other  
> suggestion: yes, I probably will factor this out into a utility once  
> I've worked out how to access the DA!!!

__init__ is indeed the wrong place: when the instance is created it is
not placed in an acquisition context yet.

Wichert.

-- 
Wichert Akkerman <wichert at wiggy.net>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.


More information about the Zope-CMF mailing list