[Zope] "dtml_source"
Tony McDonald
tony.mcdonald@ncl.ac.uk
Sat, 10 Apr 1999 07:15:39 +0100
> Someone posted an External Method to display DTML Document source recently.
> I've modified it to interpret paths, so now one can say:
> http://www.zope.org/dtml_source?path=/x/y/z
> and it will show the source of z, an object inside y, which is an object
inside x.
> And so on. Maybe there's a reason the original didn't do this?
>
> Anyway, here's my version of Extensions/dtml_source.py :-
>
> import string
> def view_source(self, path):
> "View the source of a Document"
> for id in string.split(path, '/'):
> if not id:
> continue # Leading /
> if id not in self.objectIds():
> id = None
> break
> # Walk down object hierarchy
> self = getattr(self, id)
> if not id:
> self = getattr(self, 'index_html')
> return self.read_raw()
>
I think that the confusion over dtml_source is due to its 'zopish' behaviour
... :)
Using the 'old' dtml_source, urls such as
server.org/dtml_source?path=/ninja/turtle/index_html only gets you the
source of the top level index_html
This is the way you would type in the URL to a non-zope system (ie the
dtml_source 'lives' at the top level of the 'directory' and so everything is
'underneath' it)
However, if you try the url
server.org/ninja/turtle/dtml_source?path=index_html
you get the source of the index_html at the level of 'turtle'. A *huge*
lightbulb went on when I tried this.
This is the 'zopish' way and uses acquisition to get the job done, ie
dtml_source is 'called' at the level of turtle, which doesn't find it and
passes it up to ninja who also passes it to the top level ('/' in unix
parlance) who can process the request because it finds dtml_source at its
level in the heirarchy.
hope this helps,
tone.