diff --git a/ckan/controllers/group.py b/ckan/controllers/group.py index b962a8d7c99..22397c4160e 100644 --- a/ckan/controllers/group.py +++ b/ckan/controllers/group.py @@ -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) diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py index 083bea1b600..4f18ebb8234 100644 --- a/ckan/lib/dictization/model_dictize.py +++ b/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 @@ -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): diff --git a/ckan/plugins/interfaces.py b/ckan/plugins/interfaces.py index 5c87b4953a3..2f5252d808d 100644 --- a/ckan/plugins/interfaces.py +++ b/ckan/plugins/interfaces.py @@ -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. diff --git a/ckan/tests/functional/test_group.py b/ckan/tests/functional/test_group.py index 9707e8889af..05be9188a4b 100644 --- a/ckan/tests/functional/test_group.py +++ b/ckan/tests/functional/test_group.py @@ -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 diff --git a/ckan/tests/lib/test_dictization.py b/ckan/tests/lib/test_dictization.py index 74018cb9ed3..680024b1d50 100644 --- a/ckan/tests/lib/test_dictization.py +++ b/ckan/tests/lib/test_dictization.py @@ -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, @@ -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, @@ -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