[Zope] Traversal Issue (brain fart)
Richard Shebora
richard at apogaion.com
Wed Sep 17 14:16:05 EDT 2003
Paul and All,
Thanks for the reply. I see your point about the error trapping. I
just got started in Python because it all seems more elegant than the
DTML I am used to. The indents were just cut and paste problems.
It seems I am not that far off the target. I do know the difference
between a variable name and the value it represents, but I tried many
ways to represent the following example in a loop that assigned the
values to "folder1" and so on and have failed. I don't know the syntax
to get it done and over the past two weeks have not found it. I have
noticed that many times the answer is out there, but I just don't know
the right keywords to find it. I have often found the answer to a
different question when searching for something.
Fixed paths to create the folders... This make sense to me.
=======================================================
container.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder1,
'Folder 1','')
container.folder1.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder2,
'Folder 2','')
container.folder1.folder2.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder3,
'Folder 3','')
container.folder1.folder2.folder3.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder4,
'Folder 4','')
container.folder1.folder2.folder3.folder4.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder5,
'Folder 5','')
print 'Done'
return printed
Variable paths to create the folders... This is where I get confused
about the syntax.
The first two are created fine. I get a key error on the third level.
Which means I am using the variables incorrectly. But how?
=======================================================
folder1='folder01'
folder2='folder02'
folder3='folder03'
folder4='folder04'
folder5='folder05'
container.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder1,
folder1,'')
folder=container[folder1]
folder.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder2,
folder2,'')
folder=container[folder2]
folder.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder3,
folder3,'')
folder=container[folder3]
folder.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder4,
folder4,'')
folder=container[folder4]
folder.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folder5,
folder5,'')
print 'Done'
return printed
Any clarity on this specific issue would make my day.
Thanks,
Richard
Paul Winkler wrote:
>On Wed, Sep 17, 2003 at 12:08:41PM -0400, Richard Shebora wrote:
>(snip)
>
>>#02 CREATES INBOUND FOLDER IF NEEDED.
>>folderid='INbound'
>>foldertitle='Inbound Documents'
>>try:
>>
>>container.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(folderid,
>>foldertitle,'')
>>
>
>hmm, the indentation is screwy. I assume that is just an email cut/paste
>problem, or this script would never run at all.
>
>
>> print 'Inbox Folder '+folderid+' Created'
>>except:
>> print 'Inbox Folder '+folderid+' Already Exists'
>>
>
>Note that this is very risky. YOu should find out what error
>happens when the folder already exists, and catch only that error.
>If anything else goes wrong you will hide it behind a misleading
>"Already exists" message.
>
>(snip)
>
>>#08 CREATES DOCUMENTS IN CURRENT TRADING PARTNER'S DOCUMENT FOLDER
>> if fields[0]=='ST':
>> DOCid=DOCtype+'-'+DOCindex
>> DOClocation = TPdocs[DOCtype] # sets current folder
>> try:
>>
>>DOClocation.manage_addProduct['PropertyFolder'].manage_addPropertyFolder(DOCid,DOCtitle,'')
>> print DOCid+' '+DOCtitle+' Created'
>> except:
>> print DOCid+' '+DOCtitle+' Already Exists'
>>
>>09 CREATE DOCUMENT SEGMENTS # This is the goofy section that fails.
>> SEGlocation=context.DOCid # sets current folder
>>
>
>Look at that last line. DOCid is a variable.
>You are asking context for something literally named "DOCid",
>when I think you want to ask for something whose name is the
>value of DOCid. Be sure you understand the difference.
>
>You already know one way to do this correctly in zope,
>since you do it numerous times elsewhere in the script ;-)
>
>Also I doubt that context is where you want to look. Since
>you just created the DOCid-named item in DOClocation,
>maybe that's where you should look for it.
>
>
More information about the Zope
mailing list