[Twisted-web] nevow.liveevil question (dynamically adding a link with its own handler)

David Moore djm at software.net.nz
Sun Dec 19 13:05:01 MST 2004


I'm working on a project[1] which will require very dynamic webpages. 
I'm very excited to discover nevow.liveevil (I'd rather program in
Python than JavaScript).

But I'm having trouble dynamically adding a link which can then call
further Python code.

My code....
---------------------------------------------------------------------
#!/usr/bin/python
from nevow import rend
from nevow import loaders
from nevow import tags
from nevow import liveevil
from twisted.internet import reactor

def adder(client):
#    newLink = loaders.stan(tags.a(href="#")["Nothing"])
    newLink = loaders.stan(tags.a(href="#", 
                onclick=liveevil.handler(adder))["AddAgain"])
    client.append('content', newLink)

mycontent = loaders.stan(
tags.html[
    tags.head[liveevil.glue], 
    tags.body[ 
        tags.a(href="#", onclick=liveevil.handler(adder))["Add"],
        tags.div(id="content"),
    ]
])
mypage = rend.Page(docFactory=mycontent)
mypage.addSlash = True

mysite = liveevil.LiveSite(mypage)
reactor.listenTCP(8080, mysite)
reactor.run()
---------------------------------------------------------------------

When I click on the Add link I get
---------------------------------------------------------------------
Traceback (most recent call last):
  File "br.py", line 28, in ?
    reactor.run()
  File "/usr/lib/python2.3/site-packages/twisted/internet/default.py", line 126, in run
    self.mainLoop()
  File "/usr/lib/python2.3/site-packages/twisted/internet/default.py", line 134, in mainLoop
    self.runUntilCurrent()
--- <exception caught here> ---
  File "/usr/lib/python2.3/site-packages/twisted/internet/base.py", line 423, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/liveevil.py", line 101, in handleInput
    self.events.publish(identifier, *(self, ) + args)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/events.py", line 41, in publish
    sub(*args)
  File "br.py", line 12, in adder
    client.append('content', newLink)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/liveevil.py", line 130, in append
    client.sendScript(
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/liveevil.py", line 112, in flt
    fl = flatten(stan, ctx=ctx)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/flat/ten.py", line 146, in flatten
    list(iterflatten(stan, ctx, result.append))
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/flat/ten.py", line 104, in iterflatten
    for item in gen:
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/flat/flatstan.py", line 84, in TagSerializer
    yield serialize(toBeRenderedBy, context)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/flat/ten.py", line 91, in serialize
    return partialflatten(context, obj)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/flat/ten.py", line 82, in partialflatten
    return flattener(obj, context)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/flat/flatstan.py", line 168, in FunctionSerializer
    data = convertToData(context.locate(IData), context)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/context.py", line 100, in locate
    return self.parent.locate(interface, depth)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/context.py", line 203, in locate
    return WebContext.locate(self, interface, depth)
  File "/usr/lib/python2.3/site-packages/Nevow/nevow/context.py", line 99, in locate
    raise KeyError, "Interface %s was not remembered." % key
exceptions.KeyError: 'Interface nevow.inevow.IData was not remembered.'
---------------------------------------------------------------------
I don't get this problem if I replace the AddAnother link with the Nothing 
link (as commented out in the code.)

Is this expected-behaviour, a bug in my code, or a bug in liveevil????

Any help would be greatly appreciated.

Thanks!
David.




[1] https://eduforge.org/projects/exe E-learning XML Editor

-- 
 (o_    David Moore
 //\    LinuxSoftware - Custom software development for Linux!
 V_/_   http://www.linuxsoftware.co.nz



More information about the Twisted-web mailing list