Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 220-clean-user-controller-imports
- Loading branch information
Showing
156 changed files
with
1,723 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# coding=UTF-8 | ||
|
||
"""Data previewer functions | ||
Functions and data structures that are needed for the ckan data preview. | ||
""" | ||
|
||
import urlparse | ||
|
||
import pylons.config as config | ||
|
||
import ckan.plugins as p | ||
|
||
DEFAULT_DIRECT_EMBED = ['png', 'jpg', 'gif'] | ||
DEFAULT_LOADABLE_IFRAME = ['html', 'htm', 'rdf+xml', 'owl+xml', 'xml', 'n3', 'n-triples', 'turtle', 'plain', 'atom', 'rss', 'txt'] | ||
|
||
|
||
def compare_domains(urls): | ||
''' Return True if the domains of the provided are the same. | ||
''' | ||
first_domain = None | ||
for url in urls: | ||
# all urls are interpreted as absolute urls, | ||
# except for urls that start with a / | ||
if not urlparse.urlparse(url).scheme and not url.startswith('/'): | ||
url = '//' + url | ||
parsed = urlparse.urlparse(url.lower(), 'http') | ||
domain = (parsed.scheme, parsed.hostname, parsed.port) | ||
|
||
if not first_domain: | ||
first_domain = domain | ||
continue | ||
if first_domain != domain: | ||
return False | ||
return True | ||
|
||
|
||
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'] | ||
|
||
return compare_domains([ckan_url, resource_url]) | ||
|
||
|
||
def can_be_previewed(data_dict): | ||
''' | ||
Determines whether there is an extension that can preview the resource. | ||
:param data_dict: contains a resource and package dict. | ||
The resource dict has to have a value for ``on_same_domain`` | ||
:type data_dict: dictionary | ||
''' | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
<div class="module-content"> | ||
<div class="alert alert-block"> | ||
<h4 class="pull-left">{{ _('This resource cannot be previewed.') }} </h4> | ||
<button class="btn btn-link btn-mini" data-toggle="collapse" data-target="#demo"> | ||
<i class="icon-info-sign"></i> More details... | ||
<button class="btn btn-link btn-mini" data-toggle="collapse" data-target="#details"> | ||
<i class="icon-info-sign"></i> {{ _('More details...') }} | ||
</button> | ||
<div id="demo" class="collapse"> | ||
{% set t = '<code>'|safe + resource_type + '</code>'|safe %} | ||
{{ gettext('No handler defined for data type: %(type)s.', type=t) }} | ||
<div id="details" class="collapse"> | ||
{% if reason %} | ||
{{_(reason)}} | ||
{% else %} | ||
{% set t = '<code>'|safe + resource_type + '</code>'|safe %} | ||
{{ gettext('No handler defined for data type: %(type)s.', type=t) }} | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.