Hi Steven,
Try using a validator instance:
class Root(controllers.RootController):
@turbogears.expose(template=".templates.welcome")
def index(self):
return dict(form=form, action="save")
@turbogears.validate(validators=MySchema())
@turbogears.expose()
def save(self, tg_errors=None, **kw):
return ("Errors: %r<br />"
"Values: %r" % (tg_errors, kw))
Though using this method you lose all the nice feautures the widget
framework is providing, like autocompletion of the input values the
user typed, nice error messages beside the fields, etc..
The "new way" of doing this is:
class MySchema(validators.Schema):
age = validators.Int()
class MyForm(widgets.TableForm):
fields = [
widgets.TextField("name"),
widgets.TextField("age"),
]
validator = MySchema()
form = MyForm()
class Root(controllers.RootController):
@turbogears.expose(template=".templates.welcome")
def index(self):
return dict(form=form, action="save")
@turbogears.validate(form=form)
@turbogears.error_handler(index)
@turbogears.expose()
def save(self, **kw):
return "Values: %r" % kw
You can also forget about the schema (if you don't need chained
validators, et al) and place the validator in it's own widget:
class MyForm(widgets.TableForm):
fields = [
widgets.TextField("name"),
widgets.TextField("age", validator=validators.Int()),
]
Alberto
On Feb 24, 2006, at 5:08 PM, Steven James wrote:
>
> Those tests look like good examples. I will take some time to study
> them. Thanks! I'll post here what I've tried so far, in the hopes that
> someone will recognize the problem--otherwise I will continue to work
> on the problem and post the solution here when I find it.
>
> My first attempt to fix this problem was using
> @validate(validators=Schema), as this was described in the
> DeprecationWarning of @expose. I got a traceback. It is worth noting
> that now I get the same traceback even when I use the deprecated
> @expose(validators=...).
>
> I tried like this:
>
> @turbogears.expose()
> @turbogears.validate(validators=setEmailForwardSchema)
> def setEmailForward(self, ...
>
> I get this traceback:
>
> Page handler: <bound method Root.setEmailForward of
> <ctiwebmin.controllers.Root object at 0x01040A10>>
> Traceback (most recent call last):
> File
> "c:\python24\lib\site-packages\CherryPy-2.2.0betadev_r980-py2.4.egg
> \cherrypy\_cphttptools.py",
> line 99, in _run
> self.main()
> File
> "c:\python24\lib\site-packages\CherryPy-2.2.0betadev_r980-py2.4.egg
> \cherrypy\_cphttptools.py",
> line 248, in main
> body = page_handler(*virtual_path, **self.params)
> File "<string>", line 3, in setEmailForward
> File
> "c:\python24\lib\site-packages\TurboGears-0.9a1-py2.4.egg\turbogears
> \controllers.py",
> line 210, in expose
> tg_format, html, fragment, *args, **kw)
> File
> "c:\python24\lib\site-packages\TurboGears-0.9a1-py2.4.egg\turbogears
> \database.py",
> line 193, in run_with_transaction
> retval = func(*args, **kw)
> File
> "c:\python24\lib\site-packages\TurboGears-0.9a1-py2.4.egg\turbogears
> \controllers.py",
> line 228, in _execute_func
> output = errorhandling.try_call(func, *args, **kw)
> File
> "c:\python24\lib\site-packages\TurboGears-0.9a1-py2.4.egg\turbogears
> \errorhandling.py",
> line 63, in try_call
> output = func(self, *args, **kw)
> File "<string>", line 3, in setEmailForward
> File
> "c:\python24\lib\site-packages\TurboGears-0.9a1-py2.4.egg\turbogears
> \controllers.py",
> line 136, in validate
> errors.update(error.unpack_errors())
> ValueError: dictionary update sequence element #0 has length 1; 2 is
> required
>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---