Merge branch '29-new-preview-interface'
This commit is contained in:
commit
5f56877eba
|
@ -11,6 +11,8 @@ class WMSPreview(p.SingletonPlugin):
|
||||||
p.implements(p.IConfigurer, inherit=True)
|
p.implements(p.IConfigurer, inherit=True)
|
||||||
p.implements(p.IResourcePreview, inherit=True)
|
p.implements(p.IResourcePreview, inherit=True)
|
||||||
|
|
||||||
|
WMS = ['wms']
|
||||||
|
|
||||||
def update_config(self, config):
|
def update_config(self, config):
|
||||||
|
|
||||||
p.toolkit.add_public_directory(config, 'public')
|
p.toolkit.add_public_directory(config, 'public')
|
||||||
|
@ -19,7 +21,6 @@ class WMSPreview(p.SingletonPlugin):
|
||||||
|
|
||||||
self.proxy_enabled = p.toolkit.asbool(config.get('ckan.resource_proxy_enabled', 'False'))
|
self.proxy_enabled = p.toolkit.asbool(config.get('ckan.resource_proxy_enabled', 'False'))
|
||||||
|
|
||||||
|
|
||||||
def setup_template_variables(self, context, data_dict):
|
def setup_template_variables(self, context, data_dict):
|
||||||
import ckanext.resourceproxy.plugin as proxy
|
import ckanext.resourceproxy.plugin as proxy
|
||||||
if self.proxy_enabled and not data_dict['resource']['on_same_domain']:
|
if self.proxy_enabled and not data_dict['resource']['on_same_domain']:
|
||||||
|
@ -30,11 +31,22 @@ class WMSPreview(p.SingletonPlugin):
|
||||||
def can_preview(self, data_dict):
|
def can_preview(self, data_dict):
|
||||||
format_lower = data_dict['resource']['format'].lower()
|
format_lower = data_dict['resource']['format'].lower()
|
||||||
|
|
||||||
check = format_lower in ['wms']
|
correct_format = format_lower in self.WMS
|
||||||
if not self.proxy_enabled and check:
|
can_preview_from_domain = self.proxy_enabled or data_dict['resource']['on_same_domain']
|
||||||
check = data_dict['resource']['on_same_domain']
|
quality = 2
|
||||||
|
|
||||||
return check
|
if p.toolkit.check_ckan_version('2.1'):
|
||||||
|
if correct_format:
|
||||||
|
if can_preview_from_domain:
|
||||||
|
return {'can_preview': True, 'quality': quality}
|
||||||
|
else:
|
||||||
|
return {'can_preview': False,
|
||||||
|
'fixable': 'Enable resource_proxy',
|
||||||
|
'quality': quality}
|
||||||
|
else:
|
||||||
|
return {'can_preview': False, 'quality': quality}
|
||||||
|
|
||||||
|
return correct_format and can_preview_from_domain
|
||||||
|
|
||||||
def preview_template(self, context, data_dict):
|
def preview_template(self, context, data_dict):
|
||||||
return 'dataviewer/wms.html'
|
return 'dataviewer/wms.html'
|
||||||
|
@ -61,11 +73,22 @@ class GeoJSONPreview(p.SingletonPlugin):
|
||||||
def can_preview(self, data_dict):
|
def can_preview(self, data_dict):
|
||||||
format_lower = data_dict['resource']['format'].lower()
|
format_lower = data_dict['resource']['format'].lower()
|
||||||
|
|
||||||
check = format_lower in self.GeoJSON
|
correct_format = format_lower in self.GeoJSON
|
||||||
if not self.proxy_enabled and check:
|
can_preview_from_domain = self.proxy_enabled or data_dict['resource']['on_same_domain']
|
||||||
check = data_dict['resource']['on_same_domain']
|
quality = 2
|
||||||
|
|
||||||
return check
|
if p.toolkit.check_ckan_version('2.1'):
|
||||||
|
if correct_format:
|
||||||
|
if can_preview_from_domain:
|
||||||
|
return {'can_preview': True, 'quality': quality}
|
||||||
|
else:
|
||||||
|
return {'can_preview': False,
|
||||||
|
'fixable': 'Enable resource_proxy',
|
||||||
|
'quality': quality}
|
||||||
|
else:
|
||||||
|
return {'can_preview': False, 'quality': quality}
|
||||||
|
|
||||||
|
return correct_format and can_preview_from_domain
|
||||||
|
|
||||||
def setup_template_variables(self, context, data_dict):
|
def setup_template_variables(self, context, data_dict):
|
||||||
import ckanext.resourceproxy.plugin as proxy
|
import ckanext.resourceproxy.plugin as proxy
|
||||||
|
|
Loading…
Reference in New Issue