[Twisted-web] athena under a vhost: strange issue

aleuser at inwind.it aleuser at inwind.it
Tue Sep 5 10:14:54 CDT 2006


Hi,
I think I have found a strange issue in athena under a virtual host.

The problem is the 'self.callRemote' server side functions; they will work only the first time, after that (I mean: after one only 'self.callRemote' is executed) the athena page seems to be disconnected and no other dinamic athena function seems to be working!

If I use the same page without the virtual host (browsing directly to the athena web server ) it works ok.

The problem seem to be the deferred returned by the server side 'self.callRemote'. If I don't return it, it will not be executed under a virtual host. 

No errors are reported in the debug athena window and in the firefox javascript console.


In the following examples, the 'msgbox' is an 'alert' client-side in the "liveform.js" file.
...
  function msgbox(self, msg){
    alert(msg);
    return false;
  },
..


Here the code:

class LiveFormExampleFragment(athena.LiveFragment):
    jsClass = u"LiveForm.Checkin"
    docFactory = loaders.stan(T.span(render=T.directive('liveFragment'))[
        'TestInput= ',
        T.input(type="text",
             onchange="Nevow.Athena.Widget.get(this).callRemote('testing', this.value);"),
        'TestInput 2 = ',
        T.input(type="text",
             onchange="""
               ret = Nevow.Athena.Widget.get(this).callRemote('testing2', this.value);
               ret.addCallback(function(arg){
                  alert(arg);
               })
             """),
      ])

    def testing2(self, val):
        aa = self.callRemote('msgbox', u'message1..')
        bb = self.callRemote('msgbox', u'...message2')
        print "I always print val = ", val
        #Under a vhost I cant do a simple """ return 'Finish : %s'%val """ because
        #  it will work only the first time! after that, nothing will work..
        return DeferredList([aa, bb]).addCallback(lambda _: u'Finish : %s'%val)
    athena.expose(testing2)

    def testing(self, val):
        aa = self.callRemote('msgbox', u'message1..')
        bb = self.callRemote('msgbox', u'...message2')
        print "I always print val = ", val
        #if I remove the next 'return DeferredList' the message1 & 2 will be printed on the
        #  screen only the first time! after that, nothing will work..
        return DeferredList([aa, bb]) #<<< so don't remove me!
    athena.expose(testing)


class LiveFormExample(athena.LivePage):
    docFactory = loaders.stan([
                   T.html[T.body[
                     T.invisible(render=T.directive('liveglue')),
                                 T.invisible(render=T.directive("form")),
                   ]]])
    def __init__(self, *a, **kw):
        athena.LivePage.__init__(self, *a, **kw)
        self.jsModules.mapping[u'LiveForm'] = './liveform.js'

    def render_form(self, ctx, data):
        c = LiveFormExampleFragment()
        c.page = self
        return ctx.tag[c]


Alessandro





More information about the Twisted-web mailing list