示例#1
0
def get_tile_layer_config():
    '''
        Returns a dict with all configuration options related to the common
        base map (ie those starting with 'ckanext.basemaps.layers')
    '''

    namespace = 'ckanext.basemaps.laylers.'
    conf_dict = dict([(k.replace(namespace, ''), v)
                      for k, v in config.iteritems()
                      if k.startswith(namespace)])
    if conf_dict:
        arr_name = conf_dict['names'].split(',')
        arr_url = conf_dict['urls'].split(',')
        arr_attribution = conf_dict['attributions'].split(',')
        arr_subdomains = json.JSONDecoder().decode(conf_dict['subdomains'])
        json_dict = {}
        for x in xrange(0, len(arr_name)):
            tmp_dict = {}
            tmp_dict['url'] = arr_url[x]
            try:
                tmp_dict['attribution'] = arr_attribution[x]
            except IndexError:
                tmp_dict['attribution'] = ""
            try:
                tmp_dict['subdomains'] = arr_subdomains[x]
            except IndexError:
                tmp_dict['subdomains'] = [""]

            json_dict[arr_name[x]] = tmp_dict
        return json_dict
    else:
        return conf_dict
示例#2
0
文件: plugin.py 项目: fugitspace/ckan
def get_mapview_config():
    '''
    Extracts and returns map view configuration of the reclineview extension.
    '''
    namespace = 'ckanext.spatial.common_map.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#3
0
def get_common_map_config():
    '''
        Returns a dict with all configuration options related to the common
        base map (ie those starting with 'ckanext.spatial.common_map.')
    '''
    namespace = 'ckanext.spatial.common_map.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems() if k.startswith(namespace)])
def get_gmap_config():
    '''
        Returns a dict with all configuration options related to the
        Google Maps API (ie those starting with 'ckanext.data_depositario.gmap')
    '''
    namespace = 'ckanext.data_depositario.gmap.'

    gmap_configs = dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
            if k.startswith(namespace)])

    if not gmap_configs.get('api_key'):
        log.critical('''Please specify a ckanext.data_depositario.gmap.api_key
                     in your config for the Google Maps layer''')

    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
def get_tile_layer_config():
    '''
        Returns a dict with all configuration options related to the common
        base map (ie those starting with 'ckanext.basemaps.layers')
    '''

    namespace = 'ckanext.basemaps.laylers.'
    conf_dict = dict([(k.replace(namespace, ''), v) for k, v in config.iteritems() if k.startswith(namespace)])
    if conf_dict:
        arr_name = conf_dict['names']. split(',')
        arr_url = conf_dict['urls']. split(',')
        arr_attribution = conf_dict['attributions']. split(',')
        json_dict = {}
        for x in xrange(0,len(arr_name)):
            tmp_dict = {}
            tmp_dict['url'] = arr_url[x]
            try:
              tmp_dict['attribution'] = arr_attribution[x]
            except IndexError:
              tmp_dict['attribution'] = ""

            json_dict[arr_name[x]] = tmp_dict
        return json_dict
    else:
        return conf_dict
示例#6
0
def get_mapview_config():
    '''
    Extracts and returns map view configuration of the reclineview extension.
    '''
    namespace = 'ckanext.spatial.common_map.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#7
0
def get_gmap_config():
    '''
        Returns a dict with all configuration options related to the
        Google Maps API (ie those starting with 'ckanext.taijiang.gmap')
    '''
    namespace = 'ckanext.taijiang.gmap.'

    gmap_configs = dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
            if k.startswith(namespace)])

    if not gmap_configs.get('api_key'):
        log.critical('''Please specify a ckanext.taijiang.gmap.api_key
                     in your config for the Google Maps layer''')

    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#8
0
def get_shapefile_viewer_config():
    '''
        Returns a dict with all configuration options related to the
        Shapefile viewer (ie those starting with 'ckanext.geoview.shp_viewer.')
    '''
    namespace = 'ckanext.geoview.shp_viewer.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#9
0
def get_odn_config():
    '''
        Returns a dict with all configuration options related to ODN,
        that is those starting with 'odn.')
    '''
    namespace = 'odn.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#10
0
def get_ofi_config():
    '''
    Returns a dict with all configuration options related to the
    OFI (ie those starting with 'bcgov.ofi.')
    '''
    namespace = 'bcgov.ofi.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#11
0
def get_openlayers_viewer_config():
    '''
        Returns a dict with all configuration options related to the
        OpenLayers viewer (ie those starting with 'ckanext.geoview.ol_viewer.')
    '''
    namespace = 'ckanext.geoview.ol_viewer.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#12
