Skip to content

Commit

Permalink
Cherry-picked branch 'feature-1490-standard-package-output-from-logic…
Browse files Browse the repository at this point in the history
…-layer'
  • Loading branch information
amercader authored and David Read committed Dec 16, 2011
1 parent aeff7e5 commit bbaba50
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -155,6 +155,11 @@ def package_dictize(pkg, context):
q = select([rel_rev]).where(rel_rev.c.object_package_id == pkg.id)
result = _execute_with_revision(q, rel_rev, context)
result_dict["relationships_as_object"] = obj_list_dictize(result, context)
#isopen
# Get an actual Package object, not a PackageRevision
pkg_object = model.Package.get(pkg.id)
result_dict['isopen'] = pkg_object.isopen if isinstance(pkg_object.isopen,bool) else pkg_object.isopen()

return result_dict

def group_dictize(group, context):
Expand Down
14 changes: 9 additions & 5 deletions ckan/logic/action/get.py
Expand Up @@ -438,8 +438,11 @@ def group_package_show(context, data_dict):
if limit:
query = query.limit(limit)

pack_rev = query.all()
return _package_list_with_resources(context, pack_rev)
result = []
for pkg_rev in query.all():
result.append(package_dictize(pkg_rev,context))

return result

def tag_show(context, data_dict):
'''Shows tag details'''
Expand All @@ -457,9 +460,11 @@ def tag_show(context, data_dict):
check_access('tag_show',context, data_dict)

tag_dict = tag_dictize(tag,context)

extended_packages = []
for package in tag_dict['packages']:
extended_packages.append(_extend_package_dict(package,context))
pkg = model.Package.get(package['id'])
extended_packages.append(package_dictize(pkg,context))

tag_dict['packages'] = extended_packages

Expand Down Expand Up @@ -682,8 +687,7 @@ def package_search(context, data_dict):
log.warning('package %s in index but not in database' % package)
continue

result_dict = table_dictize(pkg, context)
result_dict = _extend_package_dict(result_dict,context)
result_dict = package_dictize(pkg,context)
results.append(result_dict)

return {
Expand Down
1 change: 1 addition & 0 deletions ckan/model/package.py
Expand Up @@ -189,6 +189,7 @@ def as_dict(self, ref_package_by='name', ref_group_by='name'):
# Set 'license' in _dict to cater for old clients.
# Todo: Remove from Version 2?
_dict['license'] = self.license.title if self.license else _dict.get('license_id', '')
_dict['isopen'] = self.isopen()
tags = [tag.name for tag in self.tags]
tags.sort() # so it is determinable
_dict['tags'] = tags
Expand Down
1 change: 1 addition & 0 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -43,6 +43,7 @@ def setup_class(cls):
'name': u'roger',
'state': u'active',
'title': u"Roger's books"}],
'isopen': True,
'license_id': u'other-open',
'maintainer': None,
'maintainer_email': None,
Expand Down

0 comments on commit bbaba50

Please sign in to comment.