Пример #1
0
 def get_config_value(key, default=''):
     if model.meta.engine.has_table('system_info'):
         value = model.get_system_info(key)
     else:
         value = None
     config_value = config.get(key)
     # sort encodeings if needed
     if isinstance(config_value, str):
         try:
             config_value = config_value.decode('utf-8')
         except UnicodeDecodeError:
             config_value = config_value.decode('latin-1')
     # we want to store the config the first time we get here so we can
     # reset them if needed
     if key not in _CONFIG_CACHE:
         _CONFIG_CACHE[key] = config_value
     if value is not None:
         log.debug('config `%s` set to `%s` from db' % (key, value))
     else:
         value = _CONFIG_CACHE[key]
         if value:
             log.debug('config `%s` set to `%s` from config' % (key, value))
         else:
             value = default
     setattr(app_globals, get_globals_key(key), value)
     # update the config
     config[key] = value
     return value
Пример #2
0
    def get_config_value(key, default=''):
        if model.meta.engine.has_table('system_info'):
            value = model.get_system_info(key)
        else:
            value = None
        config_value = config.get(key)
        # sort encodeings if needed
        if isinstance(config_value, str):
            try:
                config_value = config_value.decode('utf-8')
            except UnicodeDecodeError:
                config_value = config_value.decode('latin-1')
        # we want to store the config the first time we get here so we can
        # reset them if needed
        if key not in _CONFIG_CACHE:
            _CONFIG_CACHE[key] = config_value
        if value is not None:
            log.debug('config `%s` set to `%s` from db' % (key, value))
        else:
            value = _CONFIG_CACHE[key]
            if value:
                log.debug('config `%s` set to `%s` from config' % (key, value))
            else:
                value = default

        set_app_global(key, value)

        # update the config
        config[key] = value

        return value
Пример #3
0
    def get_config_value(key: str, default: str = ''):
        # type_ignore_reason: engine theoretically uninitialized
        if model.meta.engine.has_table('system_info'):  # type: ignore
            value = model.get_system_info(key)
        else:
            value = None
        config_value = config.get(key)
        # sort encodeings if needed

        # we want to store the config the first time we get here so we can
        # reset them if needed
        if key not in _CONFIG_CACHE:
            _CONFIG_CACHE[key] = config_value
        if value is not None:
            log.debug('config `%s` set to `%s` from db' % (key, value))
        else:
            value = _CONFIG_CACHE[key]
            if value:
                log.debug('config `%s` set to `%s` from config' % (key, value))
            else:
                value = default

        set_app_global(key, value)

        # update the config
        config[key] = value

        return value
Пример #4
0
def external_license_label(items):
    mapped_licenses = model.get_system_info('mapped_licenses')
    if mapped_licenses:
        mapped_licenses = json.loads(mapped_licenses)
        for item in items:
            if item['name'] in mapped_licenses:
                item['display_name'] = mapped_licenses[item['name']]
    return items
Пример #5
0
 def _check_uptodate(self):
     ''' check the config is uptodate needed when several instances are
     running '''
     value = model.get_system_info('ckan.config_update')
     if self._config_update != value:
         if self._mutex.acquire(False):
             reset()
             self._config_update = value
             self._mutex.release()
Пример #6
0
 def _check_uptodate(self):
     ''' check the config is uptodate needed when several instances are
     running '''
     value = model.get_system_info('ckan.config_update')
     if self._config_update != value:
         if self._mutex.acquire(False):
             reset()
             self._config_update = value
             self._mutex.release()
Пример #7
0
    def license_mapping(self):
        try:
            tk.check_access('sysadmin', {'user': g.user, model: model})
        except tk.NotAuthorized:
            return tk.abort(403)
        if request.method == 'POST':
            license_id = request.POST.get('license_id')
            license_label = request.POST.get('license_label')

            if license_id and license_label:
                mapped_licenses = model.get_system_info('mapped_licenses')
                if mapped_licenses:
                    mapped_licenses = json.loads(mapped_licenses)
                    mapped_licenses[license_id] = license_label
                    mapped_licenses = json.dumps(mapped_licenses)
                    model.set_system_info(
                        'mapped_licenses', str(mapped_licenses)
                    )
                else:
                    new_licenses = {license_id: license_label}
                    new_licenses = json.dumps(new_licenses)
                    model.set_system_info(
                        'mapped_licenses', str(new_licenses)
                    )

            return tk.redirect_to('license_mapping')

        query = model.Session.query(model.Package.license_id)
        defined_licenses = []
        undefined_licenses = set()

        licenses_file = config.get('licenses_group_url', '')
        licenses_file = licenses_file.replace('file://', '')

        if licenses_file:
            with open(licenses_file) as f:
                licenses_info = json.load(f)

            for i in licenses_info:
                defined_licenses.append(i['id'])

            for lic in query:
                if lic[0] not in defined_licenses:
                    undefined_licenses.add(lic[0])

        extra_vars = {
            'undefined': undefined_licenses
        }
        return tk.render('admin/license_mapping.html', extra_vars)
