On 2007-06-17 16:03:23 +0200, Christopher Arndt wrote:
>
> Michael Bienia schrieb:
> > I had to move the validator from the schema to the validator attribute
> > of the widget to get it working (and then even the inherited
> > from_python() worked).
> >
> > Has someone an idea why it works when I add my validator to the widget
> > but not if I do it from a schema definition?
>
> I don't know. Can you post [1] some code?
I've created a minimal testcase. I'm using turbogears 1.0.2.2.
Here is the controller from my testcase (newly started project with
tg-admin quickstart):
---8<---
from turbogears import controllers, expose, flash, redirect
from turbogears import widgets, validators, validate, error_handler
class MyValidator(validators.Number):
def _from_python(self, value, state):
return "foobar"
class NumberField(widgets.WidgetsList):
number1 = widgets.TextField()
number2 = widgets.TextField(validator = validators.Number(not_empty = True))
number3 = widgets.TextField()
number4 = widgets.TextField(validator = MyValidator(not_empty = True))
class NumberSchema(validators.Schema):
number1 = validators.Number(not_empty = True)
number2 = validators.Number(not_empty = True)
number3 = MyValidator(not_empty = True)
number4 = MyValidator(not_empty = True)
number_form = widgets.TableForm(fields = NumberField(), action = "accept",
validator = NumberSchema())
class Root(controllers.RootController):
@expose(template="foobar.templates.welcome")
def index(self):
import time
return dict(now=time.ctime())
@expose(template = ".templates.number_form")
def edit(self):
return dict(form = number_form, data = {'number1': 5.1, 'number2': 5.2,
'number3': 5.3, 'number4': 5.4})
@expose()
@error_handler(edit)
@validate(form = number_form)
def accept(self, **data):
flash("All are numbers")
redirect('/index')
--->8---
MyValidator is not really useful but it demonstrates the problem quite
good. The number_form template contains only
<div py:content="form(value = data)">form</div>
in the body.
When visiting http://localhost:8080/edit I see
Number1: 5.1
Number2: 5,2
Number3: 5.3
Number4: foobar
My locale is german ("de").
All four fields report an error if I enter a non-number but only fields
2 and 4 format the preset data.
Michael
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---