[ZPT] How Do I Use ZPT Output In Python Code?
Dieter Maurer
dieter@handshake.de
Mon, 12 Aug 2002 21:51:16 +0200
Shane McChesney writes:
> ...
>
> Not sure how clear that is, but post any follow-up
> questions and I'll respond as quickly as possible.
I did not got it, but I am not interested enough to try
hard to understand it...
> ...
> I have built a management page that lets me click on a
> button to fire the "setQuestionUI" method, which should
> apply the question template ZPT to the Question instance,
> then store the results in the "QuestionUI" property of the
> instance.
The result is what? A string, a list, a what?
How should it be interpreted?
> It runs without erroring out (at least the
> versions below do), but I don't get the expected result. I
What do you expect?
> want the XHTML results in that property, not the stuff
> you'll see below.
A property does not have "XHTML" results, it is of a simple
datatype: a string, a list, a datetime, ...
> def setQuestionUI(self, REQUEST = None):
> "Generate the appropriate XHTML representation for this
> question."
> thePTFile = PageTemplateFile('www/viewQuestion',
> globals(), __name__ = 'thePTFile')
> self.QuestionUI = thePTFile
>
> if REQUEST is not None:
> return self.manage_main(self, REQUEST)
>
> ..populates the QuestionUI property with...
>
> <PageTemplateFile instance at 02197AD0>
That's the Page Template instance itself. You need to call
it, in order to render it.
> --------------------------------------------------
> While this approach...
>
> def setQuestionUI(self, REQUEST = None):
> "Generate the appropriate XHTML representation for this
> question."
> thePTFile = PageTemplateFile('www/viewQuestion',
> globals(), __name__ = 'thePTFile').document_src()
> self.QuestionUI = thePTFile
>
> if REQUEST is not None:
> return self.manage_main(self, REQUEST)
>
> ..populates the QuestionUI property with...
>
> <!-- Page Template Diagnostics
> Macro expansion failed
> exceptions.TypeError: object of type 'string' is not
> callable
> -->
It lacks acquisition context (and therefore its bindings).
But it would not give you what you like, anyway. When it starts
working, it will give you the Page Template source. I doubt
very much that you can do something with it.
Your method "setQuestionUI" is context independent (i.e. a constant).
Almost sure, you do not want this.
Assume, you want the rendered result of the ZPT in your property,
then you would use:
thePTFile= PageTemplateFile(...).__of__(self)
self.QuestionUI= thePTFile()
It would be even better, when you moved the "PageTemplateFile" out
of the method into a class variable:
thePTFile= PageTemplateFile(...)
def setQuestionUI(self):
....
self.QuestionUI= self.thePTFile()
Dieter