Hello,

I'm trying to use newfangled widgets and run into a problem. I'm not sure 
whether I'm doing something wrong or simply run into a bug.

I have defined widget-based form like this:


addBookForm = TableForm(name='addbook', submittext=_('Add Book'),
        widgets=[...])

Now I have the following method in my controller class:

    @turbogears.expose(content_type="text/html; charset=UTF-8",
            inputform=addBookForm,
            html="bookswap.templates.addbook")
    def addbook(self, **kw):
        if cherrypy.request.method == 'POST':
            errors = cherrypy.request.form_errors
            if errors:
                turbogears.flash(_('please correct errors below'))
            else:
                turbogears.flash(_('book has been added'))
                raise cherrypy.HTTPRedirect(turbogears.url("/addbook"))
        return dict(form=addBookForm)

The logic is simple: on GET request simply present user with a form. On POST, 
validate form data and either redirect to the same form (/addbook) to enter 
next book or re-display form highlighting the errors.

Note that addBookForm is a static var (module-level global). Btw, is it OK? In 
other thread Kevin said that widgets are stateless so I suppose I'm doing right 
but it feels a bit awkward. Anyway.


When I'm trying to display form in a brower I got a traceback:

Traceback (most recent call last):
  File 
"C:\Python24\Lib\site-packages\CherryPy-2.1.0-py2.4.egg\cherrypy\_cphttptools.py",
 line 271, in run
    main()
  File 
"C:\Python24\Lib\site-packages\CherryPy-2.1.0-py2.4.egg\cherrypy\_cphttptools.py",
 line 502, in main
    body = page_handler(*args, **cherrypy.request.paramMap)
  File "d:\projects\3rd-party\turbogears\turbogears\controllers.py", line 240, 
in newfunc
    html, fragment, *args, **kw)
  File "d:\projects\3rd-party\turbogears\turbogears\database.py", line 191, in 
run_with_transaction
    retval = func(*args, **kw)
  File "d:\projects\3rd-party\turbogears\turbogears\controllers.py", line 257, 
in _execute_func
    output = func(self, *args, **kw)
  File "d:\projects\3rd-party\turbogears\turbogears\controllers.py", line 111, 
in newfunc
    inputform.input(kw)
  File "d:\projects\3rd-party\turbogears\turbogears\widgets\forms.py", line 
108, in input
    widget.input(values)
  File "d:\projects\3rd-party\turbogears\turbogears\widgets\base.py", line 366, 
in input
    widget.input(values)
  File "d:\projects\3rd-party\turbogears\turbogears\widgets\base.py", line 134, 
in input
    params[self.name] = self.validator.to_python(
  File 
"C:\Python24\Lib\site-packages\FormEncode-0.4-py2.4.egg\formencode\api.py", 
line 304, in to_python
    value = tp(value, state)
  File 
"C:\Python24\Lib\site-packages\FormEncode-0.4-py2.4.egg\formencode\validators.py",
 line 923, in _to_python
    value = float(value)
TypeError: float() argument must be a string or a number

After I changed line 106 of the controllers.py from:
            if not processed and form:
to: 
            if not processed and form and kw:
the problem gone.

That's using r491 of SVN.



Reply via email to