Merge branch '29-new-preview-interface'

This commit is contained in:
amercader 2013-08-08 17:52:05 +01:00
commit 5f56877eba
1 changed files with 32 additions and 9 deletions

View File

@ -11,6 +11,8 @@ class WMSPreview(p.SingletonPlugin):
p.implements(p.IConfigurer, inherit=True)
p.implements(p.IResourcePreview, inherit=True)
WMS = ['wms']
def update_config(self, config):
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'))
def setup_template_variables(self, context, data_dict):
import ckanext.resourceproxy.plugin as proxy
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):
format_lower = data_dict['resource']['format'].lower()
check = format_lower in ['wms']
if not self.proxy_enabled and check:
check = data_dict['resource']['on_same_domain']
correct_format = format_lower in self.WMS
can_preview_from_domain = self.proxy_enabled or 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):
return 'dataviewer/wms.html'
@ -61,11 +73,22 @@ class GeoJSONPreview(p.SingletonPlugin):
def can_preview(self, data_dict):
format_lower = data_dict['resource']['format'].lower()
check = format_lower in self.GeoJSON
if not self.proxy_enabled and check:
check = data_dict['resource']['on_same_domain']
correct_format = format_lower in self.GeoJSON
can_preview_from_domain = self.proxy_enabled or 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):
import ckanext.resourceproxy.plugin as proxy