1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Stopped iterating on INSTALLED_APPS.

Used the app cache's get_app_configs() method instead.
This commit is contained in:
Aymeric Augustin
2013-12-19 15:57:23 +01:00
parent d4733b6df0
commit 65cd74be8e
18 changed files with 116 additions and 82 deletions

View File

@@ -6,6 +6,7 @@ from importlib import import_module
from inspect import getargspec, getcallargs
from django.conf import settings
from django.core.apps import app_cache
from django.template.context import (BaseContext, Context, RequestContext, # NOQA: imported for backwards compatibility
ContextPopException)
from django.utils.itercompat import is_iterable
@@ -1302,9 +1303,12 @@ def get_templatetags_modules():
# Populate list once per process. Mutate the local list first, and
# then assign it to the global name to ensure there are no cases where
# two threads try to populate it simultaneously.
for app_module in ['django'] + list(settings.INSTALLED_APPS):
templatetags_modules_candidates = ['django.templatetags']
templatetags_modules_candidates += ['%s.templatetags' % app_config.name
for app_config in app_cache.get_app_configs()]
for templatetag_module in templatetags_modules_candidates:
try:
templatetag_module = '%s.templatetags' % app_module
import_module(templatetag_module)
_templatetags_modules.append(templatetag_module)
except ImportError:

View File

@@ -3,12 +3,11 @@ Wrapper for loading templates from "templates" directories in INSTALLED_APPS
packages.
"""
from importlib import import_module
import os
import sys
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.apps import app_cache
from django.template.base import TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.utils._os import safe_join
@@ -18,12 +17,8 @@ from django.utils import six
if six.PY2:
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
app_template_dirs = []
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app)
except ImportError as e:
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates')
for app_config in app_cache.get_app_configs():
template_dir = os.path.join(app_config.path, 'templates')
if os.path.isdir(template_dir):
if six.PY2:
template_dir = template_dir.decode(fs_encoding)

View File

@@ -7,6 +7,7 @@ except ImportError:
resource_string = None
from django.conf import settings
from django.core.apps import app_cache
from django.template.base import TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.utils import six
@@ -23,12 +24,12 @@ class Loader(BaseLoader):
"""
if resource_string is not None:
pkg_name = 'templates/' + template_name
for app in settings.INSTALLED_APPS:
for app_config in app_cache.get_app_configs():
try:
resource = resource_string(app, pkg_name)
resource = resource_string(app_config.name, pkg_name)
except Exception:
continue
if six.PY2:
resource = resource.decode(settings.FILE_CHARSET)
return (resource, 'egg:%s:%s' % (app, pkg_name))
return (resource, 'egg:%s:%s' % (app_config.name, pkg_name))
raise TemplateDoesNotExist(template_name)