| 113 | # Import installed apps settings into this namespace |
| 114 | # The downside of this method is that apps with the same name but in |
| 115 | # different namespaces will clobber one another |
| 116 | for app_name in self.INSTALLED_APPS: |
| 117 | last_part = app_name.split('.')[-1] |
| 118 | try: |
| 119 | # import the application's settings.py |
| 120 | # this will be the defaults |
| 121 | mod = __import__('%s.settings' % app_name, |
| 122 | globals(), |
| 123 | locals(), |
| 124 | ['*']) |
| 125 | except ImportError: |
| 126 | # If it doesn't exist, move on |
| 127 | pass |
| 128 | else: |
| 129 | # Warn in case we're stomping on configuration |
| 130 | if hasattr(self, last_part): |
| 131 | warnings.warn( |
| 132 | ('While trying to import application settings for %s it ' |
| 133 | 'appears another installed application is named %s. ' |
| 134 | 'This will result in %s stomping on the other ' |
| 135 | "application's configuration. You should rename one or " |
| 136 | 'the other.') % (app_name, last_part, app_name), |
| 137 | RuntimeWarning) |
| 138 | |
| 139 | # Populate a UserSettingsHolder with the uppercase attributes |
| 140 | # It will be our set of defaults for local_app_settings |
| 141 | app_settings = UserSettingsHolder(object()) |
| 142 | for attr in dir(mod): |
| 143 | if attr == attr.upper(): |
| 144 | attr_value = getattr(mod, attr) |
| 145 | setattr(app_settings, attr, attr_value) |
| 146 | |
| 147 | # On a per-site/project basis, the application configuration |
| 148 | # can be overridden, so we must get local overrides |
| 149 | local_app_settings = UserSettingsHolder(app_settings) |
| 150 | try: |
| 151 | mod = __import__('app_settings.%s' % last_part, |
| 152 | globals(), |
| 153 | locals(), |
| 154 | ['*']) |
| 155 | except ImportError: |
| 156 | # If there are no overrides, move on |
| 157 | # The application defaults will still be used |
| 158 | pass |
| 159 | else: |
| 160 | for attr in dir(mod): |
| 161 | if attr == attr.upper(): |
| 162 | attr_value = getattr(mod, attr) |
| 163 | setattr(app_settings, attr, attr_value) |
| 164 | |
| 165 | # set the net application settings as an attribute of self |
| 166 | setattr(self, last_part, local_app_settings) |
| 167 | |