[Zope] Setting title in an external method

Greg Ward gward@cnri.reston.va.us
Thu, 9 Mar 2000 16:06:52 -0500


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