[Zope] Problems with QUERY_STRING
Nico de Boer
nico@nfg.nl
24 Jun 2002 10:07:45 +0200
Hi,
I'm trying to do the following:
First I split the QUERY_STRING variable and join it
with dots:
<dtml-let splitpath="_.string.split(QUERY_STRING,'/')"
training="_.string.join(splitpath[1:],'.')">
So I get the following:
training = path.to.training
Then I want to get the attributes of the training with the
dtml-with tag:
<dtml-with "training">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tr><td>Institute:</td><td><dtml-var institute></td></tr>
<tr><td>Location:</td><td><dtml-var location></td></tr>
<tr><td>Title training:</td><td><dtml-var title></td></tr>
<tr><td>Start date:</td><td><dtml-var date_start></td></tr>
<tr><td>Stop date:</td><td><dtml-var date_stop></td></tr>
</table>
</dtml-with>
</dtml-let>
Institute, location etc are attributes of my ZClass Training.
The 'with' tag doesn't work; I get KeyErrors.
Max M gave me the following solution:
You can traverse Zope with a path from code directly. You must use the
restrictedTraverse() method..
Asuming that: QUERY_STRING='path/to/training'
You can just do it like:
<dtml-call "REQUEST.set('training',
getPhysicalRoot().restrictedTraverse(QUERY_STRING))">
<dtml.with training>
... etc.
But the getPhysicalRoot() method gives me a NameError:
NameError: global name 'getPhysicalRoot' is not defined
and an AttributeError when I tried it like this:
<dtml-call "REQUEST.set('training',
PARENTS[1].getPhysicalRoot().restrictedTraverse(QUERY_STRING))">
So I tried the following:
<dtml-call "REQUEST.set('training', ROOT().restrictedTraverse(QUERY_STRING))">
Where ROOT is a Python Script in the Root of Zope that does the following:
return container
But 'training' now is an <Application instance at 91b6bf0>.
Can anyone help me with this problem?
Greetz Nico