Setting title in an external method
Hi all -- A common idiom around here is to use an external method to process a form and, if an error that the user can't fix occurs -- eg. you can't view such-and-such an object because it doesn't exist, or you don't have privileges -- use "return" to show them the contents of a DTML method that explains the problem. Here's a simple example: def my_xm (self, REQUEST=None, RESPONSE=None): # ... churn away, processing the form ... return self.my_dtml (self, REQUEST, RESPONSE) Here's the source for the "my_dtml" DTML method: <dtml-var standard_html_header> title: <b><dtml-var title></b><br> document_title: <b><dtml-var document_title></b> <p> This is the <dtml-var document_id> Document in the <dtml-var title_and_id> Folder. </p> <dtml-var standard_html_footer> Both "my_xm" and "my_dtml" are in the root directory of an almost-fresh Zope 2.1.4 installation. The problem is that the "title" when I call "my_xm" (ie. the "Title:" HTTP header and "<TITLE>" HTML tag) is just "Zope", which I presume is the title *of the folder* containing the external method. Yuck. I want the form result to have a title of its own, eg. "Error Viewing Blah-blah". What's the best way to do this? Possibilities that occur to me: * redirect to the error-reporting DTML Method instead (but I like to keep the number of redirects to a minimum) * use a DTML Document instead of a Method (not sure if this will work, and sometimes I really do want it to be a method -- eg. it might be called from within a larger Document in some context) * set some magical attribute of 'self' or 'RESPONSE' in the external method; I tried "RESPONSE.setHeader ('Title', 'My Title')", but that didn't work Any other ideas? Thanks -- Greg -- Greg Ward - software developer gward@cnri.reston.va.us Corporation for National Research Initiatives 1895 Preston White Drive voice: +1-703-620-8990 Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
Greg Ward wrote:
Hi all --
A common idiom around here is to use an external method to process a form and, if an error that the user can't fix occurs -- eg. you can't view such-and-such an object because it doesn't exist, or you don't have privileges -- use "return" to show them the contents of a DTML method that explains the problem.
<snip>
* set some magical attribute of 'self' or 'RESPONSE' in the external method; I tried "RESPONSE.setHeader ('Title', 'My Title')", but that didn't work
Try just REQUEST.set('title', 'Foo') -Michel
On 08 March 2000, Michel Pelletier said:
* set some magical attribute of 'self' or 'RESPONSE' in the external method; I tried "RESPONSE.setHeader ('Title', 'My Title')", but that didn't work
Try just REQUEST.set('title', 'Foo')
Nope -- that doesn't do it. It does raise a lot more questions, though. :-( Recap: I'm working in a near-fresh Zope 2.1.4 installation. Everything's in the root folder. Two objects of interest: my_dtml_meth - a DTML method that shows the document title, ID, etc. (because I'm curious); the title for this object is "Test DTML Method" my_xm - an external method that does nothing except attempt to set the document title and call my_dtml_meth; the title for this object is "External Method: Call DTML Method" The code has changed a bit since my last post, so here we go again. Here's my_dtml_meth (the DTML Method): <dtml-var standard_html_header> id: <b><dtml-var id></b><br> title: <b><dtml-var title></b><br> document_title: <b><dtml-var document_title></b><br> document_id: <b><dtml-var document_id></b><br> title_or_id: <b><dtml-var title_or_id></b><br> title_and_id: <b><dtml-var title_and_id></b><br> <dtml-var standard_html_footer> And here's my_xm (the external method that calls my_dtml_meth): def my_xm (self, REQUEST=None, RESPONSE=None): RESPONSE.setHeader ('Title', "Title from External Method (try 1)") REQUEST.set ('title', "Title from External Method (try 2)") return self.my_dtml_meth (self, REQUEST, RESPONSE) Note that I'm trying two attempts to set the title; my original guess based on reading the HTTPResponse code, and Michel's suggestion. Here's what happens when I call these things. First, my_dtml_meth, as rendered in Netscape: id: title: Zope document_title: Test DTML Method document_id: my_dtml_meth title_or_id: Zope title_and_id: Zope () Ie. it's possible to get the object's title using "document_title" -- but the standard_html_header uses "title", so my browser's window advertises this document as "Zope". Ugh. Guess I could fix standard_html_header, but why does it work this way? Now I call my_xm, hoping against hope that it will override the title of my_dtml_meth; here's what I get: id: title: Zope document_title: Test DTML Method document_id: my_dtml_meth title_or_id: Zope title_and_id: Zope () Hmmm... identical. Ie. neither attempt to set the title in my_xm had any affect whatsoever. In fact, I just used a command-line HTTP client to diff the headers and body, and they compare byte-for-byte. So: no dice. Better ideas, anyone? (I think I've learned enough to solve my problem, though: use document_title rather than title in standard_html_header, and make sure the DTML method in question has a meaningful title. But I'm still curious why things work the way they do.) Thanks -- Greg -- Greg Ward - software developer gward@cnri.reston.va.us Corporation for National Research Initiatives 1895 Preston White Drive voice: +1-703-620-8990 Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
On Wed, 8 Mar 2000 12:10:07 -0500, Greg Ward <gward@cnri.reston.va.us> wrote: <snip problem details>
The problem is that the "title" when I call "my_xm" (ie. the "Title:" HTTP header and "<TITLE>" HTML tag) is just "Zope", which I presume is the title *of the folder* containing the external method. Yuck. I want the form result to have a title of its own, eg. "Error Viewing Blah-blah".
What's the best way to do this? Possibilities that occur to me:
* use a DTML Document instead of a Method (not sure if this will work, and sometimes I really do want it to be a method -- eg. it might be called from within a larger Document in some context)
This should work, is 'The Right Thing'. If you are using a DTML Method, then it will be a method *of the folder* containing the method. DTML method's dont add a namespace of their own, so <dtml-var title_or_id> is supposed to give you the folder's title. Toby Dickenson tdickenson@geminidataloggers.com
participants (3)
-
Greg Ward -
Michel Pelletier -
Toby Dickenson