I've having problems putting an optional FileField on my form.
If I use:
FileField("photo", validator=validators.FieldStorageUploadConverter())
and don't enter a photo, then it returns a tg_error of "invalid" for
the field (which isn't a helpful error message).
If I use:
FileField("photo",
validator=validators.Any(validators.FieldStorageUploadConverter(),validators.Empty()))
then I get the error message below.
Any ideas on how to make the field optional, yet vaildate correctly if
there is something in it?
Ed
Error Message:
Page handler: <bound method PostController.save of
<wltm.controllers.PostController object at 0x015D8DB0>>
Traceback (most recent call last):
File
"c:\python24\lib\site-packages\CherryPy-2.2.1-py2.4.egg\cherrypy\_cphttptools.py",
line 105, in _run
self.main()
File
"c:\python24\lib\site-packages\CherryPy-2.2.1-py2.4.egg\cherrypy\_cphttptools.py",
line 254, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in save
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\controllers.py",
line 273, in expose
output = database.run_with_transaction(
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\database.py",
line 221, in run_with_transaction
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\controllers.py",
line 290, in <lambda>
mapping, fragment, *args, **kw)))
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\controllers.py",
line 314, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\errorhandling.py",
line 71, in try_call
return func(self, *args, **kw)
File "<string>", line 3, in save
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\controllers.py",
line 118, in validate
kw.update(form.validate(value))
File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\widgets\forms.py",
line 1046, in validate
return self.validator.to_python(value, state)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\api.py",
line 316, in to_python
value = tp(value, state)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\schema.py",
line 132, in _to_python
new[name] = validator.to_python(value, state)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\api.py",
line 316, in to_python
value = tp(value, state)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\compound.py",
line 57, in _to_python
to_python)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\compound.py",
line 82, in attempt_convert
return validate(validator, value, state)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\compound.py",
line 15, in to_python
return validator.to_python(value, state)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\api.py",
line 319, in to_python
vp(value, state)
File
"c:\python24\lib\site-packages\FormEncode-0.5.1-py2.4.egg\formencode\validators.py",
line 442, in validate_python
if value or value == 0:
File "c:\Python24\lib\cgi.py", line 625, in __len__
return len(self.keys())
File "c:\Python24\lib\cgi.py", line 601, in keys
raise TypeError, "not indexable"
TypeError: not indexable
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---