[#29] Use new precedence feature for previews.

This commit is contained in:
Dominik Moritz 2013-07-19 12:35:35 +02:00 committed by amercader
parent b51f5de2f1
commit 43ee51e8c6
1 changed files with 31 additions and 9 deletions

View File

@ -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')
@ -28,13 +30,22 @@ class WMSPreview(p.SingletonPlugin):
p.toolkit.c.resource['proxy_url'] = data_dict['resource']['url'] p.toolkit.c.resource['proxy_url'] = data_dict['resource']['url']
def can_preview(self, data_dict): def can_preview(self, data_dict):
format_lower = data_dict['resource']['format'].lower() correct_format = format_lower in self.WMS
can_preview_from_domain = self.proxy_enabled or data_dict['resource']['on_same_domain']
quality = 2
check = format_lower in ['wms'] if p.toolkit.check_ckan_version('2.1'):
if not self.proxy_enabled and check: if correct_format:
check = data_dict['resource']['on_same_domain'] 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 check 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 +72,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