> Before I get into my specific code, here's a quick contrived example
> of how it currently works and how I think it should work:
> 
>     @expose(template='.foo')
>     def test(self):
>         class TestObj(object):
>             def __init__(self):
>                 self.testval='three:3'
> 
>         class TestValidator:
>             def to_python(self, value, state=None):
>                 log.info('Call to_python on value "%s"', value)
>                 result = {'1':'one:1',
>                           '2':'two:2',
>                           '3':'three:3',
>                           '4':'four:4',
>                           '5':'five:5' }.get(value, None)
>                 if result is None: raise Invalid('Bad Value', value,
> state)
>                 return result
>             def from_python(self, value, state=None):
>                 log.info('Call from_python on value "%s"', value)
>                 name, id = value.split(':')
>                 return id
> 
>         class TestFields(WidgetsList):
>             testval=SingleSelectField(
>                 'testval', label='Test Value',
>                 options=[('1','one'), ('2','two'), ('3','three'),
> ('4','four')],
>                 validator=TestValidator())
> 
>         test_form = TableForm('test', fields=TestFields())
> 
>         return dict(form=test_form,
>                     item=TestObj())
> 
> The template has the expected ${form.display(item)}.  If I use the
> widgets code as-is, I get the following log output:
> 
> ...
> 2007-03-04 07:00:58,853 tutornet.controllers INFO Call to_python on
> value "three:3"
> 2007-03-04 07:00:58,982 tutornet.controllers INFO Call to_python on
> value "three:3"
> 2007-03-04 07:00:58,982 tutornet.controllers INFO Call to_python on
> value "three:3"
> 2007-03-04 07:00:58,983 tutornet.controllers INFO Call to_python on
> value "three:3"
> 
> And of course, no option in the select field is ever selected.  If I
> switch the widgets code to call from_python, however, I get the
> following log output:
> 
> ...
> 2007-03-04 07:04:34,820 tutornet.controllers INFO Call from_python on
> value "three:3"
> 2007-03-04 07:04:34,822 tutornet.controllers INFO Call from_python on
> value "three:3"
> 2007-03-04 07:04:34,823 tutornet.controllers INFO Call from_python on
> value "three:3"
> 2007-03-04 07:04:34,825 tutornet.controllers INFO Call from_python on
> value "three:3"
> 
> And the third option is correctly selected.

To me it looks as if you reversed the to- and from-values - no wonder 
that you need to switch the calls.

Your option list is this:


[('1','one'), ('2','two'), ('3','three'),  ('4','four')]

Which means that '1', '2', ... _are_ the *python* values we're talking 
here about.

But in your validator's _to_python-call, you map '1' to 'one:1'.

Now obviously '1' != 'one:1' and so forth, so that the selected item 
will never get displayed correctly.

So either your option-list reads

[('one:1','one'), ('two:2','two'), ('three:3','three'),  ('four:4','four')]

or your mapping has to work differently.

Diez

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to