Wichert Akkerman schrieb:
> 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.

there are two places where you can put your code, in both cases
acquisition is fully functional.
if it is ATContentTyoe based you can add a method:

    # AT specific, called after creation of the final
    # instance
    def at_post_create_script(self, member_id=None):
        da = getattr(self, 'MyDA', None)

or if it is a "mere" CMF content type:

    def manage_afterAdd(self, item, container):
            Add self to the catalog.
            (Called when the object is created or moved.)
        da = getattr(self, 'MyDA', None)

fn:Robert  Rottermann
tel;work:++41 31 333 10 20
tel;fax:++41 31 333 10 23
tel;home:++41 31 333 36 03

Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to