def enable(self): # Keep this code at the beginning to leave the settings unchanged # in case it raises an exception because INSTALLED_APPS is invalid. if "INSTALLED_APPS" in self.options: try: apps.set_installed_apps(self.options["INSTALLED_APPS"]) except Exception: apps.unset_installed_apps() raise override = UserSettingsHolder(settings._wrapped) for key, new_value in self.options.items(): setattr(override, key, new_value) self.wrapped = settings._wrapped settings._wrapped = override for key, new_value in self.options.items(): try: setting_changed.send( sender=settings._wrapped.__class__, setting=key, value=new_value, enter=True, ) except Exception as exc: self.enable_exception = exc self.disable()
def handle_setting_change(key, for_delete=False): # When a setting changes or is deleted, remove its value from cache along # with any other settings that depend on it. setting_keys = [key] for dependent_key in settings_registry.get_dependent_settings(key): # Note: Doesn't handle multiple levels of dependencies! setting_keys.append(dependent_key) # NOTE: This block is probably duplicated. cache_keys = set([Setting.get_cache_key(k) for k in setting_keys]) cache.delete_many(cache_keys) # Send setting_changed signal with new value for each setting. for setting_key in setting_keys: setting_changed.send(sender=Setting, setting=setting_key, value=getattr(settings, setting_key, None), enter=not bool(for_delete))
def __getattr__(self, name): if name in self.defaults.keys(): from django.conf import settings name_with_prefix = (self.prefix + '_' + name).upper() raw_value = getattr(settings, name_with_prefix, self.defaults[name]) value = self._set_attr(name_with_prefix, raw_value) setattr(settings, name_with_prefix, raw_value) setting_changed.send(self.__class__, setting=name_with_prefix, value=raw_value, enter=True) return value raise AttributeError(name)
def handle_setting_change(key, for_delete=False): # When a setting changes or is deleted, remove its value from cache along # with any other settings that depend on it. setting_keys = [key] for dependent_key in settings_registry.get_dependent_settings(key): # Note: Doesn't handle multiple levels of dependencies! setting_keys.append(dependent_key) # NOTE: This block is probably duplicated. cache_keys = {Setting.get_cache_key(k) for k in setting_keys} cache.delete_many(cache_keys) # if we have changed a setting, we want to avoid mucking with the in-memory cache entirely settings._awx_conf_memoizedcache.clear() # Send setting_changed signal with new value for each setting. for setting_key in setting_keys: setting_changed.send(sender=Setting, setting=setting_key, value=getattr(settings, setting_key, None), enter=not bool(for_delete))