#824: Number validator not working
------------------------+---------------------------------------------------
Reporter: anonymous | Owner: godoy
Type: defect | Status: new
Priority: normal | Milestone:
Component: TurboGears | Version: 0.9a5
Severity: normal | Resolution:
Keywords: |
------------------------+---------------------------------------------------
Comment (by anonymous):
I changed the method decorators to:
{{{
@turbogears.expose(format='json', allow_json=True)
@JSON_INPUT(validators = validators)
@turbogears.validate(validators = validators)
def changedContactIDs(self, last_sync_date):
}}}
This change produced the following output:
2006-05-09 09:38:02,007 cherrypy.msg INFO HTTP: Page handler: <bound
method GroupAPIController.newFunction of
<contact.controllers.group.GroupAPIController object at 0x142bed0>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line
105, in _run
self.main()
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/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 newFunction
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/TurboGears-0.9a5-py2.4.egg/turbogears/controllers.py", line
210, in expose
output = database.run_with_transaction(func._expose,func, accept,
allow_json, allow_json_from_config,*args, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/TurboGears-0.9a5-py2.4.egg/turbogears/database.py", line
216, in run_with_transaction
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/TurboGears-0.9a5-py2.4.egg/turbogears/controllers.py", line
230, in <lambda>
func._expose.when(rule)(lambda _func, accept, allow_json,
allow_json_from_config,*args,**kw: _execute_func(
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/TurboGears-0.9a5-py2.4.egg/turbogears/controllers.py", line
251, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/TurboGears-0.9a5-py2.4.egg/turbogears/errorhandling.py",
line 71, in try_call
return func(self, *args, **kw)
File "/Volumes/Litter
Box/Users/stodd/Documents/Contracts/[EMAIL
PROTECTED]/Projects/contact/contact/controllers/group.py",
line 23, in newFunction
theItems = [(theKey,
validators[theKey].to_python(theDictionary[theKey])) for theKey in
theValidationKeys]
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/FormEncode-0.5.1-py2.4.egg/formencode/api.py", line 316, in
to_python
value = tp(value, state)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/TurboGears-0.9a5-py2.4.egg/turbogears/validators.py", line
57, in _to_python
value = format.parse_decimal(value)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4
/site-packages/TurboGears-0.9a5-py2.4.egg/turbogears/i18n/format.py", line
165, in parse_decimal
value = value.replace(get_group_format(locale), "")
AttributeError: 'float' object has no attribute 'replace'
So, it appears that there was a change in
to_python/_to_python/parse_decimal sequence.
FYI, I inherited the code for JSON_INPUT which is as follows:
{{{
def JSON_INPUT(validators = {}):
def decorator(fn):
def newFunction(self, *args, **vargs):
if cherrypy.request.headerMap['Content-Type'] ==
'text/javascript':
theBody = cherrypy.request.body.read()
theDictionary = simplejson.loads(theBody)
theValidationKeys =
set(theDictionary.keys()).intersection(set(validators.keys()))
theItems = [(theKey,
validators[theKey].to_python(theDictionary[theKey])) for theKey in
theValidationKeys]
theDictionary.update(dict(theItems))
theDictionary = dict([(str(theItem[0]),
theItem[1]) for theItem in theDictionary.items()])
vargs.update(theDictionary)
result = fn(self, *args, **vargs)
return result
return newFunction
return decorator
}}}
--
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/824>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Tickets" 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-tickets
-~----------~----~----~----~------~----~------~--~---