diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-29 20:43:10 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-29 20:43:10 +0100 |
| commit | 21f22f9544b0c6c4390bcd1acd98e6e5201ed83e (patch) | |
| tree | 7727998ee9711d3b40ab1299503d29863ecbe8e0 /django/apps | |
| parent | 82aadbb5d50cca5e4c42f3f5b7cb1707b818ab28 (diff) | |
Added Apps.clear_cache().
This avoid leaking implementation details to tests that swap models.
Diffstat (limited to 'django/apps')
| -rw-r--r-- | django/apps/registry.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/django/apps/registry.py b/django/apps/registry.py index 67cca2cfdf..a66e561566 100644 --- a/django/apps/registry.py +++ b/django/apps/registry.py @@ -84,7 +84,7 @@ class Apps(object): app_config = AppConfig.create(entry) self.app_configs[app_config.label] = app_config - self.get_models.cache_clear() + self.clear_cache() self._apps_loaded = True def populate_models(self): @@ -133,7 +133,7 @@ class Apps(object): del self._postponed - self.get_models.cache_clear() + self.clear_cache() self._models_loaded = True @property @@ -248,7 +248,7 @@ class Apps(object): "Conflicting '%s' models in application '%s': %s and %s." % (model_name, app_label, app_models[model_name], model)) app_models[model_name] = model - self.get_models.cache_clear() + self.clear_cache() def has_app(self, app_name): """ @@ -299,14 +299,14 @@ class Apps(object): (label, app_config) for label, app_config in self.app_configs.items() if app_config.name in available) - self.get_models.cache_clear() + self.clear_cache() def unset_available_apps(self): """ Cancels a previous call to set_available_apps(). """ self.app_configs = self.stored_app_configs.pop() - self.get_models.cache_clear() + self.clear_cache() def set_installed_apps(self, installed): """ @@ -327,7 +327,7 @@ class Apps(object): """ self.stored_app_configs.append((self.app_configs, self._apps_loaded, self._models_loaded)) self.app_configs = OrderedDict() - self.get_models.cache_clear() + self.clear_cache() self._apps_loaded = False self.populate_apps(installed) self._models_loaded = False @@ -338,7 +338,15 @@ class Apps(object): Cancels a previous call to set_installed_apps(). """ self.app_configs, self._apps_loaded, self._models_loaded = self.stored_app_configs.pop() - self.get_models.cache_clear() + self.clear_cache() + + def clear_cache(self): + """ + Clears all internal caches, for methods that alter the app registry. + + This is mostly used in tests. + """ + self.clear_cache() ### DEPRECATED METHODS GO BELOW THIS LINE ### @@ -353,7 +361,7 @@ class Apps(object): app_config = AppConfig.create(app_name) app_config.import_models(self.all_models[app_config.label]) self.app_configs[app_config.label] = app_config - self.get_models.cache_clear() + self.clear_cache() return app_config.models_module def app_cache_ready(self): |
