Source

django-envconf / environment / environment_settings.py

Full commit
class SettingsBase(object):
    def __init__(self):
        self.overwrite = False
        self.load_settings()

    def load_settings(self):
        for setting in self.get_current_settings():
            self.set_setting(setting['attribute_name'],
                             self.get_setting(setting['class'], setting['attribute_name']),
                             setting['should_overwrite'])

    def get_current_settings(self):
        current_settings = []
        for cls in self.__class__.__mro__:
            for setting in dir(cls):
                if not setting.startswith('__') and setting != 'overwrite' and not callable(self.__getattribute__(setting)):
                    current_settings.append(
                                                {
                                                 'attribute_name': setting,
                                                 'should_overwrite': cls.overwrite,
                                                 'class': cls
                                                 }
                                            )
        return current_settings

    def set_setting(self, name, value, should_overwrite):
        print name

        if (not hasattr(self, name) or should_overwrite):
            self.__setattr__(name, value)

    def get_setting(self, cls, name):
        return cls.__getattribute__(cls.__new__(cls), name)

class A(SettingsBase):
    FOO = 5

    overwrite = True

    def __init__(self):
        super(A, self).__init__()

class B(A):
    FOO = 50

    overwrite = False

    def __init__(self):
        super(B, self).__init__()