[Twisted-web] nevow athena version 9.0 vs later

Михаил Михайлов mihailovmv77 at gmail.com
Sat Dec 8 16:43:31 EST 2007


my example consists 2 files: aacc_web.py and aacc_web.js

python aacc_web.py
will start on port 8080

generated html contains textarea and in case of input
prints the entered symbol on the console and in textarea
It works ONLY in version 9.0 and does NOT (!) work in last versions

Explain what's wrong



//import Nevow.Athena
function keypress(event)
    var key =3D event.charCode ? event.charCode : event.keyCode
    var node =3D $("termid");
    Nevow.Athena.Widget.get(node).callRemote("aacc_keypress", event.charCod=
event.keyCode, event.metaKey, event.altKey, event.ctrlKey, event.shiftKey);

AaccWeb.Users =3D Nevow.Athena.Widget.subclass("AaccWeb.Users");

    function start(self, node, event) {
        return false;
    function showConference(self, toWhat) {
        var client_data =3D Nevow.Athena.NodeByAttribute(self.node, "class",
        client_data.innerHTML =3D toWhat;

aacc_web.py code

# -*- coding: utf-8 -*-
""" aacc_web

from twisted.application import service, internet
from twisted.internet import reactor, protocol, defer, task, ssl
from twisted.protocols import basic
from twisted.python import log, logfile, util
from twisted.cred import portal, checkers, credentials
from twisted.web import static

from nevow import appserver
from nevow import tags, guard
from nevow import rend, loaders, inevow, athena
from nevow import url
from nevow.inevow import IRequest

import os, logging, pprint, time, sys

class Users(athena.LiveFragment):
    jsClass =3D u" AaccWeb.Users"

    docFactory =3D loaders.xmlstr("""
<div xmlns:nevow=3D"http://nevow.com/ns/nevow/0.1"
   xmlns:athena=3D" http://divmod.org/ns/athena/0.7"
   nevow:render=3D"liveFragment" class=3D"Users">

    running =3D False

    def __init__(self, **kwargs):
        print 'start Users AJAX session'

    def aacc_start(self):
        if self.running:
        reactor.callLater(1, self.updateConference, True)
        self.running =3D True

    def aacc_keypress(self, charcode, keycode, metakey, altkey, ctrlkey,
        print 'charcode: %s keycode: %s metakey: %s altkey: %s ctrlkey: %s
shiftkey: %s' % (charcode, keycode, metakey, altkey, ctrlkey, shiftkey)
        self.updateConference(True, unichr(charcode))

    def updateConference(self, force=3DFalse, sym=3D''):
        """ updateConference """
        #print 'updateConference'
        def onUpdateConferenceOk(result):
            self.callUpdateConference =3D reactor.callLater(1,
        def onUpdateConferenceErr(err):
            self.running =3D False

        if not force:
            self.callUpdateConference =3D reactor.callLater(1,

        mystr =3D u"""<textarea id=3D"termid" cols=3D"10" rows=3D"5"
onkeypress=3D"return keypress(event)">""" + sym + u"""</textarea>"""

        df =3D self.callRemote('showConference', mystr)
        df.addCallbacks(onUpdateConferenceOk, onUpdateConferenceErr)

class ConferencePage(athena.LivePage ):

    docFactory =3D loaders.xmlstr("""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns:nevow=3D"http://nevow.com/ns/nevow/0.1">
        <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Du=
        <nevow:invisible nevow:render=3D"liveglue"/>
        <script type=3D"text/javascript" src=3D"aacc_web.js">
        <div nevow:render=3D"conference">

    def __init__(self, *a, **kw):
        super(ConferencePage, self).__init__(*a, **kw)
        self.jsModules.mapping[u'AaccWeb'] =3D util.sibpath(__file__,

    addSlash =3D True

    def render_liveglue(self, ctx, data):
        req =3D ctx.locate(IRequest)
        args =3D dict([(k,v[0]) for (k,v) in req.args.items()])
        self.args =3D args
        return athena.LivePage.render_liveglue(self, ctx, data)

    def render_conference(self, ctx, data):
        args =3D dict([(k,v) for (k,v) in self.args.items ()])
        c =3D Users(**args)
        c.page =3D self
        reactor.callLater(0, c.aacc_start)
        return ctx.tag[c]

class RootPage(rend.Page):
    """ """
    addSlash =3D True
    docFactory =3D loaders.xmlstr("""
<html xmlns:nevow=3D"http://nevow.com/ns/nevow/0.1">

    def renderHTTP(self, ctx):
        print 'render of root page'
        req =3D ctx.locate(IRequest)
        my_url =3D url.here.child('conference')
        return my_url

    def child_conference(self, ctx):
        return ConferencePage()

class aacc_web:
    """ """

    def __init__(self, **kwargs):
        """ """
        resource =3D RootPage()
        site =3D appserver.NevowSite(resource)
        reactor.listenTCP(8080, site)

if __name__ =3D=3D "__main__":
    aacc_web =3D aacc_web()


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20071209/0d=

More information about the Twisted-web mailing list