Hello, after batteling with XMLRPC and getting nevow to put something on the screen, I got stuck implementing a livepage and webform example. After changing the implements to inevow.IResource in httpResource, I got a message about a missing locateChild method (is that about the same as the getChild method in a twisted web resource?) ... I've created one, but I'm not shure if it's correct. Bottomline is I can't get it to work, not from the code and not from a resource file ... what's wrong with this code? Here's my code: ----------------------------------------------------------------------------------------------- class ISimpleMethod(TypedInterface): def simple(self, name=String(description="Your name."), age=Integer(description="Your age.")): """Simple Please enter your name and age. """ class Implementation(object): implements(ISimpleMethod) def simple(self, name, age): print "Hello, %s, who is %s" % (name, age) class WebForm(rend.Page): print 'WEBFORMS:', webform.renderForms('original') docFactory = loaders.stan(tags.html[ tags.body[ tags.h1["Here is the form:"], webform.renderForms()]]) class httpResource(resource.Resource): implements(inevow.IResource) def __init__(self, service): resource.Resource.__init__(self) self.service = service ##self.putChild('RPC2', Example(self.service)) self.putChild('formtest', WebForm(Implementation())) rt = static.File("rpy") rt.ignoreExt(".rpy") rt.processors = {'.rpy': script.ResourceScript} self.putChild('rpy', rt) def render(self, request): self._clientIP = request.getClientIP() return resource.Resource.render(self, request) def render_GET(self, request): """Process HTTP GET Requests.""" print 'GET: request ->', request return '<html><body><h3>Not Implemented</h3></body></html>' def getChild(self, path, request): """This method handles http calls""" print 'getChild path:', path print 'getChild request:', request if path=="": return httpResource(self.service) else: return httpResource(self.service) def locateChild(self, ctx, segments): """""" print 'CTX:', ctx print 'SEGMENTS:', segments return self, segments components.registerAdapter(httpResource, IowwService, inevow.IResource) def main(): """""" application = service.Application('OWW', uid=1000, gid=1000) s = owwService() serviceCollection = service.IServiceCollection(application) internet.TCPServer(7080, appserver.NevowSite(s)).setServiceParent(serviceCollection) serviceCollection.startService() reactor.run() if __name__ == '__main__': main() ---------------------------------------------------------------------------- livepage.rpy ---------------------------------------------------------------------------- from nevow.livepage import handler from nevow import rend, tags, loaders def greeter(client, nodeName): client.alert("Greetings. You clicked the %s node." % nodeName) # Any string arguments after the event handler function will be evaluated # as JavaScript in the context of the web browser and results passed to the # Python event handler handler = handler(greeter, 'node.name') class Live(rend.Page): docFactory = loaders.stan( tags.html[ tags.body[ tags.ol[ tags.li(onclick=handler, name="one")["One"], tags.li(onclick=handler, name="two")["Two"], tags.li(onclick=handler, name="three")["Three"] ] ] ]) resource = Live() ------------------------------------------------------------------ testform.rpy ------------------------------------------------------------------ from formless.annotate import TypedInterface, Integer, String from nevow import rend, tags, loaders, appserver, inevow from formless import webform from zope.interface import Interface, implements class ISimpleMethod(TypedInterface): def simple(self, name=String(description="Your name."), age=Integer(description="Your age.")): """Simple Please enter your name and age. """ class Implementation(object): implements(ISimpleMethod) def simple(self, name, age): print "Hello, %s, who is %s" % (name, age) class WebForm(rend.Page): print 'WEBFORMS:', webform.renderForms('original') docFactory = loaders.stan(tags.html[ tags.body[ tags.h1["Here is the form:"], webform.renderForms()]]) resource = WebForm(Implementation())
Remi Cool wrote:
Hello, after batteling with XMLRPC and getting nevow to put something on the screen, I got stuck implementing a livepage and webform example.
After changing the implements to inevow.IResource in httpResource, I got a message about a missing locateChild method (is that about the same as the getChild method in a twisted web resource?) ... I've created one, but I'm not shure if it's correct.
Bottomline is I can't get it to work, not from the code and not from a resource file ... what's wrong with this code?
I was using twisted.web.static and not nevow.static and that mistake was responsible for the cannotAdapt errors. The webforms example worked after changing the ISimpleMethod class to: class ISimpleMethod(TypedInterface): def simple(self, name=String(description="Your name."), age=Integer(description="Your age.")): """Simple Please enter your name and age. """ simple = annotate.autocallable(simple) The Livepage example also needed a little touchup ... class Live(LivePage): addSlash = True docFactory = loaders.stan( tags.html[ tags.head[livepage.glue], tags.body[ tags.ol[ tags.li(onclick="server.handle('greeter', this.name)", name="one")["One"], tags.li(onclick="server.handle('greeter', this.name)", name="two")["Two"], tags.li(onclick="server.handle('greeter', this.name)", name="three")["Three"] ] ] ]) def __init__(self): livepage.LivePage.__init__(self) def handle_greeter(self, ctx, value): return livepage.alert("you've clicked %s" % value) Most important was the tags.head[livepage.glue] addition. Now that everything works, I can go on to the next step (pfew) ... calling the client from the server with livepage, sessions, authentication and experimenting with nufox XUL. - Remi -
participants (1)
-
Remi Cool