[Zope] Fully render dtml object from external method - solved !
Dr. Ross Lazarus
rossl@med.usyd.edu.au
Thu, 03 Jun 1999 16:43:52 +1000
At last.
With some help from Kent Polk, I stumbled across a way to do what I
needed. This little external method will spit back a fully rendered html
version of every dtml document (methods work too) in the folder you call
it from. Looks like the calling of the dtml object with self, request
and globals as parameters is the way forward....I'm sure there's a more
elegant way to do this but at least it works.
You need this if you want to (for example) save a fully rendered html
version of your zope pages to a disk file...
#publish test
#rml june 1999
import Globals,DocumentTemplate,string
def rehtml(s=''):
'''
strip out and replace quoted html tags
str(o) seems to return quoted html
not sure what the right call is - but this fixes it...
rml may 1999
'''
rep = [('<','<'),('>','>'),('"','"'),('&','&')]
for rold,nnew in rep:
s = string.join(string.split(s,rold),nnew)
return s
def render_dtml_docs_to_html(self,REQUEST):
s = []
for t in ('DTML Method','DTML Document'):
for docid,doc in self.objectItems([t]):
try:
r = rehtml(doc(self,REQUEST,globals()))
s.append(r)
except:
pass # methods which need request form vars will fail !
return string.join(s,'\n')
--
Dr Ross Lazarus
Associate Professor and Sub-Dean for Information Technology
Faculty of Medicine, Room 126A, A27, University of Sydney,
Camperdown, NSW 2006, Australia
Tel: (+61 2) 93514429 Mobile: +61414872482
Fax: (+61 2) 93516646 Email: rossl@med.usyd.edu.au
http://www.health.usyd.edu.au/people/rossl.htm