Genshi in Nevow, Revisited

Posted on March 27, 2008 by oubiwann


Blog post image

About a year ago, I blogged about usi ng Genshi in Nevow. It was purely an exercise in curiosity on my part: I wanted to know how flexible Nevow's template parsing was. Could I just drop something else in there that was completely different? The answer was yes and no :-)

The "no" part of that was discovered by a kind reader, Karl Bartel, who found that the Genshi templates in Nevow were one-time wonders: after the first render, data was not refreshed. I didn't have time to take a look at why, since Zenoss was occupying so much of my time then. Now that I'm rocking out at Divmod, this sort of thing is more or less my business now :-) What's more, a friend recently made a deeply heart-felt plea to get Genshi working on Nevow, so I took another look tonight.

Here's the "yes" part of that answer :-) This only represents about an hour or so of work, so this hasn't been tested very thoroughly, but there's a trivial way to get last year's old, static code working such that Genshi templates are dynamically rendered in Nevow. Here's what I did to make it work:

  • preserve the original template data in a temp variable
  • reassign to self.template after Nevow's load() method has been called
  • clean Nevow's template cache
That's it :-)

If you want a single template to be able to be processed by both Nevow's templating machinery as well as Genshi's, you're going to have to make some sacrifices in efficiency. However, if you want a pure-Genshi solution for Nevow, you should be able to use this code to get something up in no time.

In addition to the bullet points above, I also did the following:
  • added some "method filters" so that Nevow stuff didn't get called by the Genshi loader
  • checked to see if the python attributes available to the Genshi templates were callable and if so, called them
As usual, leave a comment if you run across any problems.

Technorati Tags: , , , , , , ,

Author oubiwann
Date March 27, 2008
Time 03:05:08
Category
Tags
Line Count 1
Word Count 378
Character Count 3011

Comments?
This blog doesn't use standard (embedded) comments; however, since the site is hosted on Github, if there is something you'd like to share, please do so by opening a "comment" ticket!