[Zope] Testing for how an object is called.

Casey Duncan cduncan@kaivo.com
Fri, 25 May 2001 08:36:09 -0600


kosh@aesaeion.com wrote:
> 
> I have several kludge ways now that do the job but none I entirely like.
> How can I check for the difference between being called with <dtml-var
> foo> and being called from foo.com/foo ?
> 
> This behavior is used for both internal and external behavior of the
> object.
> 
> Thanks
> 
> Designing the webpages of tomorrow http://webme-eng.com
> Designing the MMORPGS of tomorrow http://worldforge.org
> 

Here is the best way I can think of:

<dtml-if expr="REQUEST.steps[-1] == document_id">
	...Then we were called from the URL...
<dtml-else>
	...We weren't...
</dtml-if>

This won't work with index_html methods or documents that are called by
specifying the URL of their parent, but you could extend the expression
to work in that case as well.

If the thing is a python script then it would be:

if context.REQUEST.steps[-1] == script.getId():
	...We were called by URL...
else:
	...We weren't...


-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>