Beispiel #1
0
def set_global(key, value):
    ''' helper function for getting value from database or config file '''
    model.set_system_info(key, value)
    setattr(app_globals, get_globals_key(key), value)
    model.set_system_info('ckan.config_update', str(time.time()))
    # update the config
    config[key] = value
    log.info('config `%s` set to `%s`' % (key, value))
Beispiel #2
0
def set_global(key, value):
    ''' helper function for getting value from database or config file '''
    model.set_system_info(key, value)
    setattr(app_globals, get_globals_key(key), value)
    model.set_system_info('ckan.config_update', str(time.time()))
    # update the config
    config[key] = value
    log.info('config `%s` set to `%s`' % (key, value))
    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)
Beispiel #4
0
def hdx_carousel_settings_update(context, data_dict):
    '''

    :param 'hdx.carousel.config': a list with the carousel settings
    :type 'hdx.carousel.config': list
    :return: The JSON string that is the value of the new 'hdx.carousel.config'
    :rtype: str
    '''

    logic.check_access('hdx_carousel_update', context, {})

    settings = data_dict.get('hdx.carousel.config')
    settings_json = json.dumps(settings)
    model.set_system_info('hdx.carousel.config', settings_json)
    return settings_json