[Zope-dev] Recursive folders from Python
Phil Harris
phil.harris@zope.co.uk
Tue, 31 Oct 2000 09:32:21 -0000
Try something like (taken from my own code, so it works for me, caveta
emptor):
def mkcontext(self,context=None):
global default_dd
if not context:
return 'EH!!!!!'
c=string.split(context,'/')
newself=self
for a in c:
try:
newself.manage_addFolder(a,createPublic=0,createUserF=0,REQUEST=getattr(self
,'REQUEST',None))
except:
pass
newself=getattr(newself,a) ## this is the relevant line
newself.manage_addLocalRoles(c[-1],['Manager'])
try:
newself.manage_addDTMLMethod('index_html','Start
Page',file=default_dd)
except:
pass
This func takes a slash separated list of folders (actually a NDS context
like 'dacs/media/stf/wmlph' and creates the folder hierarchy.
It's probably overkill for what you want but the relevant line is the
getattr one (as marked).
hth
Phil
----- Original Message -----
From: "Dieter Maurer" <dieter@handshake.de>
To: "Jason Spisak" <444@hiretechs.com>
Cc: <zope-dev@zope.org>
Sent: Monday, October 30, 2000 6:43 PM
Subject: Re: [Zope-dev] Recursive folders from Python
> Jason Spisak writes:
> > Does anyonw know why this code won't create a folder within a folder.
> > It's tells me the id is already in use, so that means it's not
> > descending into the newly created folder to make another folder.
> >
> > def create(self):
> > for digit in range(0, 10):
> > folder = self.manage_addFolder(str(digit), str(digit))
> > subfolder = self.folder.manage_addFolder(str(digit),
str(digit))
> Apparently, the above line should add a new folder in (say) '00'.
> What it does, however, is trying to add the new folder in the object named
> 'folder' (accessible from 'self'). This may well go wrong.
>
> Keep in mind, that the local name space of the function 'create'
> (where your variable 'folder' lives) is disjunct from the attribute
> namespace of 'self' (where the attribute 'folder' lives).
>
>
> Dieter
>
> _______________________________________________
> Zope-Dev maillist - Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope )