diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-13 20:22:21 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-17 10:17:44 +0100 |
| commit | da36d03fe69c35e2f289590c8c44c4c0d1281f24 (patch) | |
| tree | 14f804f4a64a1bd7624694b0e2fa96a3348ab33a | |
| parent | a4cb1400046f29f933b388ad6390f517e1f80c7a (diff) | |
Added get_app_configs() to iterate on app_config instances.
Refactored get_apps() to rely on that method.
This commit is fully backwards-compatible.
| -rw-r--r-- | django/apps/cache.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/django/apps/cache.py b/django/apps/cache.py index 893b1af2b4..034971c624 100644 --- a/django/apps/cache.py +++ b/django/apps/cache.py @@ -153,6 +153,21 @@ class BaseAppCache(object): """ return self.loaded + def get_app_configs(self, only_installed=True): + """ + Return an iterable of application configurations. + + If only_installed is True (default), only applications explicitly + listed in INSTALLED_APPS are considered. + """ + self._populate() + for app_config in self.app_configs.values(): + if only_installed and not app_config.installed: + continue + if self.available_apps is not None and app_config.label not in self.available_apps: + continue + yield app_config + def get_app_config(self, app_label, only_installed=True): """ Returns the application configuration for the given app_label. @@ -177,15 +192,7 @@ class BaseAppCache(object): """ Returns a list of all installed modules that contain models. """ - self._populate() - - # app_configs is an OrderedDict, which ensures that the returned list - # is always in the same order (with new apps added at the end). This - # avoids unstable ordering on the admin app list page, for example. - apps = [app for app in self.app_configs.items() if app[1].installed] - if self.available_apps is not None: - apps = [app for app in apps if app[0] in self.available_apps] - return [app[1].models_module for app in apps] + return [app_config.models_module for app_config in self.get_app_configs()] def _get_app_package(self, app): return '.'.join(app.__name__.split('.')[:-1]) |
