From: Michel T. <mic...@ya...> - 2004-11-12 03:31:11
|
Hi guys! Ian, after the recent thread about form validation I think to try FormEncode, I used and still use FunFormKit for my projects, I use the FFK form generation and I confess it limitates my possibilities. I like the way htmlfill work, I tried to make a validator to a form with sucess, my only problem was when I try to use htmlfill. I will put my code on the end of message. I must question you that are using FormEncode with Webware, what is the best way to work with the two packages? I think in a way: First I will check for errors in the writeHTML method, if the form was processed and there is an error, I will define an attribute with this error. If there is no error, I can call a formProcessed function... Then I should write the content of the page, the form is part of the page (using self.write to write it). I want to trigger the page writing, I want to get the content before write and then parse it with htmlfill, filling default values and error messages. Does anyone know how can I trigger the page writing? I use a subclass of the Cheetah's Template, not Page. Sorry any english mistake, my htmlfill try are the follow: #:: FormEncode test... from validator.schema import Schema from validator import validators from validator import htmlfill class MyValidator(Schema): name=validators.String(not_empty=True) age=validators.Int() form='''\ <form method="post"> <table> <tr> <td>Name: <form:error name="name"></td><td><input type="text" name="name"></td> <form:iferror name="name">mndfnaofdas</form:iferror> </tr> <p><input type="submit" name="_action_send" value="Send Data"></p> </form>''' userInput={'name':'michel', 'age':20} errorDict={} try: userInput=validators.to_python(MyValidator, userInput) except validators.Invalid, error: errorDict=error.error_dict parser=htmlfill.FillingParser(userInput, errors=errorDict) parser.feed(form) print parser.text() parser.close() ... I get the follow error: Traceback (most recent call last): File "teste.py", line 29, in ? parser.feed(form) File "/usr/lib/python2.3/site-packages/validator/htmlfill.py", line 68, in feed HTMLParser.HTMLParser.feed(self, data) File "/usr/lib/python2.3/HTMLParser.py", line 108, in feed self.goahead(0) File "/usr/lib/python2.3/HTMLParser.py", line 150, in goahead k = self.parse_endtag(i) File "/usr/lib/python2.3/HTMLParser.py", line 329, in parse_endtag self.handle_endtag(tag.lower()) File "/usr/lib/python2.3/site-packages/validator/htmlfill.py", line 127, in handle_endtag self.handle_end_iferror() TypeError: handle_end_iferror() takes exactly 2 arguments (1 given) Thanks for any help! ===== -- Michel Thadeu Sabchuk Curitiba/PR _______________________________________________________ Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora! http://br.acesso.yahoo.com/ |