[Zope3-Users] make a Folder a Site

Jan-Wijbrand Kolman jw at infrae.com
Wed May 25 06:53:23 EDT 2005


answering myself :)


Jan-Wijbrand Kolman wrote:
> Maybe I miss something very obvious here...
> 
> I created a FooFolder class, subclassing zope.app.folder.Folder. After adding
> the necessary configurations, I have an entry in the addMenu, and I indeed can
> add a FooFolder instance.
> 
> Now I want this FooFolder to become a site right after having added it (so,
> instead of doing this from the ZMI). I naively thought to do this in the
> FooFolder's __init__, like so:
> 
>   from zope.app.folder import Folder
>   from zope.app.site.service import SiteManager
> 
>   class FooFolder(Folder):
> 
>     def __init__(self):
>       super(FooFolder, self).__init__()
>       sitemanager = SiteManager(self)
>       self.setSiteManager(sitemanager)
> 
> This however throws:
> 
>   File "/home/jw/projects/zope3x/lib/python/zope/app/site/service.py", line 81,
> in __init__
>     self._setNext(site)
>   File "/home/jw/projects/zope3x/lib/python/zope/app/site/service.py", line 96,
> in _setNext
>     raise TypeError("Not enough context information")
> 
> 
> Somehow I cannot think of the correct way to do this... Can anyone help? Do I
> need to specify more details?


One way I found, was to register a custom add view class for FooFolders, and
make it override the createAndAdd method, like so:

  from zope.security.proxy import removeSecurityProxy
  from zope.app.site.service import SiteManager

  class AddDocumentLibrary(object):

    def createAndAdd(self, data):
      obj = super(AddDocumentLibrary, self).createAndAdd(data)
      bare = removeSecurityProxy(obj)
      sitemanager = SiteManager(bare)
      bare.setSiteManager(sitemanager)

This works, but maybe there're other ways too?


regards,
jw

-- 
Jan-Wijbrand Kolman
jw at infrae.com


More information about the Zope3-users mailing list