Skip to content

Commit

Permalink
[1741] add group view, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Feb 16, 2012
1 parent a4aa805 commit 7825cae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -205,7 +205,8 @@ def read(self, id):
group_type = self._get_group_type(id.split('@')[0])
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': self._form_to_db_schema(group_type=type)}
'schema': self._form_to_db_schema(group_type=type),
'for_view': True}
data_dict = {'id': id}
q = c.q = request.params.get('q', '') # unicode format (decoded from utf8)

Expand Down
6 changes: 5 additions & 1 deletion ckan/lib/dictization/model_dictize.py
@@ -1,6 +1,6 @@
from pylons import config
from sqlalchemy.sql import select, and_
from ckan.plugins import PluginImplementations, IDatasetForm, IPackageController
from ckan.plugins import PluginImplementations, IDatasetForm, IPackageController, IGroupController
import datetime

from ckan.model import PackageRevision
Expand Down Expand Up @@ -257,6 +257,10 @@ def group_dictize(group, context):

context['with_capacity'] = False

if context.get('for_view'):
for item in PluginImplementations(IGroupController):
result_dict = item.before_view(result_dict)

return result_dict

def tag_list_dictize(tag_list, context):
Expand Down
7 changes: 7 additions & 0 deletions ckan/plugins/interfaces.py
Expand Up @@ -207,6 +207,13 @@ def authz_remove_role(self, object_role):
def delete(self, entity):
pass

def before_view(self, pkg_dict):
'''
Extensions will recieve this before the group gets displayed. The dictionary
passed will be the one that gets sent to the template.
'''
return pkg_dict

class IPackageController(Interface):
"""
Hook into the package controller.
Expand Down
4 changes: 4 additions & 0 deletions ckan/tests/functional/test_group.py
Expand Up @@ -40,6 +40,10 @@ def authz_remove_role(self, object_role):
def delete(self, entity):
self.calls['delete'] += 1

def before_view(self, data_dict):
self.calls['before_view'] += 1
return data_dict

class TestGroup(FunctionalTestCase):

@classmethod
Expand Down
7 changes: 3 additions & 4 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -52,7 +52,7 @@ def setup_class(cls):
"approval_status": u"approved"}],
'isopen': True,
'license_id': u'other-open',
'license_title': u'OKD Compliant::Other (Open)',
'license_title': u'Other (Open)',
'maintainer': None,
'maintainer_email': None,
'type': None,
Expand Down Expand Up @@ -216,12 +216,11 @@ def test_02_package_dictize(self):

pprint(result)
pprint(self.package_expected)
print "\n".join(unified_diff(pformat(result).split("\n"), pformat(self.package_expected).split("\n")))

assert sorted(result.values()) == sorted(self.package_expected.values())
assert result == self.package_expected



def test_03_package_to_api1(self):

context = {"model": model,
Expand All @@ -233,7 +232,7 @@ def test_03_package_to_api1(self):
pprint(pkg.as_dict())
asdict = pkg.as_dict()
asdict['download_url'] = asdict['resources'][0]['url']
asdict['license_title'] = u'OKD Compliant::Other (Open)'
asdict['license_title'] = u'Other (Open)'

assert package_to_api1(pkg, context) == asdict

Expand Down

0 comments on commit 7825cae

Please sign in to comment.