def update_analytics_code_by_organization(organization_id, force_online=False): """ Analytic codes are saved in the app_globals in format of organization_id: analytic code dict. if it is the first time for the organization to get the analytic code than it retrieves the analytic code from the DB, otherwise it uses the old value from the app_global dictionary. :param organization_id: :param force_online: if set to true, get analytic code from DB and not using cache. :return: None """ if hasattr(g.app_globals, GLOBAL_KEY_NAME): log.info("Google Analytics: get {} object from APP_GLOBALS".format( GLOBAL_KEY_NAME)) analytics_obg = getattr(g.app_globals, GLOBAL_KEY_NAME) analytics_obg = copy.deepcopy(analytics_obg) # updating current organization analytic code if analytics_obg.get('curr_org_id') != organization_id: if organization_id != '': # checks if analytic code for this object was retrieved if force_online or organization_id not in analytics_obg.keys(): analytics_obg[organization_id] = get_online_analytics_code( organization_id) # updating current organization_id analytics_obg['curr_org_id'] = organization_id analytics_obg['curr_analytics_code'] = analytics_obg[ organization_id] else: analytics_obg['curr_org_id'] = '' analytics_obg['curr_analytics_code'] = '' g.set_app_global(GLOBAL_KEY_NAME, analytics_obg) # init app globals with analytics object for the first time else: log.info("Google Analytics: init {} object".format(GLOBAL_KEY_NAME)) online_ga_code = '' if organization_id != '': online_ga_code = get_online_analytics_code(organization_id) analytics_obg = { 'curr_org_id': organization_id, 'curr_analytics_code': online_ga_code, organization_id: online_ga_code } g.set_app_global(GLOBAL_KEY_NAME, analytics_obg)
def update_config(self, config_): set_app_global('ckan.ozwillo_url', pconfig.get('%s.ozwillo_url' % __name__)) set_app_global('ckan.ozwillo_portal_url', pconfig.get('%s.ozwillo_portal_url' % __name__)) set_app_global('ckan.ozwillo_ckan_app_id', pconfig.get('%s.ozwillo_ckan_app_id' % __name__)) set_app_global('ckan.localized_links', footer_links()) toolkit.add_template_directory(config_, 'templates') toolkit.add_public_directory(config_, 'public') toolkit.add_resource('fanstatic', 'theme')
def update_config(self, config_): set_app_global('ckan.ozwillo_url', pconfig.get('%s.ozwillo_url' % __name__)) set_app_global('ckan.ozwillo_portal_url', pconfig.get('%s.ozwillo_portal_url' % __name__)) set_app_global('ckan.ozwillo_ckan_app_id', pconfig.get('%s.ozwillo_ckan_app_id' % __name__)) set_app_global('ckan.localized_links', footer_links()) toolkit.add_template_directory(config_, 'templates') toolkit.add_public_directory(config_, 'public') toolkit.add_resource('fanstatic', 'theme')
def config_option_update(context, data_dict): ''' .. versionadded:: 2.4 Allows to modify some CKAN runtime-editable config options It takes arbitrary key, value pairs and checks the keys against the config options update schema. If some of the provided keys are not present in the schema a :py:class:`~ckan.plugins.logic.ValidationError` is raised. The values are then validated against the schema, and if validation is passed, for each key, value config option: * It is stored on the ``system_info`` database table * The Pylons ``config`` object is updated. * The ``app_globals`` (``g``) object is updated (this only happens for options explicitly defined in the ``app_globals`` module. The following lists a ``key`` parameter, but this should be replaced by whichever config options want to be updated, eg:: get_action('config_option_update)({}, { 'ckan.site_title': 'My Open Data site', 'ckan.homepage_layout': 2, }) :param key: a configuration option key (eg ``ckan.site_title``). It must be present on the ``update_configuration_schema`` :type key: string :returns: a dictionary with the options set :rtype: dictionary .. note:: You can see all available runtime-editable configuration options calling the :py:func:`~ckan.logic.action.get.config_option_list` action .. note:: Extensions can modify which configuration options are runtime-editable. For details, check :doc:`/extensions/remote-config-update`. .. warning:: You should only add config options that you are comfortable they can be edited during runtime, such as ones you've added in your own extension, or have reviewed the use of in core CKAN. ''' model = context['model'] _check_access('config_option_update', context, data_dict) schema = schema_.update_configuration_schema() available_options = schema.keys() provided_options = data_dict.keys() unsupported_options = set(provided_options) - set(available_options) if unsupported_options: msg = 'Configuration option(s) \'{0}\' can not be updated'.format( ' '.join(list(unsupported_options))) raise ValidationError(msg, error_summary={'message': msg}) data, errors = _validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) for key, value in data.iteritems(): # Save value in database model.set_system_info(key, value) # Update CKAN's `config` object config[key] = value # Only add it to the app_globals (`g`) object if explicitly defined # there globals_keys = app_globals.app_globals_from_config_details.keys() if key in globals_keys: app_globals.set_app_global(key, value) # Update the config update timestamp model.set_system_info('ckan.config_update', str(time.time())) log.info('Updated config options: {0}'.format(data)) return data
def config_option_update(context, data_dict): ''' .. versionadded:: 2.4 Allows to modify some CKAN runtime-editable config options It takes arbitrary key, value pairs and checks the keys against the config options update schema. If some of the provided keys are not present in the schema a :py:class:`~ckan.plugins.logic.ValidationError` is raised. The values are then validated against the schema, and if validation is passed, for each key, value config option: * It is stored on the ``system_info`` database table * The Pylons ``config`` object is updated. * The ``app_globals`` (``g``) object is updated (this only happens for options explicitly defined in the ``app_globals`` module. The following lists a ``key`` parameter, but this should be replaced by whichever config options want to be updated, eg:: get_action('config_option_update)({}, { 'ckan.site_title': 'My Open Data site', 'ckan.homepage_layout': 2, }) :param key: a configuration option key (eg ``ckan.site_title``). It must be present on the ``update_configuration_schema`` :type key: string :returns: a dictionary with the options set :rtype: dictionary .. note:: You can see all available runtime-editable configuration options calling the :py:func:`~ckan.logic.action.get.config_option_list` action .. note:: Extensions can modify which configuration options are runtime-editable. For details, check :doc:`/extensions/remote-config-update`. .. warning:: You should only add config options that you are comfortable they can be edited during runtime, such as ones you've added in your own extension, or have reviewed the use of in core CKAN. ''' model = context['model'] _check_access('config_option_update', context, data_dict) schema = schema_.update_configuration_schema() available_options = schema.keys() provided_options = data_dict.keys() unsupported_options = set(provided_options) - set(available_options) if unsupported_options: msg = 'Configuration option(s) \'{0}\' can not be updated'.format( ' '.join(list(unsupported_options))) raise ValidationError(msg, error_summary={'message': msg}) data, errors = _validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) for key, value in data.iteritems(): # Save value in database model.set_system_info(key, value) # Update the pylons `config` object config[key] = value # Only add it to the app_globals (`g`) object if explicitly defined # there globals_keys = app_globals.app_globals_from_config_details.keys() if key in globals_keys: app_globals.set_app_global(key, value) # Update the config update timestamp model.set_system_info('ckan.config_update', str(time.time())) log.info('Updated config options: {0}'.format(data)) return data