Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Jonathan Lundell
On 30 Jul 2013, at 12:22 AM, Niphlod niph...@gmail.com wrote: can you explain better what's going on ? the generic json view (as any other view) is made to serialize a python object to something (in json's case, a json string). If you already return a string because your code encodes it

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Matt
On Tuesday, July 30, 2013 10:26:45 AM UTC-4, Jonathan Lundell wrote: On 30 Jul 2013, at 12:22 AM, Niphlod nip...@gmail.com javascript: wrote: can you explain better what's going on ? the generic json view (as any other view) is made to serialize a python object to something (in json's

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Anthony
Can you show your code? You say you return locals(), but locals() produces a dictionary, so it should ultimately execute a view. Or are you just returning the list directly? Anthony On Tuesday, July 30, 2013 10:28:53 AM UTC-4, Matt wrote: On Tuesday, July 30, 2013 10:26:45 AM UTC-4,

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Jonathan Lundell
On 30 Jul 2013, at 8:34 AM, Anthony abasta...@gmail.com wrote: Can you show your code? You say you return locals(), but locals() produces a dictionary, so it should ultimately execute a view. Or are you just returning the list directly? A list directly (see the code fragment below). Since

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Matt
On Tuesday, July 30, 2013 11:51:08 AM UTC-4, Jonathan Lundell wrote: On 30 Jul 2013, at 8:34 AM, Anthony abas...@gmail.com javascript: wrote: Can you show your code? You say you return locals(), but locals() produces a dictionary, so it should ultimately execute a view. Or are you just

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Matt Broadstone
On Tue, Jul 30, 2013 at 2:11 PM, Matt mbroa...@gmail.com wrote: On Tuesday, July 30, 2013 11:51:08 AM UTC-4, Jonathan Lundell wrote: On 30 Jul 2013, at 8:34 AM, Anthony abas...@gmail.com wrote: Can you show your code? You say you return locals(), but locals() produces a dictionary, so it

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Matt Broadstone
On Tue, Jul 30, 2013 at 2:14 PM, Alan Etkin spame...@gmail.com wrote: The question is: what should happen when a controller returns a list? The JSON serializer is happy to serialize a list. Is there any downside in doing it? Does it make any sense right now for a controller to return a

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Alan Etkin
The question is: what should happen when a controller returns a list? The JSON serializer is happy to serialize a list. Is there any downside in doing it? Does it make any sense right now for a controller to return a list? It would be inconsistent with this documented part of the

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Anthony
@request.restful() def jsonlisttest(): response.view = 'generic.json' def GET(*args, **vars): sample_raw_rpc_response = '[one, two, three]' sample_rpc_response = simplejson.loads(sample_raw_rpc_response) return sample_rpc_response Looks like you're starting

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Matt Broadstone
On Tue, Jul 30, 2013 at 2:26 PM, Anthony abasta...@gmail.com wrote: @request.restful() def jsonlisttest(): response.view = 'generic.json' def GET(*args, **vars): sample_raw_rpc_response = '[one, two, three]' sample_rpc_response =

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Anthony
So the advice is to make generic-list.json, and force that view, expecting that the input is in some format we decide upon. e.g. instead of returning sample_rpc_response, we return dict(result=sample_rpc_response)? You could do that, but see my other response. Anthony -- --- You

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Matt Broadstone
On Tue, Jul 30, 2013 at 2:31 PM, Anthony abasta...@gmail.com wrote: So the advice is to make generic-list.json, and force that view, expecting that the input is in some format we decide upon. e.g. instead of returning sample_rpc_response, we return dict(result=sample_rpc_**response)? You

Re: [web2py] controller return list instead of string or dict

2013-07-30 Thread Anthony
Why not: def GET(*args, **vars): sample_raw_rpc_response = '[one, two, three]' sample_rpc_response = simplejson.loads(sample_raw_rpc_response) result = someOtherOperationThatCanPOTENTIALLYReturnAList( sample_rpc_response) return simplejson.dumps(result) Or if

[web2py] controller return list instead of string or dict

2013-07-29 Thread Matt
Hi, We're running into an issue with our restful api where a certain method is returning a json string (eg: ['one', 'two', 'three'] ), however web2py wants to render this as a string even when the request.extension is forced to json, and the response.view is forced to generic.json. I've