Re: [Twisted-web] livepage breaks after reload
Ahh this is killing me! Part of the problem that I described earlier in this thread is that simply adding a locateChild stops javascript events from triggering the connected python function/methode. I am trying to render the same page no matter what url (past the domain) is given. This single page should render differently depending on the url, though. So in locateChild I store the url segments and return self and an empty segment tuple. This seems to work but, as I said, breaks the livepage functionality. WHY is locateChild DOING thaaAAt???? What follows is some code that illustrates exactly that. Javascript events come perfectly through until I uncommend the localChild methode. #noema #################### START OF .TAC FILE ######################## import random from twisted.application import service, internet from nevow import loaders, rend, tags, livepage, url class MyPage(rend.Page): addSlash = True #def locateChild(self, context, segments): # #store the rest of the url for any kind of manual processing # self.postpath = segments # return self, () def onLinkAction(self, client): client.set('atag', random.choice(('one', 'two', 'three', 'four', 'five'))) def render_link(self, context, data): return tags.a(onclick=livepage.handler(self.onLinkAction), href=url.here, id="atag")['click!'] def render_glue(self, context, data): return livepage.glue docFactory = loaders.stan( tags.html[ tags.head[ tags.title["mypage"], ], tags.body[ tags.div[ render_link ], tags.span(render=render_glue) ] ]) application = service.Application('mypage') internet.TCPServer(8080, livepage.LiveSite(MyPage()))\ .setServiceParent(application) #################### END OF .TAC FILE ##########################
On Wed, 2005-01-26 at 16:37 +0100, noema wrote:
Ahh this is killing me! Part of the problem that I described earlier in this thread is that simply adding a locateChild stops javascript events from triggering the connected python function/methode.
I am trying to render the same page no matter what url (past the domain) is given. This single page should render differently depending on the url, though. So in locateChild I store the url segments and return self and an empty segment tuple. This seems to work but, as I said, breaks the livepage functionality.
WHY is locateChild DOING thaaAAt????
It's because you're not allowing the subclass to have a go at locating the child and so the 'link' and 'glue' child resource cannot be found. See below. You're locate child should look something more like ... def locateChild(self, context, segments): # Do whatever you need to do here, probably returning # a resource and the remaining segments. # I don't know what it is so let Page (my subclass) try. return rend.Page.locateChild(self, context, segments)
What follows is some code that illustrates exactly that. Javascript events come perfectly through until I uncommend the localChild methode.
#noema
#################### START OF .TAC FILE ########################
import random from twisted.application import service, internet from nevow import loaders, rend, tags, livepage, url
class MyPage(rend.Page): addSlash = True
#def locateChild(self, context, segments): # #store the rest of the url for any kind of manual processing # self.postpath = segments # return self, ()
def onLinkAction(self, client): client.set('atag', random.choice(('one', 'two', 'three', 'four', 'five')))
def render_link(self, context, data): return tags.a(onclick=livepage.handler(self.onLinkAction), href=url.here, id="atag")['click!']
def render_glue(self, context, data): return livepage.glue
docFactory = loaders.stan( tags.html[ tags.head[ tags.title["mypage"], ], tags.body[ tags.div[ render_link ], tags.span(render=render_glue) ] ])
application = service.Application('mypage') internet.TCPServer(8080, livepage.LiveSite(MyPage()))\ .setServiceParent(application)
#################### END OF .TAC FILE ##########################
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-- __ / \__ Matt Goodall, Pollenation Internet Ltd \__/ \ w: http://www.pollenation.net __/ \__/ e: matt@pollenation.net / \__/ \ t: +44 (0)113 2252500 \__/ \__/ / \ Any views expressed are my own and do not necessarily \__/ reflect the views of my employer.
You're locate child should look something more like ...
def locateChild(self, context, segments):
# Do whatever you need to do here, probably returning # a resource and the remaining segments.
# I don't know what it is so let Page (my subclass) try. return rend.Page.locateChild(self, context, segments)
I am not sure I fully understand what you mean. Am I not exactly doing what you are suggesting?! I return a resource and the remaining segments. Just that in my case the resource is the current resource itself and the remaining segments are empty. (to make any child valid and be handled by MyPage (which it does just not with livepage support))
return rend.Page.locateChild(self, context, segments)
Isn't this returned/called anyways if I wouldn't overwrite the inherited locateChild methode.
What follows is some code that illustrates exactly that. Javascript events come perfectly through until I uncommend the localChild methode.
#noema
#################### START OF .TAC FILE ########################
import random from twisted.application import service, internet from nevow import loaders, rend, tags, livepage, url
class MyPage(rend.Page): addSlash = True
#def locateChild(self, context, segments): # #store the rest of the url for any kind of manual processing # self.postpath = segments # return self, ()
def onLinkAction(self, client): client.set('atag', random.choice(('one', 'two', 'three', 'four', 'five')))
def render_link(self, context, data): return tags.a(onclick=livepage.handler(self.onLinkAction), href=url.here, id="atag")['click!']
def render_glue(self, context, data): return livepage.glue
docFactory = loaders.stan( tags.html[ tags.head[ tags.title["mypage"], ], tags.body[ tags.div[ render_link ], tags.span(render=render_glue) ] ])
application = service.Application('mypage') internet.TCPServer(8080, livepage.LiveSite(MyPage()))\ .setServiceParent(application)
#################### END OF .TAC FILE ##########################
On Wed, 2005-01-26 at 19:29 +0100, noema wrote:
You're locate child should look something more like ...
def locateChild(self, context, segments):
# Do whatever you need to do here, probably returning # a resource and the remaining segments.
# I don't know what it is so let Page (my subclass) try. return rend.Page.locateChild(self, context, segments)
I am not sure I fully understand what you mean. Am I not exactly doing what you are suggesting?! I return a resource and the remaining segments. Just that in my case the resource is the current resource itself and the remaining segments are empty. (to make any child valid and be handled by MyPage (which it does just not with livepage support))
Oops, my reasoning was completely flawed although I'm still confident I'm correct about the problem. Liveevil connects to the nevow_liveOutput and nevow_liveInput child resources (see rend.LiveEvilChildMixin). By overriding locateChild, and not allowing the super class to play, you are blocking access to those liveevil resources.
return rend.Page.locateChild(self, context, segments)
Isn't this returned/called anyways if I wouldn't overwrite the inherited locateChild methode.
Yes, *if* you don't override locateChild. But in your code, the problem occurs once you uncomment locateChild and replace rend.Page's implementation of locateChild. If you want to handle all segments but still let Liveevil work, perhaps the following will help: def locateChild(self, ctx, segments): r = rend.Page(self, ctx, segments) if r is not appserver.NotFound: return r return self, () That /should/ let the super class locate the resources needed by liveevil and make your page handle all other segments. Hope this makes more sense this time ;-). Cheers, Matt
What follows is some code that illustrates exactly that. Javascript events come perfectly through until I uncommend the localChild methode.
#noema
#################### START OF .TAC FILE ########################
import random from twisted.application import service, internet from nevow import loaders, rend, tags, livepage, url
class MyPage(rend.Page): addSlash = True
#def locateChild(self, context, segments): # #store the rest of the url for any kind of manual processing # self.postpath = segments # return self, ()
def onLinkAction(self, client): client.set('atag', random.choice(('one', 'two', 'three', 'four', 'five')))
def render_link(self, context, data): return tags.a(onclick=livepage.handler(self.onLinkAction), href=url.here, id="atag")['click!']
def render_glue(self, context, data): return livepage.glue
docFactory = loaders.stan( tags.html[ tags.head[ tags.title["mypage"], ], tags.body[ tags.div[ render_link ], tags.span(render=render_glue) ] ])
application = service.Application('mypage') internet.TCPServer(8080, livepage.LiveSite(MyPage()))\ .setServiceParent(application)
#################### END OF .TAC FILE ##########################
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Thanx a lot Matt! Your suggestion was close enough. In case somebody else is interested. This is what finally did the trick for me: def locateChild(self, ctx, segments): r = rend.Page.locateChild(self, ctx, segments[-1:]) if r is not rend.NotFound: return r return self, segments[1:] #noema Matt Goodall wrote:
On Wed, 2005-01-26 at 19:29 +0100, noema wrote:
You're locate child should look something more like ...
def locateChild(self, context, segments):
# Do whatever you need to do here, probably returning # a resource and the remaining segments.
# I don't know what it is so let Page (my subclass) try. return rend.Page.locateChild(self, context, segments)
I am not sure I fully understand what you mean. Am I not exactly doing what you are suggesting?! I return a resource and the remaining segments. Just that in my case the resource is the current resource itself and the remaining segments are empty. (to make any child valid and be handled by MyPage (which it does just not with livepage support))
Oops, my reasoning was completely flawed although I'm still confident I'm correct about the problem.
Liveevil connects to the nevow_liveOutput and nevow_liveInput child resources (see rend.LiveEvilChildMixin). By overriding locateChild, and not allowing the super class to play, you are blocking access to those liveevil resources.
return rend.Page.locateChild(self, context, segments)
Isn't this returned/called anyways if I wouldn't overwrite the inherited locateChild methode.
Yes, *if* you don't override locateChild. But in your code, the problem occurs once you uncomment locateChild and replace rend.Page's implementation of locateChild.
If you want to handle all segments but still let Liveevil work, perhaps the following will help:
def locateChild(self, ctx, segments): r = rend.Page(self, ctx, segments) if r is not appserver.NotFound: return r return self, ()
That /should/ let the super class locate the resources needed by liveevil and make your page handle all other segments.
Hope this makes more sense this time ;-).
Cheers, Matt
What follows is some code that illustrates exactly that. Javascript events come perfectly through until I uncommend the localChild methode.
#noema
#################### START OF .TAC FILE ########################
import random
from twisted.application import service, internet from nevow import loaders, rend, tags, livepage, url
class MyPage(rend.Page): addSlash = True
#def locateChild(self, context, segments): # #store the rest of the url for any kind of manual processing # self.postpath = segments # return self, ()
def onLinkAction(self, client): client.set('atag', random.choice(('one', 'two', 'three', 'four', 'five')))
def render_link(self, context, data): return tags.a(onclick=livepage.handler(self.onLinkAction), href=url.here, id="atag")['click!']
def render_glue(self, context, data): return livepage.glue
docFactory = loaders.stan( tags.html[ tags.head[ tags.title["mypage"], ], tags.body[ tags.div[ render_link ], tags.span(render=render_glue) ] ])
application = service.Application('mypage') internet.TCPServer(8080, livepage.LiveSite(MyPage()))\ .setServiceParent(application)
#################### END OF .TAC FILE ##########################
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (2)
-
Matt Goodall
-
noema