[Zope-dev] Adding properties in __init__

2000-11-07 Thread Chris Withers

Hi,

I have a product class that subclasses SimpleItem and PropertyManager.

If I try and add a property in __init__ as so:

self.manage_addProperty('AProperty','1\n2\n3','lines')

I get the following wonderful error:

Error Type: AttributeError
Error Value: aq_base

I'm guessing that this is because self isn't an acquisition wrapper in
__init__ (even though SimpleItem is Acquisition.Implicit) but what am I
supposed to do to add a property in __init__?

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] Adding properties in __init__

2000-11-07 Thread Itamar Shtull-Trauring

Chris Withers wrote:

> self.manage_addProperty('AProperty','1\n2\n3','lines')

> I'm guessing that this is because self isn't an acquisition wrapper in
> __init__ (even though SimpleItem is Acquisition.Implicit) but what am I
> supposed to do to add a property in __init__?

I usually override _properties in the subclass, with the new property
definition, and then doing 

self.Aproperty = '1\n2\n3'

works nicely.

-- 
Itamar S.T.  [EMAIL PROTECTED]
Fingerprint = D365 7BE8 B81E 2B18 6534  025E D0E7 92DB E441 411C

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] Adding properties in __init__

2000-11-07 Thread Toby Dickenson

On Tue, 07 Nov 2000 11:54:57 +, Chris Withers <[EMAIL PROTECTED]>
wrote:

>I have a product class that subclasses SimpleItem and PropertyManager.
>
>If I try and add a property in __init__ as so:
>
>self.manage_addProperty('AProperty','1\n2\n3','lines')
>
>I get the following wonderful error:
>
>Error Type: AttributeError
>Error Value: aq_base
>
>I'm guessing that this is because self isn't an acquisition wrapper in
>__init__ (even though SimpleItem is Acquisition.Implicit) but what am I
>supposed to do to add a property in __init__?

__init__ has no idea of context, so its less useful in Zope than you
might usually expect.

Your object must have a factory method somewhere I suggest adding
an extra method to your object (I always name it '_after_create') and
arrange for it to be called by your factory once the new object is
installed in its container.

Toby Dickenson
[EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] Adding properties in __init__

2000-11-07 Thread Chris Withers

Toby Dickenson wrote:
> 
> Your object must have a factory method somewhere I suggest adding
> an extra method to your object (I always name it '_after_create') and
> arrange for it to be called by your factory once the new object is
> installed in its container.

...yurch! ;-)

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )