import os import re from logging import getLogger from pylons import config from pylons.i18n import _ from genshi.input import HTML from genshi.filters import Transformer import ckan.lib.helpers as h from ckan.lib.search import SearchError from ckan.lib.helpers import json from ckan import model from ckan.plugins import implements, SingletonPlugin from ckan.plugins import IRoutes from ckan.plugins import IConfigurable, IConfigurer from ckan.plugins import IGenshiStreamFilter from ckan.plugins import IPackageController from ckan.logic import ValidationError import html from ckanext.spatial.lib import save_package_extent,validate_bbox, bbox_query from ckanext.spatial.model import setup as setup_model log = getLogger(__name__) def package_error_summary(error_dict): ''' Do some i18n stuff on the error_dict keys ''' def prettify(field_name): field_name = re.sub('(?' map_attribution = html.MAP_ATTRIBUTION_OSM elif map_type == 'os': js_library_links = '' map_attribution = '' # done in the js instead data = {'extent': extent, 'title': _(title), 'map_type': map_type, 'js_library_links': js_library_links, 'map_attribution': map_attribution, 'element_id': map_element_id} stream = stream | Transformer('body//div[@id="%s"]' % map_element_id)\ .append(HTML(body_html % data)) stream = stream | Transformer('head')\ .append(HTML(html.PACKAGE_MAP_EXTRA_HEADER % data)) stream = stream | Transformer('body')\ .append(HTML(html.PACKAGE_MAP_EXTRA_FOOTER % data)) return stream def update_config(self, config): here = os.path.dirname(__file__) template_dir = os.path.join(here, 'templates') public_dir = os.path.join(here, 'public') if config.get('extra_template_paths'): config['extra_template_paths'] += ','+template_dir else: config['extra_template_paths'] = template_dir if config.get('extra_public_paths'): config['extra_public_paths'] += ','+public_dir else: config['extra_public_paths'] = public_dir