[Twisted-web] Livepage, ClientHandle and context [continued]

Chris (FeedTagger) chris.were at gmail.com
Mon Jun 27 00:30:40 MDT 2005

Sorry, just registered so unable to join existing thread.

I'm having similar problems that are outlined here:
"I also can't see a way to use handler_* methods, because this methods
must be inside a rend.Fragment subclass in my case."

I expect this can be rectified in livepage.py (line 728 on my co):
    def locateHandler(self, ctx, path, name):
        ### XXX TODO: Handle path
        return getattr(self, 'handle_%s' % (name, ))

My implementation is slightly different in that I'm not using
rend.Fragment, I have a Page broker that responds to requests and
returns a new page that implements from a master page.


pageMappings ] {
  'search': search.Page
  'index': index.Page

class Page(livepage.LivePage):
  def locateChild(self,ctx,segments):
    # depending on the value of segments[0] return the correct page
    # from a predefined map, otherwise 404
    page = pageMappings[segments[0]]
    return page(), segments[1]

Then in index.Page.py:
class Page(_master.FrontPage):

  def render_button(self,ctx,data):
    return ctx.tag(onclick="server.handle('click')")

  def handle_click(self,ctx,client):
    client.alert('clicked button')


class CorePage(livepage.LivePage):
  # various properties that all generic pages should exhibit

class FrontPage(CorePage):
  # load front page template
  # provide any default slot fills etc.

Now the problem as I see it (with primitive livepage knowledge) is
that the livepage request that's sent with server.handle('click') is
attempting to be mapped to myserver.Page, instead of my intended
index.Page class.
Is it possible to provide this functionality or should this whole
template based approach be re-worked in some other fashion?

... as a side note using a generic dispatcher of pages (myserver.Page)
I can do cool things like detect /xml appended to url and instead of
loading .xhtml templates, load the appropriate .xml templates. Hence
without changing any application code I can generate xml versions of
every single webpage across a site.


More information about the Twisted-web mailing list