I've tried from __init__ so content is self in my case (at least I think so):

from zope.app.component import site
from zope.proxy import removeAllProxies

class Centershock(BTreeContainer, SiteManagerContainer):
    __doc__ = ICentershock.__doc__
    def __init__(self):
        """ Makes this object a site and add some required utitlies."""
        bare = removeAllProxies(self)
        sm = site.LocalSiteManager(bare)

That gives the wierd error:

  File "/home/florian/Zope3/src/zope/interface/adapter.py", line 481, in 
    subscribers = [subscription(*objects)
  File "/home/florian/Zope3/src/zope/app/container/contained.py", line 183, in 
    for sub in subs.sublocations():
  File "/home/florian/Zope3/src/zope/app/container/contained.py", line 214, in 
    for key in container:
  File "/home/florian/Zope3/src/zope/app/container/sample.py", line 56, in 
    return iter(self.__data)
AttributeError: 'Centershock' object has no attribute '_SampleContainer__data'

Any idea?



Am Dienstag, 7. März 2006 10:05 schrieb Andreas Elvers:
> Florian Lindner wrote:
> > Hello,
> > my content object depends on a number of utilities to be present. It is
> > usually also used as a site. During development it happens often that I
> > delete and recreate it.
> > Can I install a hook or something so I can make that these utilies are
> > being created when my objects becomes a site? How do I create utitlies in
> > software space?
> Hi,
> I'm creating a special add view of my application (). If you add a foo
> it will be created with a LocalSiteManager and a catalog. Hope this
> helps.
> Now create the view class you defined in the browser configure.zcml
> inside foo.py:
> from zope.app import zapi
> from zope.proxy import removeAllProxies
> from zope.app.component import site
> from zope.app.catalog.catalog import Catalog
> from zope.app.catalog.interfaces import ICatalog
> from zope.app.event.objectevent import ObjectCreatedEvent
> from zope.event import notify
> from myapp.helper import addLocalUtility
> class Foo(object):
>     class AddFoo(object):
>      """ Add a foo.
>      This special addform class is needed to add special initialization.
> (Catalog init)
>      """
>      def createAndAdd(self,data):
>          content = super(AddFoo, self).createAndAdd(data)
>          # get foo object, stripping off security proxy
>          bare = removeAllProxies(content)
>          # create a LocalSiteManager
>          sm = site.LocalSiteManager(bare)
>          # and assign it to Labor folder
>          content.setSiteManager(sm)
Zope3-users mailing list

Reply via email to