On 1/13/06, Max Ischenko <[EMAIL PROTECTED]> wrote:
>
> Here is how what I ended up with, in case of anyone interested:
>
>
>     @turbogears.expose(content_type="text/html; charset=UTF-8",
>             html="bookswap.templates.addbook")
>     def addbook(self, **kw):
>         ### XXX: why this is needed?
>         for k,v in kw.items():
>             if isinstance(v, str): kw[k] = unicode(v, 'utf-8')
>         if kw: # feed data if any
>             addBookForm.input(kw)
>             cherrypy.request.input_values = kw # to display form with
> data
>         if cherrypy.request.method == 'POST':
>             errors = cherrypy.request.form_errors
>             cherrypy.request.form_processed = True
>             if errors:
>                 turbogears.flash(_('please correct errors below'))
>             else:
>                 log.info("Adding book from %s", kw)
>                 turbogears.flash(_('book has been added'))
>                 turbogears.redirect('/addbook')
>         return dict(form=addBookForm)
>
> Note the absense of inputform parameter in expose() and the need to set
> cherrypy.request.input_values in order the form to be displayed filled
> with user data.

Yeah, that's pretty ugly. You don't *have* to put the data in
input_values. You can alternatively pass a dictionary (or instance) to
the form from your template.

> A weird thing: yesterdays unicode data were handled OK by this
> particular method but after today's SVN update it broke and I had to
> add this hack in order to make it work again:

Hmm... We did have the UnicodeDecodeFilter included. I wonder if that
is not included any longer for some reason.

Kevin

Reply via email to