Thank your for your excellent help. The basic example works. Next step is your SchemaBuilder suggestion.
Regards Georg --------------------------------------------------------------------- Am 11.05.2010 11:44, schrieb Christoph Zwerschke: > Am 11.05.2010 08:53, schrieb Georg Balmer: >> I got the example from a direct download from formencode.org: >> . [2] svn co http://svn.colorstudy.com/FormEncode/trunk FormEncode >> (examples directory: WebwareExamples/index.py) > > Thanks, I was not aware of that example. Seems it was actually written > for Paste WebKit (http://pythonpaste.org/webkit/). > > As you noticed it uses htmlform which is deprecated; you must use > htmlfill directly. You must also add a name="color" attribute to the > checkboxes to make these work. > > It seems your problem is that the formencode errors are now unicode, so > you must encode these. Here is how I got it working with the current > Webware (I simplified it a bit by not using Webware actions): > > > class form(Page): > > schema = FormSchema() > > def awake(self, trans): > Page.awake(self, trans) > try: > fields = self.request().fields() > if 'name' in fields: > fields = self.schema.to_python(fields, self) > else: > fields = self.getDefaults() > except formencode.Invalid, e: > errors = dict((k, v.encode('utf-8')) > for k, v in e.unpack_errors().iteritems()) > else: > errors = None > self.rendered_form = formencode.htmlfill.render(form_template, > defaults=fields, errors=errors) > > def writeContent(self): > self.write(page_style % self.rendered_form) > > def getDefaults(self): > return dict(age='enter your age', color=['blue']) > > > Let me know how it works for you. > > Btw, instead of using a schema, you could also embed the validation info > in the form template and use the SchemaBuilder to parse these. > > -- Christoph > > ------------------------------------------------------------------------------ > > _______________________________________________ > Webware-discuss mailing list > Webware-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/webware-discuss > ------------------------------------------------------------------------------ _______________________________________________ Webware-discuss mailing list Webware-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/webware-discuss