[Twisted-Python] Form Processor hmmmm looks cool what does it do :)

John Janecek jjanecek at telusplanet.net
Sun Aug 31 23:27:39 EDT 2003


Thanx to the dude who answered my last post :)
When i get some time i have to try and put into practive wxpython suggestions

I took the form processor example from the sandbox and made it do something.
What it is doing i am not quite sure :)

#form_input.py
#simple proggie to test how to handle forms
#hacked together from myformstuf which is in the glyph directory in the sandbox
#not really sure if this is done right

from twisted.web.woven import page
#this module is required for the method def wmfactory_form(self, request): 
to work
from twisted.web.woven.form import FormProcessor
from twisted.python import formmethod as fm

class FormPage(page.Page) :

     template = '''
     <html>
     <head><title>a form page</title>
     </head>
     <body>
     <form action="post" model="form" />
     </body>
     </html>
     '''

     formSignature = fm.MethodSignature(
             fm.String("username","","User Name : ","Enter a user name"),
             fm.Password("password","","Password : ","Enter a password")
             )

     def proc(self,**kw) :
         print "proc : ",kw

     def wmfactory_form(self, request):
         print "factory form"
         return self.formSignature.method(self.proc)

     def wchild_post(self,request) :
         print "child post ",request.args
         return FormProcessor(self.formSignature.method(self.proc))



#the test throttle code
def main() :
     print "Main Loop"
     from twisted.web.server import Site
     from twisted.internet import reactor

     reactor.listenTCP(9999,Site(FormPage()))
     reactor.run()

main()

self.proc is a required arguement.
It returns a dictionary with all the form variables in it when form is posted.
I am not really sure what am i supposed to do in this function. Like in 
this instance
would this be where i could stick variables into a data base ?

The method FormProcessor(self.formSignature.method(self.proc)) appears from 
the code
to be able to take a second arguement where i can add my own view. If no 
view is added
it uses the view that is provided by default. It would be kinda nice to 
have my own view,
how would my own view be able to access the variables that are posted from 
the form.

FormProcessor also appears to be able to take a 3rd arguement that is some 
sort of error view,
what type of errors would happen, and how will they be triggered.

FormProcessor looks like the smart way to handle forms. Unfortunately I 
seem to be missing a few pieces.

Well i will keep on plugging away at it :)
Hmmmm well anyways i am kinda lost i will think about being lost some more :))


Thanx

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20030831/00bcce84/attachment.htm 


More information about the Twisted-Python mailing list