Hello, I'm making a tree out of a StructuredTextDocument e.g.:
StructuredTextDocument([ StructuredTextParagraph(o This is colin's test tree doc., [ StructuredTextParagraph( o most salient overall:, [ StructuredTextParagraph( x. finish this project. and journal project., [ ]) ]) ]), StructuredTextParagraph(o and something else , [ ]), ])
With the following external method:
from ZTUtils import SimpleTreeMaker import StructuredText
def StTree(container, REQUEST, context):
treeobj = context.testdocument #this is a CMFDocument
#Get the EditableBody of a CMFDocument containing structured text. tree_root = StructuredText.Basic(treeobj.EditableBody())
#Note that if I use a ParsedXML Document, everything works fine! #tree_root = context.ParsedXMLTestDoc
tree_name = 'mytree' tm = SimpleTreeMaker(tree_name)
#Change the child access function so it will work with StructuredTextDocument def getKids(object): return object.getChildren()
tm.setChildAccess(function=getKids)
#note the following hack! (it doesn't work all the way, that is my problem) #if I don't do this an error results. tree_root.REQUEST = container.REQUEST
tree, rows = tm.cookieTree(tree_root) rows.pop(0) return {'root': tree, 'rows': rows}
This code works, in that the first indent levels of the structured text are returned as the top-level nodes of the tree.
However, clicking on them does not expand the tree.
If I replace the Structured Text tree_root with a ParsedXML Test document, and comment out the tm.setChildAccess line and the tree_root.REQUEST hack, a working tree document results.
I think this is a problem with the plain StructuredTextDocument lacking it's own request object.
Can anyone give me any pointers?
My goal is to create an easy way to make documents that can be expanded and collapsed like documents in MSWord outline format. If there's a simpler solution, please let me know!
Thanks!
Colin Leath
Colin Leath wrote:
I think this is a problem with the plain StructuredTextDocument lacking it's own request object.
The REQUEST object is an object representing the HTTP REQUEST as is usually acquired, so STD's (nice ;-) obviously aren't managing to acquire the REQUEST in the context you're using them.
Bear in mind that the way some of the TreeMaker stuff works will strip acquisition and may be causing the REQUEST to be lost from the acquisition chain if your STD usage also does something interesting with acquisition.
cheers,
Chris