0
 def get_tolomeo_config(self):
     '''
         Returns a dict with all configuration options related to the
         Tolomeo viewer (ie those starting with 'ckanext.tolomeo.')
     '''
     namespace = 'tolomeo.'
     return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                  if k.startswith(namespace)])
示例#13
0
def get_ofi_config():
    '''
    Returns a dict with all configuration options related to the
    OFI (ie those starting with 'bcgov.ofi.')
    '''
    namespace = 'bcgov.ofi.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#14
0
def get_openlayers_viewer_config():
    '''
        Returns a dict with all configuration options related to the
        OpenLayers viewer (ie those starting with 'ckanext.geoview.ol_viewer.')
    '''
    namespace = 'ckanext.geoview.ol_viewer.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#15
0
def get_common_map_config():
    '''
        Returns a dict with all configuration options related to the common
        base map (ie those starting with 'ckanext.spatial.common_map.')
    '''
    namespace = 'ckanext.spatial.common_map.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#16
0
def get_odn_config():
    '''
        Returns a dict with all configuration options related to ODN,
        that is those starting with 'odn.')
    '''
    namespace = 'odn.'
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])
示例#17
0
def load_sources_hook(config, *args, **kwargs):
    """Hook to load all the known sources and stuff them in config.  Run once,
    on server startup.

    Frontpage hooks are also passed the `config` hash, as it's not available
    during setup.
    """
    # Extract source definitions from config and store as source_name => config
    update_config = defaultdict(dict)
    key_rx = re.compile(
        '(?x) ^ spline-frontpage [.] sources [.] (\w+) (?: [.] (\w+) )? $')
    for key, val in config.iteritems():
        # Match against spline-frontpage.source.(source).(key)
        match = key_rx.match(key)
        if not match:
            continue

        source_name, subkey = match.groups()
        if not subkey:
            # This is the type declaration; use a special key
            subkey = '__type__'

        update_config[source_name][subkey] = val

    # Figure out the global limit and expiration time, with reasonable
    # defaults.  Make sure they're integers.
    global_limit = int(config.get('spline-frontpage.limit', 10))
    # max_age is optional and can be None
    try:
        global_max_age = int(config['spline-frontpage.max_age'])
    except KeyError:
        global_max_age = None

    config['spline-frontpage.limit'] = global_limit
    config['spline-frontpage.max_age'] = global_max_age

    # Ask plugins to turn configuration into source objects
    sources = []
    for source, source_config in update_config.iteritems():
        hook_name = 'frontpage_updates_' + source_config['__type__']
        del source_config['__type__']  # don't feed this to constructor!

        # Default to global limit and max age.  Source takes care of making
        # integers and whatnot
        source_config.setdefault('limit', global_limit)
        source_config.setdefault('max_age', global_max_age)

        # Hooks return a list of sources; combine with running list
        sources += run_hooks(hook_name, config=config, **source_config)

    # Save the list of sources, and done
    config['spline-frontpage.sources'] = sources
示例#18
0
def load_sources_hook(config, *args, **kwargs):
    """Hook to load all the known sources and stuff them in config.  Run once,
    on server startup.

    Frontpage hooks are also passed the `config` hash, as it's not available
    during setup.
    """
    # Extract source definitions from config and store as source_name => config
    update_config = defaultdict(dict)
    key_rx = re.compile(
        '(?x) ^ spline-frontpage [.] sources [.] (\w+) (?: [.] (\w+) )? $')
    for key, val in config.iteritems():
        # Match against spline-frontpage.source.(source).(key)
        match = key_rx.match(key)
        if not match:
            continue

        source_name, subkey = match.groups()
        if not subkey:
            # This is the type declaration; use a special key
            subkey = '__type__'

        update_config[source_name][subkey] = val

    # Figure out the global limit and expiration time, with reasonable
    # defaults.  Make sure they're integers.
    global_limit = int(config.get('spline-frontpage.limit', 10))
    # max_age is optional and can be None
    try:
        global_max_age = int(config['spline-frontpage.max_age'])
    except KeyError:
        global_max_age = None

    config['spline-frontpage.limit'] = global_limit
    config['spline-frontpage.max_age'] = global_max_age

    # Ask plugins to turn configuration into source objects
    sources = []
    for source, source_config in update_config.iteritems():
        hook_name = 'frontpage_updates_' + source_config['__type__']
        del source_config['__type__']  # don't feed this to constructor!

        # Default to global limit and max age.  Source takes care of making
        # integers and whatnot
        source_config.setdefault('limit', global_limit)
        source_config.setdefault('max_age', global_max_age)

        # Hooks return a list of sources; combine with running list
        sources += run_hooks(hook_name, config=config, **source_config)

    # Save the list of sources, and done
    config['spline-frontpage.sources'] = sources
示例#19
0
def get_namespace_config(namespace):
    return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
                 if k.startswith(namespace)])