--- a/web/test/unittest_views_json.py Thu Dec 20 12:14:14 2012 +0100
+++ b/web/test/unittest_views_json.py Thu Dec 20 12:15:57 2012 +0100
@@ -37,6 +37,13 @@
self.assertEqual(req.headers_out.getRawHeaders('content-type'), ['application/json'])
self.assertEqual(data, '[["guests", 1], ["managers", 1]]')
+ def test_json_rsetexport_empty_rset(self):
+ req = self.request()
+ rset = req.execute('Any X WHERE X is CWUser, X login "foobarbaz"')
+ data = self.view('jsonexport', rset)
+ self.assertEqual(req.headers_out.getRawHeaders('content-type'), ['application/json'])
+ self.assertEqual(data, '[]')
+
def test_json_rsetexport_with_jsonp(self):
req = self.request()
req.form.update({'callback': 'foo',
--- a/web/views/json.py Thu Dec 20 12:14:14 2012 +0100
+++ b/web/views/json.py Thu Dec 20 12:15:57 2012 +0100
@@ -23,6 +23,7 @@
_ = unicode
from cubicweb.utils import json_dumps
+from cubicweb.predicates import any_rset
from cubicweb.view import EntityView, AnyRsetView
from cubicweb.web.application import anonymized_request
from cubicweb.web.views import basecontrollers
@@ -90,6 +91,7 @@
class JsonRsetView(JsonMixIn, AnyRsetView):
"""dumps raw result set in JSON format"""
__regid__ = 'jsonexport'
+ __select__ = any_rset() # means rset might be empty or have any shape
title = _('json-export-view')
def call(self):