Part of nevow.livepage View Source View In Hierarchy
Known subclasses: nevow.livetest.Tester
A Page which is Live provides asynchronous, bidirectional RPC between
Python on the server and JavaScript in the client browser. A LivePage must
include the "liveglue" JavaScript which includes a unique identifier which
is assigned to every page render of a LivePage and the JavaScript required
for the client to communicate asynchronously with the server.
A LivePage grants the client browser the capability of calling server-side
Python methods using a small amount of JavaScript code. There are two
types of Python handler methods, persistent handlers and transient handlers.
1) To grant the client the capability to call a persistent handler over and over
as many times as it wishes, subclass LivePage and provide handle_foo
methods. The client can then call handle_foo by executing the following
JavaScript:
server.handle('foo')
handle_foo will be invoked because the default implementation of
locateHandler looks for a method prefixed handle_*. To change this,
override locateHandler to do what you wish.
2) To grant the client the capability of calling a handler once and
exactly once, use ClientHandle.transient to register a callable and
embed the return result in a page to render JavaScript which will
invoke the transient handler when executed. For example:
def render_clickable(self, ctx, data):
def hello(ctx):
return livepage.alert("Hello, world. You can only click me once.")
return ctx.tag(onclick=IClientHandle(ctx).transient(hello))
The return result of transient can also be called to pass additional
arguments to the transient handler. For example:
def render_choice(self, ctx, data):
def chosen(ctx, choseWhat):
return livepage.set(
"choosable",
["Thanks for choosing ", choseWhat])
chooser = IClientHandle(ctx).transient(chosen)
return span(id="choosable")[
"Choose one:",
p(onclick=chooser("one"))["One"],
p(onclick=chooser("two"))["Two"]]
Note that the above situation displays temporary UI to the
user. When the user invokes the chosen handler, the UI which
allowed the user to invoke the chosen handler is removed from
the client. Thus, it is important that the transient registration
is deleted once it is invoked, otherwise uncollectable garbage
would accumulate in the handler dictionary. It is also important
that either the one or the two button consume the same handler,
since it is an either/or choice. If two handlers were registered,
the untaken choice would be uncollectable garbage.
Split Table into Classes Show Methods in One Table
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 746 | Method | renderHTTP | Render a request |
| 751 | Method | locateHandler | Undocumented |
| 755 | Method | goingLive | This particular LivePage instance is 'going live' from the |
| 771 | Method | child_livepage_client | Undocumented |
| 776 | Method | render_liveid | Undocumented |
| 786 | Method | render_liveglue | Undocumented |
Inherited from Page:
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 571 | Method | rememberStuff | Undocumented |
| 575 | Method | renderString | Render this page outside of the context of a web request, returning |
| 595 | Method | renderSynchronously | Render this page synchronously, returning a string result immediately. |
| 615 | Method | child_ | When addSlash is True, a page rendered at a url with no |
| 627 | Method | webFormPost | Accept a web form post, either redisplaying the original form (with |
| 687 | Method | onPostSuccess | Undocumented |
| 695 | Method | onPostFailure | Undocumented |
Inherited from Fragment (via Page):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 377 | Method | __init__ | Undocumented |
| 384 | Method | get | Return the data |
| 387 | Method | rend | Turn this instance into stan suitable for displaying it in a web page. |
| 432 | Method | remember | Remember an object for an interface on new PageContexts which are |
Inherited from DataFactory (via Page, Fragment):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 120 | Method | child | Return a conceptual child; an attribute, or a key, |
Inherited from RenderFactory (via Page, Fragment):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 60 | Method | renderer | Return a renderer with the given name. |
Inherited from MacroFactory (via Page, Fragment):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 90 | Method | macro | Return a macro with the given name. |
Inherited from ConfigurableMixin (via Page, Fragment):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 193 | Method | getBindingNames | Expose bind_* methods and attributes on this class. |
| 200 | Method | getBinding | Massage bind_* methods and attributes into an |
| 223 | Method | getDefault | Get a default value for a given binding. If the |
| 235 | Method | postForm | Accept a form post to the given bindingName. |
Inherited from ConfigurableFactory (via Page):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 263 | Method | locateConfigurable | formless.webform.renderForms calls locateConfigurable on the IConfigurableFactory |
| 276 | Method | configurable_ | Configurable factory for use when self is a configurable; |
| 302 | Method | configurable_original | Configurable factory for use when self.original is a configurable; |
Inherited from ChildLookupMixin (via Page):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 456 | Method | locateChild | Locate a child page of this one. ctx is a |
| 497 | Method | childFactory | Used by locateChild to return children which are generated |
| 509 | Method | putChild | Undocumented |
Inherited from FreeformChildMixin (via Page, ChildLookupMixin):
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 168 | Method | child_freeform_hand | Undocumented |
| Line # | Kind | Name | Docs |
|---|---|---|---|
| 377 | Method | __init__ | Undocumented |
| 120 | Method | child | Return a conceptual child; an attribute, or a key, |
| 615 | Method | child_ | When addSlash is True, a page rendered at a url with no |
| 168 | Method | child_freeform_hand | Undocumented |
| 771 | Method | child_livepage_client | Undocumented |
| 497 | Method | childFactory | Used by locateChild to return children which are generated |
| 276 | Method | configurable_ | Configurable factory for use when self is a configurable; |
| 302 | Method | configurable_original | Configurable factory for use when self.original is a configurable; |
| 384 | Method | get | Return the data |
| 200 | Method | getBinding | Massage bind_* methods and attributes into an |
| 193 | Method | getBindingNames | Expose bind_* methods and attributes on this class. |
| 223 | Method | getDefault | Get a default value for a given binding. If the |
| 755 | Method | goingLive | This particular LivePage instance is 'going live' from the |
| 456 | Method | locateChild | Locate a child page of this one. ctx is a |
| 263 | Method | locateConfigurable | formless.webform.renderForms calls locateConfigurable on the IConfigurableFactory |
| 751 | Method | locateHandler | Undocumented |
| 90 | Method | macro | Return a macro with the given name. |
| 695 | Method | onPostFailure | Undocumented |
| 687 | Method | onPostSuccess | Undocumented |
| 235 | Method | postForm | Accept a form post to the given bindingName. |
| 509 | Method | putChild | Undocumented |
| 432 | Method | remember | Remember an object for an interface on new PageContexts which are |
| 571 | Method | rememberStuff | Undocumented |
| 387 | Method | rend | Turn this instance into stan suitable for displaying it in a web page. |
| 786 | Method | render_liveglue | Undocumented |
| 776 | Method | render_liveid | Undocumented |
| 60 | Method | renderer | Return a renderer with the given name. |
| 746 | Method | renderHTTP | Render a request |
| 575 | Method | renderString | Render this page outside of the context of a web request, returning |
| 595 | Method | renderSynchronously | Render this page synchronously, returning a string result immediately. |
| 627 | Method | webFormPost | Accept a web form post, either redisplaying the original form (with |
This particular LivePage instance is 'going live' from the perspective of the ClientHandle 'handle'. Override this to get notified when a new browser window observes this page.
This means that a new user is now looking at the page, an old user has refreshed the page, or an old user has opened a new window or tab onto the page.
This is the first time the ClientHandle instance is available for general use by the server. This Page may wish to keep track of the ClientHandle instances depending on how your application is set up.