Skip to content

Commit

Permalink
Merge branch 'wardi-2581-fix-lazyjson'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Sep 10, 2015
2 parents 23497a0 + 226ca45 commit 1621c0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 9 additions & 5 deletions ckan/lib/lazyjson.py
Expand Up @@ -28,7 +28,7 @@ def method(self, *args, **kwargs):
return getattr(self._loads(), name)(*args, **kwargs)
return method

for fn in ['__cmp__', '__contains__', '__delitem__', '__eq__', '__ge__',
for fn in ['__contains__', '__delitem__', '__eq__', '__ge__',
'__getitem__', '__gt__', '__iter__', '__le__', '__len__', '__lt__',
'__ne__', '__setitem__', 'clear', 'copy', 'fromkeys', 'get',
'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys',
Expand All @@ -47,9 +47,13 @@ class JSONString(int):
subclassing JSONEncoder and modifying its internal workings, or
monkeypatching the simplejson library.
'''
def __init__(self, s):
self.s = s
super(JSONString, self).__init__(-1)
def __new__(cls, s):
obj = super(JSONString, cls).__new__(cls, -1)
obj.s = s
return obj

def __str__(self):
return s
return self.s

def __repr__(self):
return "JSONString(%r)" % self.s
6 changes: 3 additions & 3 deletions ckan/logic/action/get.py
Expand Up @@ -1080,9 +1080,9 @@ def package_show(context, data_dict):
for item in plugins.PluginImplementations(plugins.IPackageController):
item.read(pkg)

for resource_dict in package_dict['resources']:
for item in plugins.PluginImplementations(plugins.IResourceController):
resource_dict = item.before_show(resource_dict)
for item in plugins.PluginImplementations(plugins.IResourceController):
for resource_dict in package_dict['resources']:
item.before_show(resource_dict)

if not package_dict_validated:
package_plugin = lib_plugins.lookup_package_plugin(
Expand Down
11 changes: 11 additions & 0 deletions ckan/tests/logic/action/test_get.py
Expand Up @@ -36,6 +36,17 @@ def foo(key, data, errors, context):

eq(dataset2['new_field'], 'foo')

def test_package_show_is_lazy(self):
dataset1 = factories.Dataset()

dataset2 = helpers.call_action(
'package_show',
id=dataset1['id'],
context=dict(return_type='LazyJSONObject'))

# LazyJSONObject passed through without being expanded
assert dataset2._json_dict is None


class TestGroupList(helpers.FunctionalTestBase):

Expand Down

0 comments on commit 1621c0a

Please sign in to comment.