[mod_python] evaluation psp for inclusion in psp

David Bear David.Bear at asu.edu
Tue May 23 21:42:16 EDT 2006


I am using publisher.

I have one psp template that I would like to evaluate for inclusion
into another psp template.

I thought I could do something like this:

==================================
def _get_psp(req, name="blank.ptml", vars={}, docroot=THISROOT, template=TEMPLATES):
    '''
    expects a docroot, template path and name of footer,
    returns a string containing the contents of the file named
    name'''
    fn = os.path.join(docroot, template, name)
    try:
        os.path.exists(fn)
    except IOError:
        inc = "File %s NOT Found" % fn
    ipsp = psp.PSP(req, filename=fn)
    ipsp.run(vars)
    return ipsp
==================================

then use it like this:

==================================
def index(req):
    '''
    default page
    '''
    fd = {}
    pspinclude = _get_psp(req, "registrationForm.ptml", {"submit":
"http:"})
    fd["formname"]="regform1"
    fd["form"]=pspinclude
    return _any_page(req, fd, MAINTEMPLATE )
==================================

But the psp.run method writes directly to the req object and the prior
to anything being returned from _any_page(). I want a psp method that
returns a string of html (base on a psp template). Is there a psp
method that does that?

btw, perhaps my thinking is skewed on using psp. I'm trying structure
things similar to the way zope page templates TAL and METAL work...
but that may be too much of a stretch for psp and publisher.

-- 
David Bear
phone: 	480-965-8257
fax: 	480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
 "Beware the IP portfolio, everyone will be suspect of trespassing"


More information about the Mod_python mailing list