[Twisted-Python] Twisted.web/DOMTemplate
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Okay, I've been doing some hacking trying to make a small application using twisted.web and the .rpy stuff, using DOMTemplate. Ordinarily I'd chat about something like this on the irc channel, but it was dead quiet. Apart from me talking to myself of course. in the template: <P view='getBody'> in the response object def factory_getBody(self, request, node): print 1 return node This (when twistd --nodaemon is used) prints 1 twice (instead of the once expected). This is because of the following section of code: def getNodeView(self, request, node): <snip> maybeWidget = viewMethod(request, node) if isinstance(maybeWidget, domwidgets.Widget): view = maybeWidget viewMethod = view.generateDOM This is *bad*. viewMethod in this instance is response.factory_getBody, and in order to figure out if factory_getBody returns a widget as opposed to an instance of xml.dom.minidom.Element it actually calls the function to have a look. If it doesn't return a widget it *throws the result away*. viewMethod is then returned and used elsewhere, where its actually intended to be used. Considering that rendering a template node could have program logic in it that only should be evaluated once per pageview. It could also carry some expensive database transactions. Anyhow. I can't figure out how to refactor without breaking Widget functionality, and the way 'controller' works. Anyhow. I think I'd call the above a bug report. Maybe with elements of rant thrown in. Stephen Thorne. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9VQ0HRqaMcfqEy/YRAoOPAJ0WJiLcPvftgjna6tgiD1ifAbQkGACdEDWN 7psWJh0/77eiCaEai/xVnaU= =BNcB -----END PGP SIGNATURE-----
participants (1)
-
Stephen Thorne