Python django.conf.settings._wrapped() Examples

The following are 20 code examples of django.conf.settings._wrapped(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .
Example #1
Source File: control.py    From esdc-ce with Apache License 2.0 6 votes vote down vote up
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 
Example #2
Source File: diffsettings.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #3
Source File: response.py    From Kiwi with GNU General Public License v2.0 6 votes vote down vote up
def render(self):
        try:
            with self.modify_settings:  # pylint: disable=not-context-manager
                return super().render()
        finally:
            # if this attribute is still set that means disabling settings override
            # failed which leads to navbar showing bogus menu items, see
            # https://github.com/kiwitcms/Kiwi/issues/991
            # => try to restore the original unmodified settings, see
            # django.test.utils.override_settings().disable()
            #
            # NOTE: the only way to reproduce this reliably ATM is by raising exception
            # in .disable() before restoring the original settings although I can see
            # the problem on tcms.kiwitcms.org after the last restart 1 week ago!
            # Maybe the switch to CBV and this response class made #991 harder to
            # reproduce. It was easier to reproduce in the past by triggering some kind
            # of exception in the FBV which used modify_settings() !!!
            if hasattr(self.modify_settings, 'wrapped'):
                settings._wrapped = self.modify_settings.wrapped  # pylint: disable=protected-access
                del self.modify_settings.wrapped 
Example #4
Source File: utils.py    From bioforum with MIT License 6 votes vote down vote up
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) 
Example #5
Source File: utils.py    From Hands-On-Application-Development-with-PyCharm with MIT License 6 votes vote down vote up
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) 
Example #6
Source File: utils.py    From python with Apache License 2.0 6 votes vote down vote up
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) 
Example #7
Source File: utils.py    From python2017 with MIT License 6 votes vote down vote up
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) 
Example #8
Source File: utils.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #9
Source File: diffsettings.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
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.keys()):
            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]))
        return '\n'.join(output) 
Example #10
Source File: utils.py    From openhgsenti with Apache License 2.0 6 votes vote down vote up
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) 
Example #11
Source File: utils.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def enable(self):
        override = UserSettingsHolder(settings._wrapped)
        for key, new_value in self.options.items():
            setattr(override, key, new_value)
        settings._wrapped = override
        for key, new_value in self.options.items():
            setting_changed.send(sender=settings._wrapped.__class__,
                                 setting=key, value=new_value) 
Example #12
Source File: django_settings.py    From pytest-services with MIT License 5 votes vote down vote up
def clean_django_settings():
    """Clean current django settings."""
    from django.conf import settings as django_settings

    del os.environ['DJANGO_SETTINGS_MODULE']
    django_settings._wrapped = None 
Example #13
Source File: utils.py    From python2017 with MIT License 5 votes vote down vote up
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) 
Example #14
Source File: utils.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
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) 
Example #15
Source File: utils.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def disable(self):
        settings._wrapped = 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) 
Example #16
Source File: utils.py    From python with Apache License 2.0 5 votes vote down vote up
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) 
Example #17
Source File: utils.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
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) 
Example #18
Source File: utils.py    From bioforum with MIT License 5 votes vote down vote up
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) 
Example #19
Source File: middleware.py    From nplusone with MIT License 5 votes vote down vote up
def load_config(self):
        self.notifiers = notifiers.init(vars(settings._wrapped))
        self.whitelist = [
            DjangoRule(**item)
            for item in getattr(settings, 'NPLUSONE_WHITELIST', [])
        ] 
Example #20
Source File: utils.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
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)