diff --git a/ckanext/reclineview/plugin.py b/ckanext/reclineview/plugin.py index 9e3cb1a0211..20e204bb794 100644 --- a/ckanext/reclineview/plugin.py +++ b/ckanext/reclineview/plugin.py @@ -58,7 +58,9 @@ def update_config(self, config): toolkit.add_resource('theme/public', 'ckanext-reclineview') def can_view(self, data_dict): - return data_dict['resource'].get('datastore_active') + resource = data_dict['resource'] + return (resource.get('datastore_active') or + resource.get('url') == '_datastore_only_resource') def setup_template_variables(self, context, data_dict): return {'resource_json': json.dumps(data_dict['resource']), @@ -83,9 +85,12 @@ def info(self): } def can_view(self, data_dict): - if data_dict['resource'].get('datastore_active'): + resource = data_dict['resource'] + + if (resource.get('datastore_active') or + resource.get('url') == '_datastore_only_resource'): return True - resource_format = data_dict['resource'].get('format', None) + resource_format = resource.get('format', None) if resource_format: return resource_format.lower() in ['csv', 'xls', 'xlsx', 'tsv'] else: diff --git a/ckanext/reclineview/tests/test_view.py b/ckanext/reclineview/tests/test_view.py index 1dd2388f7e6..2f7ab070836 100644 --- a/ckanext/reclineview/tests/test_view.py +++ b/ckanext/reclineview/tests/test_view.py @@ -9,6 +9,8 @@ import ckan.lib.create_test_data as create_test_data import ckan.config.middleware as middleware +from ckan.new_tests import helpers, factories + class BaseTestReclineViewBase(tests.WsgiAppCase): @classmethod @@ -78,6 +80,47 @@ def test_can_view_bad_format_no_datastore(self): assert not self.p.can_view(data_dict) +class TestReclineViewDatastoreOnly(helpers.FunctionalTestBase): + + @classmethod + def setup_class(cls): + if not p.plugin_loaded('recline_view'): + p.load('recline_view') + if not p.plugin_loaded('datastore'): + p.load('datastore') + app_config = config.copy() + app_config['ckan.legacy_templates'] = 'false' + app_config['ckan.plugins'] = 'recline_view datastore' + app_config['ckan.views.default_views'] = 'recline_view' + wsgiapp = middleware.make_app(config['global_conf'], **app_config) + cls.app = paste.fixture.TestApp(wsgiapp) + + @classmethod + def teardown_class(cls): + if p.plugin_loaded('recline_view'): + p.unload('recline_view') + if p.plugin_loaded('datastore'): + p.unload('datastore') + + def test_create_datastore_only_view(self): + dataset = factories.Dataset() + data = { + 'resource': {'package_id': dataset['id']}, + 'fields': [{'id': 'a'}, {'id': 'b'}], + 'records': [{'a': 1, 'b': 'xyz'}, {'a': 2, 'b': 'zzz'}] + } + result = helpers.call_action('datastore_create', **data) + + resource_id = result['resource_id'] + + url = h.url_for(controller='package', action='resource_read', + id=dataset['id'], resource_id=resource_id) + + result = self.app.get(url) + + assert 'data-module="data-viewer"' in result.body + + class TestReclineGridView(BaseTestReclineViewBase): view_type = 'recline_grid_view' view_class = plugin.ReclineGridView