summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-19 15:57:23 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-22 11:39:18 +0100
commit65cd74be8e99d06c7861edc5050e34d6444e4d56 (patch)
tree72431d2a70af3d235543781fadce8e647c746959 /django/utils
parentd4733b6df07b1f8a869eed8eac86869d1d14472c (diff)
Stopped iterating on INSTALLED_APPS.
Used the app cache's get_app_configs() method instead.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/autoreload.py9
-rw-r--r--django/utils/module_loading.py9
-rw-r--r--django/utils/translation/trans_real.py8
3 files changed, 10 insertions, 16 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 1913317822..05ffb12f74 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -37,9 +37,8 @@ import time
import traceback
from django.conf import settings
+from django.core.apps import app_cache
from django.core.signals import request_finished
-from django.utils._os import upath
-from importlib import import_module
try:
from django.utils.six.moves import _thread as thread
except ImportError:
@@ -91,10 +90,8 @@ def gen_filenames():
basedirs = [os.path.join(os.path.dirname(os.path.dirname(__file__)),
'conf', 'locale'),
'locale']
- for appname in reversed(settings.INSTALLED_APPS):
- app = import_module(appname)
- basedirs.append(os.path.join(os.path.dirname(upath(app.__file__)),
- 'locale'))
+ for app_config in reversed(list(app_cache.get_app_configs())):
+ basedirs.append(os.path.join(app_config.path, 'locale'))
basedirs.extend(settings.LOCALE_PATHS)
basedirs = [os.path.abspath(basedir) for basedir in basedirs
if os.path.isdir(basedir)]
diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py
index 0c6bad2a7b..8d95fc00a3 100644
--- a/django/utils/module_loading.py
+++ b/django/utils/module_loading.py
@@ -58,18 +58,17 @@ def autodiscover_modules(*args, **kwargs):
registry. This register_to object must have a _registry instance variable
to access it.
"""
- from django.conf import settings
+ from django.core.apps import app_cache
register_to = kwargs.get('register_to')
- for app in settings.INSTALLED_APPS:
- mod = import_module(app)
+ for app_config in app_cache.get_app_configs():
# Attempt to import the app's module.
try:
if register_to:
before_import_registry = copy.copy(register_to._registry)
for module_to_search in args:
- import_module('%s.%s' % (app, module_to_search))
+ import_module('%s.%s' % (app_config.name, module_to_search))
except:
# Reset the model registry to the state before the last import as
# this import will have to reoccur on the next request and this
@@ -81,7 +80,7 @@ def autodiscover_modules(*args, **kwargs):
# Decide whether to bubble up this error. If the app just
# doesn't have an admin module, we can ignore the error
# attempting to import it, otherwise we want it to bubble up.
- if module_has_submodule(mod, module_to_search):
+ if module_has_submodule(app_config.app_module, module_to_search):
raise
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index e547800b92..3ed6371966 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -7,10 +7,10 @@ import os
import re
import sys
import gettext as gettext_module
-from importlib import import_module
from threading import local
import warnings
+from django.core.apps import app_cache
from django.dispatch import receiver
from django.test.signals import setting_changed
from django.utils.encoding import force_str, force_text
@@ -179,10 +179,8 @@ def translation(language):
res.merge(t)
return res
- for appname in reversed(settings.INSTALLED_APPS):
- app = import_module(appname)
- apppath = os.path.join(os.path.dirname(upath(app.__file__)), 'locale')
-
+ for app_config in reversed(list(app_cache.get_app_configs())):
+ apppath = os.path.join(app_config.path, 'locale')
if os.path.isdir(apppath):
res = _merge(apppath)