Re: [Zope3-Users] Re: Creating objects in software space when making site

2006-03-08 Thread Joseph Method
This is just work for you, but you could put up a list mapping recipe
description to thread. But then others could help distill and annotate
the recipes.

On the question of where to put it, I have a heretical suggestion:
plone.org. Plone developers are trying to understand Zope 3.

On 3/8/06, Andreas Elvers [EMAIL PROTECTED] wrote:
 Joseph Method wrote:
  This should definitely be a prominent How-To somewhere.
 
 [...]

 Oh yes... Some kind of How-To/Recipe page would be very helpful. I'm using
 thunderbirds full-text search to find hidden recipes in zope3 user/dev
 mailing lists.

 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users



--
-J. Method
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Creating objects in software space when making site

2006-03-07 Thread Michael Howitz
Am Dienstag, den 07.03.2006, 12:49 +0100 schrieb Florian Lindner:
 Hello,
 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__
 
 implements(ICentershock)
 
 def __init__(self):
  Makes this object a site and add some required utitlies.
 bare = removeAllProxies(self)
 sm = site.LocalSiteManager(bare)
 self.setSiteManager(sm)
 
 
 That gives the wierd error:
 
   File /home/florian/Zope3/src/zope/interface/adapter.py, line 481, in 
 subscribers
 subscribers = [subscription(*objects)
   File /home/florian/Zope3/src/zope/app/container/contained.py, line 183, 
 in 
 dispatchToSublocations
 for sub in subs.sublocations():
   File /home/florian/Zope3/src/zope/app/container/contained.py, line 214, 
 in 
 sublocations
 for key in container:
   File /home/florian/Zope3/src/zope/app/container/sample.py, line 56, in 
 __iter__
 return iter(self.__data)
 AttributeError: 'Centershock' object has no attribute '_SampleContainer__data'
 
 
 Any idea?

How about calling
 super(Centershock, self).__init__(*args, **kw)
But this will not work because during __init__ you have no context which
is needed by the site manager.

Try to subscribe to the ObjectAddedEvent.


-- 
Mit freundlichen Grüßen

Michael Howitz

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Creating objects in software space when making site

2006-03-07 Thread Joseph Method
This should definitely be a prominent How-To somewhere.

On 3/7/06, Andreas Elvers [EMAIL PROTECTED] wrote:
 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.

 Any other ways of doing this ?

 - Andreas

 in your browser configure:

 configure
xmlns=http://namespaces.zope.org/browser;

addform
  label=Add foo with initialization
  name=AddMyContent.html
  class=.foo.AddFoo
  schema=myapp.interfaces.IFoo
  content_factory=myapp.foo.Foo
  fields=name
  permission=zope.ManageContent
  /
 ...
 /configure

 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)

  # Catalog setup

  cat = Catalog()
  addLocalUtility(bare,'fooCatalog',
  ICatalog,
  cat)
  notify(ObjectCreatedEvent(cat))

 I found addLocalUtility somewhere in the zope mailing lists.

 from zope.app import zapi
 from zope.app.container.interfaces import INameChooser
 from zope.app.component.interfaces.registration import ActiveStatus
 from zope.app.component.interfaces import ISite
 from zope.app.utility import UtilityRegistration

 def addLocalUtility(site, name, iface, utility, package='default'):
  Add a utility to a site

  The utility is added to the package and activated.
  This assumes the site has already a Utility Service.
  

  # preconditions
  if not ISite.providedBy(site):
  raise TypeError('ISite required.')

  # get site manager and site management folder
  sitemanager = site.getSiteManager()
  default = sitemanager[package]

  # add utility to site management folder
  chooser = INameChooser(default)
  folder_name = chooser.chooseName(utility.__name__, utility)
  default[folder_name] = utility

  # create service registration
  path = zapi.getPath(utility)
  registration = UtilityRegistration(name, iface, utility)
  key = default.registrationManager.addRegistration(registration)
  zapi.traverse(default.registrationManager, key).status = ActiveStatus

  return zapi.traverse(sitemanager, path)

 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users



--
-J. Method
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users