Пример #8
0
def package_links_settings_show(context, data_dict):
    '''
    :returns: list of dictionaries representing the setting for each package_links item. Returns default if nothing is in db.
    :rtype: list of dict
    '''

    package_links_settings = []
    setting_value_json = model.get_system_info(
        'hdx.package_links.config', config.get('hdx.package_links.config'))
    if setting_value_json:
        try:
            package_links_settings = json.loads(setting_value_json)
        except TypeError as e:
            log.warn(
                'The "hdx.package_links.config" setting is not a proper json string'
            )

    return package_links_settings
Пример #9
0
 def get_config_value(key, default=''):
     if model.meta.engine.has_table('system_info'):
         value = model.get_system_info(key)
     else:
         value = None
     # we want to store the config the first time we get here so we can
     # reset them if needed
     config_value = config.get(key)
     if key not in _CONFIG_CACHE:
         _CONFIG_CACHE[key] = config_value
     if value is not None:
         log.debug('config `%s` set to `%s` from db' % (key, value))
     else:
         value = _CONFIG_CACHE[key]
         if value:
             log.debug('config `%s` set to `%s` from config' % (key, value))
         else:
             value = default
     setattr(app_globals, get_globals_key(key), value)
     # update the config
     config[key] = value
     return value
Пример #10
0
 def get_config_value(key, default=''):
     if model.meta.engine.has_table('system_info'):
         value = model.get_system_info(key)
     else:
         value = None
     # we want to store the config the first time we get here so we can
     # reset them if needed
     config_value = config.get(key)
     if key not in _CONFIG_CACHE:
         _CONFIG_CACHE[key] = config_value
     if value is not None:
         log.debug('config `%s` set to `%s` from db' % (key, value))
     else:
         value = _CONFIG_CACHE[key]
         if value:
             log.debug('config `%s` set to `%s` from config' % (key, value))
         else:
             value = default
     setattr(app_globals, get_globals_key(key), value)
     # update the config
     config[key] = value
     return value
Пример #11
0
    def get_config_value(key: str, default: str = ''):
        value = model.get_system_info(key)
        config_value = config.get(key)

        # we want to store the config the first time we get here so we can
        # reset them if needed
        if key not in _CONFIG_CACHE:
            _CONFIG_CACHE[key] = config_value
        if value is not None:
            log.debug('config `%s` set to `%s` from db' % (key, value))
        else:
            value = _CONFIG_CACHE[key]
            if value:
                log.debug('config `%s` set to `%s` from config' % (key, value))
            else:
                value = default

        set_app_global(key, value)

        # update the config
        config[key] = value

        return value
Пример #12
0
def package_links_by_id_list(context, data_dict):
    '''
    :returns: list of dictionaries representing the settings for a package_id
    :rtype: list of dict
    '''

    package_links_settings = []
    if data_dict.get('id'):
        setting_value_json = model.get_system_info(
            'hdx.package_links.config', config.get('hdx.package_links.config'))
        if setting_value_json:
            try:
                _all_pls = json.loads(setting_value_json)
                for item in _all_pls:
                    if item.get('package_list'):
                        pkg_list = item.get('package_list').split(',')
                        if pkg_list and data_dict.get('id') in pkg_list:
                            package_links_settings.append(item)
            except TypeError as e:
                log.warn(
                    'The "hdx.package_links.config" setting is not a proper json string'
                )
    return package_links_settings
Пример #13
0
def hdx_carousel_settings_show(context, data_dict):
    '''
    :returns: list of dictionaries representing the setting for each carousel item. Returns default if nothing is in db.
    :rtype: list of dict
    '''
    from ckanext.hdx_theme.helpers.initial_carousel_settings import INITIAL_CAROUSEL_DATA

    carousel_settings = []
    setting_value_json = model.get_system_info(
        'hdx.carousel.config', config.get('hdx.carousel.config'))
    if setting_value_json:
        try:
            carousel_settings = json.loads(setting_value_json)
        except TypeError as e:
            log.warn(
                'The "hdx.carousel.config" setting is not a proper json string'
            )

    if not carousel_settings and not context.get('not_initial'):
        carousel_settings = INITIAL_CAROUSEL_DATA
        for i, item in enumerate(carousel_settings):
            item['order'] = i + 1

    return carousel_settings
Пример #14
0
def _get_config_value(key, default=''):
  if cmodel.meta.engine.has_table('system_info'):
      return cmodel.get_system_info(key)