> No, it means that '1', '2', ... are the values that will be inserted
> *without conversion* into the "value" attribute of the <option> tag in
> the template.
This is your misconception. These are the values that are used to be
compared with the _to_python-converted request parameter value. You are
right though that they aren't converted during rendering, except from
being stringified.
See the following example for a working pre-selection of a value in a
SingleSelectField:
---- controller -----
from turbogears import controllers, expose
import turbogears.widgets as w
import turbogears.validators as v
def calc_options():
return [(i, "value: %i" % i) for i in xrange(1000)]
form = w.ListForm(fields=[w.SingleSelectField('test', options=calc_options,
validator=v.Int(not_empty=True)),
w.TextField('foo')])
class Root(controllers.RootController):
@expose(template="testproject.templates.welcome")
def index(self):
import time
# log.debug("Happy TurboGears Controller Responding For Duty")
return dict(now=time.ctime(), form=form, selected=100, foo='bar')
----- template ----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://purl.org/kid/ns#"
py:extends="'master.kid'">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"
py:replace="''"/>
<title>Welcome to TurboGears</title>
</head>
<body>
${selected}
${form.display(dict(test='20', foo='baz'))}
</body>
</html>
So, again: the values in the option-list are compared to whatever the
validators _to_python-method yields.
From the formencode docs:
"""
The basic metaphor for validation is to_python and from_python. In this
context "Python" is meant to refer to "here" -- the trusted application,
your own Python objects. The "other" may be a web form, an external
database, an XML-RPC request, or any data source that is not completely
trusted or does not map directly to Python's object model. to_python is
the process of taking external data and preparing it for internal use,
from_python generally reverses this process (from_python is usually the
less interesting of the pair, but provides some important features).
"""
So - from that POV, it's the right way TG uses the validation stuff.
OTH, it is sort of an omission that the current implementation doesn't
use to from_python-method to convert e.g. model objects to id to render
them as part of a select.
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
-~----------~----~----~----~------~----~------~--~---