Skip to content

Commit

Permalink
add whether resource is on same domain is now side effect free
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Nov 24, 2012
1 parent 451571c commit 3e8ce66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ckan/controllers/package.py
Expand Up @@ -1337,7 +1337,7 @@ def resource_datapreview(self, id, resource_id):
c.package = get_action('package_show')(context, {'id': id})

data_dict = {'resource': c.resource, 'package': c.package}
data_dict = h.add_whether_on_same_domain(data_dict)
data_dict['resource']['on_same_domain'] = h.resource_is_on_same_domain(data_dict)

plugins = p.PluginImplementations(p.IResourcePreview)
plugins_that_can_preview = [plugin for plugin in plugins if plugin.can_preview(data_dict)]
Expand Down
12 changes: 3 additions & 9 deletions ckan/lib/helpers.py
Expand Up @@ -1286,18 +1286,12 @@ def _compare_domains(urls):
return True


def add_whether_on_same_domain(data_dict):
''' sets the ``on_same_domain`` flag to a resource dictionary
to true if the resource is on the ckan instance domain
'''
def resource_is_on_same_domain(data_dict):
# compare CKAN domain and resource URL
ckan_url = config.get('ckan.site_url', '//localhost:5000')
resource_url = data_dict['resource']['url']

on_same_domain = _compare_domains([ckan_url, resource_url])

data_dict['resource']['on_same_domain'] = on_same_domain
return data_dict
return _compare_domains([ckan_url, resource_url])


def _can_be_previewed(data_dict):
Expand All @@ -1308,7 +1302,7 @@ def _can_be_previewed(data_dict):
The resource dict has to have a value for ``on_same_domain``
:type data_dict: dictionary
'''
data_dict = add_whether_on_same_domain(data_dict)
data_dict['resource']['on_same_domain'] = resource_is_on_same_domain(data_dict)
plugins = p.PluginImplementations(p.IResourcePreview)
return any(plugin.can_preview(data_dict) for plugin in plugins)

Expand Down

0 comments on commit 3e8ce66

Please sign in to comment.