[Zope] accessing object from a list constructed in __init__.py

kevin7kal plone at kevinkal.com
Sat Jul 22 15:20:27 EDT 2006


Ok, thank you for that.
I can create the list of objects from the __of__(self) attribute without 
the wrapper error now,
but I still cannot access that attribute through zope.
Here is my code again, along with my zope content.

---myClass.py---
import Acquisition

class class1(Acquisition.Explicit):
    ''' a simple class with some attributes and methods'''
    attribute1 = 'attribute 1'
    attribute2 = 'attribute 2'
    _number = ''
    def __init__(self,number2):
        '''simple init for the class'''
        self._number=number2*3
       
    def method1(self):
        '''return a string methd1'''
        mthd1 =  'methd1'
        return mthd1
    def method2(self):
        ''' return a string methd2'''
        mthd2 = 'method2'
        return mthd2
    def _get_number(self):
        return self._number
    number = property(fget=_get_number)
                     
class class2(Acquisition.Explicit):
    ''' a second simple class with some attributes and methods'''
    attribute1a = []
    attribute2a = []
    def __init__(self):
        '''create a list of class1 objects in attribute1a'''
        i=1
        while i < 5:
            obj = class1(i)
            self.attribute1a.append(obj.__of__(self))
            i=i+1
       
    def method1a(self):
        '''instantiate class1 as object and return object usable by zope'''
        obj = class1(5)
        return obj.__of__(self)
    def method2a(self):
        '''returns class1.method1()'''
        c1m1 = class1.method1()
        return c1m1
    attribute1b = property(fget=method1a)
    attribute2b = property(fget=method2a)

----myZclass.py-----
from zope.interface import implements
from zope.schema.fieldproperty import FieldProperty
from OFS.SimpleItem import Item, SimpleItem
from persistent import Persistent
import myClass
from interfaces import *
import Acquisition

class Zclass2(SimpleItem,myClass.class2,Acquisition.Explicit):
    '''a simple zope class that inherits from my class'''
    implements(Izclass2)
    def __init__(self,tmpID='',tmpTITLE=''):
        '''non empty docstring'''
        cm = myClass.class2.__init__(self)
        return cm.__of__(self)

    def myZclass(self):
        cm = myClass.class2()
        return cm.__of__(self)


Alexis Roda wrote:
> En/na kevin7kal ha escrit:
>> I'm doing some work with Five and have an aquisition related issue.
>> first, zope is zope 2.9.3
>> The trouble is with accessing the attributes of objects stored in the
>> number property in class2.
>
> class2 must inherit from ExtensionClass.Base (or some subclass, like 
> Acquisition.Explicit) in order to be acquisition aware.
>
>
>
>
>
> HTH
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>


More information about the Zope mailing list