Python django.conf.settings._wrapped() Examples

The following are 20 code examples for showing how to use django.conf.settings._wrapped(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
Project: GTDWeb   Author: lanbing510   File: utils.py    License: 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 2
Project: GTDWeb   Author: lanbing510   File: diffsettings.py    License: 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
Project: bioforum   Author: reBiocoder   File: utils.py    License: 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 4
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: utils.py    License: 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
Project: python   Author: Yeah-Kun   File: utils.py    License: 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 6
Project: luscan-devel   Author: blackye   File: diffsettings.py    License: 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 7
Project: openhgsenti   Author: drexly   File: utils.py    License: 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 8
Project: python2017   Author: bpgc-cte   File: utils.py    License: 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 9
Project: Kiwi   Author: kiwitcms   File: response.py    License: 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 10
Project: esdc-ce   Author: erigones   File: control.py    License: 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 11
Project: GTDWeb   Author: lanbing510   File: utils.py    License: 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) 
Example 12
Project: nplusone   Author: jmcarp   File: middleware.py    License: 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 13
Project: bioforum   Author: reBiocoder   File: utils.py    License: 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
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: utils.py    License: 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 15
Project: python   Author: Yeah-Kun   File: utils.py    License: 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 16
Project: luscan-devel   Author: blackye   File: utils.py    License: 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 17
Project: luscan-devel   Author: blackye   File: utils.py    License: 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 18
Project: openhgsenti   Author: drexly   File: utils.py    License: 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 19
Project: python2017   Author: bpgc-cte   File: utils.py    License: 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 20
Project: pytest-services   Author: pytest-dev   File: django_settings.py    License: 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