[Zope-dev] REQUEST object enlightenment needed

Colin Leath cleath@j9k.com
Wed, 25 Sep 2002 20:06:02 +0000


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