我们从Python开源项目中,提取了以下46个代码示例,用于说明如何使用django.conf.settings._wrapped()。
def handle(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) output = [] for key in sorted(user_settings): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) elif options['all']: output.append("### %s = %s" % (key, user_settings[key])) return '\n'.join(output)
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(): setting_changed.send(sender=settings._wrapped.__class__, setting=key, value=new_value, enter=True)
def handle(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, Settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default = options['default'] default_settings = module_to_dict(Settings(default) if default else global_settings) output = [] for key in sorted(user_settings): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) elif options['all']: output.append("### %s = %s" % (key, user_settings[key])) return '\n'.join(output)
def local_settings_update(self, changes): """Update local_settings.py with new content created according to the changes parameter. The changes parameter should be a list generated by check_modules()""" if not local_settings: raise SystemError('Missing local_settings.py!') logger.info('Creating new local_settings.py with following changes: %s', self._show_changes(changes)) target = inspect.getsourcefile(local_settings) data = self._local_settings_new(changes) backup = inspect.getsource(local_settings) logger.warn('Updating %s', target) self._save_file(target, data) try: reload_module(local_settings) except ImportError as e: logger.exception(e) logger.warn('Restoring %s from backup', target) self._save_file(target, backup) else: # Force reloading of django settings settings._wrapped = empty
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings, global_settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) default_settings = module_to_dict(global_settings) output = [] for key in sorted(user_settings): if key not in default_settings: output.append("%s = %s ###" % (key, user_settings[key])) elif user_settings[key] != default_settings[key]: output.append("%s = %s" % (key, user_settings[key])) elif options['all']: output.append("### %s = %s" % (key, user_settings[key])) return '\n'.join(output)
def disable(self): if 'INSTALLED_APPS' in self.options: apps.unset_installed_apps() settings._wrapped = self.wrapped del self.wrapped for key in self.options: new_value = getattr(settings, key, None) setting_changed.send(sender=settings._wrapped.__class__, setting=key, value=new_value, enter=False)
def handle_noargs(self, **options): # Inspired by Postfix's "postconf -n". from django.conf import settings # Because settings are imported lazily, we need to explicitly load them. settings._setup() user_settings = module_to_dict(settings._wrapped) opts = Options() pformat = "%-25s = %s" puts('') for section in opts.sections: puts(colored.green("[%s]" % section)) for key, kaio_value in opts.items(section): keycolor = colored.magenta(key) if key in user_settings: keycolor = colored.blue(key) default_value = opts.options[key].default_value value = kaio_value or default_value if sys.version_info[0] < 3: value = unicode(value).encode('utf8') else: value = str(value) try: puts(pformat % (keycolor, value)) except Exception as e: raise e puts('')
def disable(self): from django.conf import settings settings._wrapped = self.wrapped
def enable(self): override = UserSettingsHolder(settings._wrapped) for key, new_value in self.options.items(): setattr(override, key, new_value) settings._wrapped = override
def disable(self): settings._wrapped = self.wrapped
def disable(self): self.wrapped = self._wrapped for update_dict in self.update_dicts: update_dict['pointer'].clear() update_dict['pointer'].update(update_dict['copy']) super(modify_dict_settings, self).disable()