2011-10-28 14:03:31 +02:00
|
|
|
from logging import getLogger
|
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
from ckan import plugins as p
|
2011-10-28 14:03:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
log = getLogger(__name__)
|
|
|
|
|
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
class WMSPreview(p.SingletonPlugin):
|
2011-10-28 14:03:31 +02:00
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
p.implements(p.IConfigurer, inherit=True)
|
|
|
|
p.implements(p.IResourcePreview, inherit=True)
|
2011-10-28 14:03:31 +02:00
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
def update_config(self, config):
|
|
|
|
''' Set up the resource library, public directory and
|
|
|
|
template directory for the preview
|
|
|
|
'''
|
|
|
|
p.toolkit.add_public_directory(config, 'public')
|
|
|
|
p.toolkit.add_template_directory(config, 'templates/dataviewer')
|
|
|
|
p.toolkit.add_resource('public', 'ckanext-wmspreview')
|
2011-10-28 14:03:31 +02:00
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
self.proxy_enabled = config.get('ckan.resource_proxy_enabled', False)
|
2011-10-28 14:03:31 +02:00
|
|
|
|
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
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']:
|
|
|
|
p.toolkit.c.resource['proxy_url'] = proxy.get_proxified_resource_url(data_dict)
|
|
|
|
else:
|
|
|
|
p.toolkit.c.resource['proxy_url'] = data_dict['resource']['url']
|
2011-10-28 14:03:31 +02:00
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
def can_preview(self, data_dict):
|
|
|
|
format_lower = data_dict['resource']['format'].lower()
|
2011-10-28 14:03:31 +02:00
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
check = format_lower in ['wms']
|
|
|
|
if not self.proxy_enabled and check:
|
|
|
|
check = data_dict['resource']['on_same_domain']
|
2011-10-28 14:03:31 +02:00
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
return check
|
2011-10-28 14:03:31 +02:00
|
|
|
|
2013-01-14 14:59:15 +01:00
|
|
|
def preview_template(self, context, data_dict):
|
|
|
|
return 'wms.html'
|