[Twisted-web] livepage breaks after reload
Matt Goodall
matt at pollenation.net
Wed Jan 26 08:56:39 MST 2005
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 at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
--
__
/ \__ Matt Goodall, Pollenation Internet Ltd
\__/ \ w: http://www.pollenation.net
__/ \__/ e: matt at pollenation.net
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.
More information about the Twisted-web
mailing list