Re: [Zope3-Users] make a Folder a Site
Ivo van der Wijk wrote: > What I currently do is: > > Derive from Folder and SiteManagerContainer, and in the __init__ do > the following: > > self.setSiteManager(LocalSiteManager(self)) > ## required for getUtility to work within this request > setSite(self) ^ | -+ I read your reply, but I basically read it to quickly and missed the setSite() hook. And of course, that was why I couldn't get to utilities I added to my site. So, now I can :-) Thanks. kind regards, jw -- Jan-Wijbrand Kolman [EMAIL PROTECTED] ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] make a Folder a Site
Jan-Wijbrand Kolman wrote: Ivo van der Wijk wrote: What I currently do is: Derive from Folder and SiteManagerContainer, and in the __init__ do the following: self.setSiteManager(LocalSiteManager(self)) ## required for getUtility to work within this request setSite(self) (actually I'm doing this from an event handler, but it should just work from __init__ afaik) Thanks! I'm doing so now from a event handler too instead of from the add view. Doing this in the __init__ didn't work, since at that time there appears not to be enough context for creating a LocalSiteManager. We wrote a little initializer package that should support such usecases. svn://svn.tiks.org/repos/Tiks/trunk/src/tiks/initializer - see README.txt for details If anybody is interested we could extend that package and move it to the zope 3 repository Regards, Dominik Huber ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] make a Folder a Site
Ivo van der Wijk wrote: > What I currently do is: > > Derive from Folder and SiteManagerContainer, and in the __init__ do > the following: > > self.setSiteManager(LocalSiteManager(self)) > ## required for getUtility to work within this request > setSite(self) > > (actually I'm doing this from an event handler, but it should just > work from __init__ afaik) Thanks! I'm doing so now from a event handler too instead of from the add view. Doing this in the __init__ didn't work, since at that time there appears not to be enough context for creating a LocalSiteManager. regards, jw -- Jan-Wijbrand Kolman [EMAIL PROTECTED] ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] make a Folder a Site
On 5/25/05, Jan-Wijbrand Kolman <[EMAIL PROTECTED]> wrote: > Hello, > > (..) > 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: > What I currently do is: Derive from Folder and SiteManagerContainer, and in the __init__ do the following: self.setSiteManager(LocalSiteManager(self)) ## required for getUtility to work within this request setSite(self) (actually I'm doing this from an event handler, but it should just work from __init__ afaik) Cheers Ivo -- Drs. I.R. van der Wijk -=- Korte Leidsedwarsstraat 12 Amaze 1017 RC Amsterdam, NL -=- T +31-20-4688336 F +31-20-4688337 Zope/Plone/Content Management W http://www.amaze.nlE [EMAIL PROTECTED] Open Source Solutions W http://vanderwijk.info E [EMAIL PROTECTED] Consultancy PGP http://vanderwijk.info/pgp ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] make a Folder a Site
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 [EMAIL PROTECTED] ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users