[Twisted-web] Adding Athena JS handlers in render methods?

kgi iacovou at gmail.com
Wed Aug 1 09:07:15 EDT 2007


On Monday 30 July 2007 17:25:43 Jean-Paul Calderone wrote:

> It's unsupported.  What you can do instead is to put the event handlers
> into the template (stan or xhtml) as patterns.  This will result in them
> being rewritten properly.  Your render and data methods will thus be able
> to load them, already pre-processed, from the docFactory and put them in
> the page.

Hi Jean-Paul; thanks for your answer; that makes a lot of sense.

In the meantime I worked around the problem by inserting the "expanded" 
javascript (that is, Nevow.Athena.Widget.handleEvent()) into the stan in the 
special methods. It's hacky but it works - I'll implement your suggestion 
next time I visit that piece of code.

If you're not fed up with Athena-related questions, I do have another one.

At the moment I've got some active content in a LiveElement that I update 
multiple times throughout the lifetime of a page. This updating is done by JS 
DOM manipulation on parameters that get passed over an Athena call (paying 
greater client complexity and load in return for lower server load and lower 
bandwidth).

However, the content has to have *something* when the LiveElement is first 
rendered, so I'm having to implement the same logic twice: once in the stan 
to provide the initial content, and once in the JS to update the page.

I'd like to kill the stan version by arranging to call the LiveElement's 
update code after the page has rendered; however, I'm unsure where the hook 
should go. I already have code to allow the LiveElements to request a 
callback, I just need to know when the Athena link is up and running.

Digging about a bit, I can see that rend.Page's self.afterRender gets called 
after renderHTTP, if it's defined, but this is too early: it gets called when 
rendering has been done on the *server*, way before the browser even starts 
requesting the various page elements (JS files, CSS files, etc). That also 
rules out trying to hook onto LivePage's _becomeLive, because that gets 
called even before renderHTTP. LivePageFactory's addClient() runs similarly 
early.

I've even considered having a special child resource (a 1x1 transparent image, 
say), placed towards the bottom of the body, access to whose resource path 
triggers the process of updating the LiveElements, but that's really the last 
resort.

Is there an approved way to achieve this?

Thanks,

Ricky



More information about the Twisted-web mailing list