[Twisted-web] Re: Athena Forms Thing

Paul Reznicek maillists at ivsn.com
Mon Dec 5 19:39:00 MST 2005


Doug Winter wrote:
> ...
> Dialtone is right to suggest using mg's form library I think, and I'm up 
> for doing some hacking on this this weekend. ...

After testing Matt's "forms" I agree 100% that (except the AJAX features),
forms are capable for very sophisticated designs!

Your proposal on:
   http://forms-project.pollenation.net/cgi-bin/trac.cgi/wiki/ajax
is qualified too - this functionality could be a real base for high
interactive user interfaces.

After getting your ajax-forms branch with:
   svn checkout svn://pollenation.net/forms/branches/ajax-forms ajax-forms
I found your's first example - but not working too much. I was playing a bit
with it and attached is a patch how to get on the server-side some more live
into it.

Looking forward the next steps !!!

Paul
-------------- next part --------------
Index: aforms/event.py 
=================================================================== 
--- aforms/event.py	(Revision 147) 
+++ aforms/event.py	(Arbeitskopie) 
@@ -21,7 +21,7 @@ 
     def __init__(self, event, method, *args): 
         self.event = event 
         self.method = method 
-        self.args = args 
+        self.args = str(args)[2:-3] or '""' 
  
     def render(self, ctx): 
-        return "server.callRemote('%s')" % self.method 
+        return "server.callRemote('%s', %s)" % (self.method, self.args) 
Index: aforms/examples/simple.py 
=================================================================== 
--- aforms/examples/simple.py	(Revision 147) 
+++ aforms/examples/simple.py	(Arbeitskopie) 
@@ -1,3 +1,4 @@ 
+#! /usr/bin/env python 
  
 import pkg_resources 
 pkg_resources.require("forms") 
@@ -4,6 +5,8 @@ 
  
 from twisted.application import service 
 from twisted.application import internet 
+from twisted.python import util 
+from twisted.internet import reactor 
  
 from nevow import rend 
 from nevow import athena 
@@ -20,20 +23,43 @@ 
     ('baz', 'Baz'), 
 ] 
  
+from zope.interface import Interface 
+ 
+class ISimple(Interface): 
+    def keypressed(): 
+        pass 
+    def blur(): 
+        pass 
+    def async_submitted(): 
+        pass 
+ 
+class Simple(object): 
+    def keypressed(self, data): 
+        print 'keypressed', data 
+    def blur(self, data): 
+        print 'blur', data 
+    def async_submitted(self, data): 
+        print 'async_submitted', data 
+        reactor.stop() 
+ 
 class Page(forms.ResourceMixin, athena.LivePage): 
-    docFactory = loaders.xmlfile("aforms/examples/simple.html") 
+    docFactory = loaders.xmlfile( 
+            util.sibpath(__file__, 'simple.html'), ignoreComment=True) 
  
     def form_example(self, ctx): 
         form = aforms.Form() 
+        formIdPrefix = 'example' 
         wf = forms.widgetFactory( 
             aforms.TextArea, 
             events=( 
-                aforms.CallRemote('onkeyup', 'keypressed'), 
-                aforms.CallRemote('onblur', 'blur', 23), 
+                aforms.CallRemote('onkeyup', 'keypressed', 'this.value'), 
+                aforms.CallRemote('onblur', 'blur', 'this.value'), 
             ) 
         ) 
-        form.addField('aString', forms.String(), wf) 
-        form.addAsyncAction(aforms.CallRemote('onclick', 'async_submitted')) 
+        fieldName = 'aString' 
+        form.addField(fieldName, forms.String(), wf) 
+        form.addAsyncAction(aforms.CallRemote('onclick', 'async_submitted', 
+                'getValue("%s-%s")' % (formIdPrefix, fieldName) )) 
         return form 
  
     def submitted(self, ctx, form, data): 
@@ -44,11 +70,19 @@ 
         return url.URL.fromString('/app') 
  
     def child_app(self, ctx): 
-        page = Page((), None) 
+        page = Page(ISimple, Simple()) 
         return page 
  
 root = Root() 
 application = service.Application("test") 
-i = internet.TCPServer(9898, appserver.NevowSite(root,  logPath="/dev/null")) 
+i = internet.TCPServer(9898, appserver.NevowSite(root, ))# logPath="/dev/null")) 
 i.setServiceParent(application) 
  
+# with this, you can start this file directly, no need for twistd ... 
+if __name__ == '__main__': 
+    """Command Line Starter 
+    """ 
+    i.startService() 
+    print 'SERVICE STARTED' 
+    reactor.run() 
+    print 'reactor STOPPED' 
Index: aforms/examples/simple.html 
=================================================================== 
--- aforms/examples/simple.html	(Revision 147) 
+++ aforms/examples/simple.html	(Arbeitskopie) 
@@ -5,6 +5,14 @@ 
 <html xmlns:n="http://nevow.com/ns/nevow/0.1"> 
   <head> 
     <n:invisible n:render="liveglue" /> 
+    <script type='text/javascript' language='javascript'> 
+    // <![CDATA[ 
+    function getValue(fieldID) { 
+        return document.getElementById(fieldID).value; 
+    } 
+    // ]]> 
+    </script> 
+ 
   </head> 
   <body> 
     <form n:render="form example" /> 


More information about the Twisted-web mailing list