diff --git a/app_namespace/demo/application_appconfig/__init__.py b/app_namespace/demo/application_appconfig/__init__.py
new file mode 100644
index 0000000..a3fc177
--- /dev/null
+++ b/app_namespace/demo/application_appconfig/__init__.py
@@ -0,0 +1,3 @@
+"""
+demo.application_extension
+"""
diff --git a/app_namespace/demo/application_appconfig/apps.py b/app_namespace/demo/application_appconfig/apps.py
new file mode 100644
index 0000000..99eefc1
--- /dev/null
+++ b/app_namespace/demo/application_appconfig/apps.py
@@ -0,0 +1,7 @@
+"""Apps for application_appconfig"""
+from django.apps import AppConfig
+
+
+class ApplicationConfig(AppConfig):
+ name = __name__
+ label = 'appconfig'
diff --git a/app_namespace/demo/application_appconfig/templates/application/template.html b/app_namespace/demo/application_appconfig/templates/application/template.html
new file mode 100644
index 0000000..aa6be6d
--- /dev/null
+++ b/app_namespace/demo/application_appconfig/templates/application/template.html
@@ -0,0 +1,8 @@
+{% extends ":application/template.html" %}
+
+{% block list %}
+
+ application_appconfig:application/template.html
+
+{{ block.super }}
+{% endblock%}
diff --git a/app_namespace/demo/settings.py b/app_namespace/demo/settings.py
index ef91a34..ac25cdc 100644
--- a/app_namespace/demo/settings.py
+++ b/app_namespace/demo/settings.py
@@ -40,7 +40,8 @@
INSTALLED_APPS = (
'app_namespace.demo.application_extension',
- 'app_namespace.demo.application'
+ 'app_namespace.demo.application_appconfig.apps.ApplicationConfig',
+ 'app_namespace.demo.application',
)
SILENCED_SYSTEM_CHECKS = ['1_7.W001', '1_8.W001']
diff --git a/app_namespace/loader.py b/app_namespace/loader.py
index 2d8b8db..6d0e038 100644
--- a/app_namespace/loader.py
+++ b/app_namespace/loader.py
@@ -42,12 +42,37 @@ def get_app_template_path(self, app, template_path):
"""
return safe_join(self.app_templates_dirs[app], template_path)
+ def app_templates_dirs_django_18(self):
+ """
+ Build a cached dict with settings.INSTALLED_APPS as keys
+ and the 'templates' directory of each application as values.
+ """
+ from django.apps import apps
+ from django.utils._os import upath
+
+ app_templates_dirs = OrderedDict()
+ for app_config in apps.get_app_configs():
+ if not app_config.path:
+ continue
+ templates_dir = os.path.join(
+ app_config.path, 'templates')
+ if os.path.isdir(templates_dir):
+ templates_dir = upath(templates_dir)
+ app_templates_dirs[app_config.name] = templates_dir
+ app_templates_dirs[app_config.label] = templates_dir
+ return app_templates_dirs
+
@cached_property
def app_templates_dirs(self):
"""
Build a cached dict with settings.INSTALLED_APPS as keys
and the 'templates' directory of each application as values.
"""
+ try:
+ return self.app_templates_dirs_django_18()
+ except ImportError:
+ pass
+
app_templates_dirs = OrderedDict()
for app in settings.INSTALLED_APPS:
try:
diff --git a/app_namespace/tests/tests.py b/app_namespace/tests/tests.py
index d53f9d7..81eec66 100644
--- a/app_namespace/tests/tests.py
+++ b/app_namespace/tests/tests.py
@@ -7,7 +7,6 @@
import django
from django.test import TestCase
-from django.conf import settings
from django.template.base import Context
from django.template.base import Template
from django.template.base import TemplateDoesNotExist
@@ -235,31 +234,27 @@ def setUp(self):
self.template_extend or self.template_initial) %
{'app': app})
- # Register the apps in settings
- self.original_installed_apps = settings.INSTALLED_APPS[:]
- settings.INSTALLED_APPS = list(settings.INSTALLED_APPS)
- settings.INSTALLED_APPS.extend(self.apps)
-
def tearDown(self):
super(MultiAppTestCase, self).tearDown()
sys.path.remove(self.app_directory)
for app in self.apps:
del sys.modules[app]
shutil.rmtree(self.app_directory)
- settings.INSTALLED_APPS = self.original_installed_apps
def multiple_extend_empty_namespace(self):
- context = Context({})
- template = Template(
- self.template_extend % {'app': 'top-level'}
- ).render(context)
- previous_app = ''
- for test_app in ['top-level'] + self.apps:
- self.assertTrue(test_app in template)
- if previous_app:
- self.assertTrue(template.index(test_app) >
- template.index(previous_app))
- previous_app = test_app
+ with self.settings(INSTALLED_APPS=self.apps +
+ ['django.contrib.admin']): # Django 1.4 Fix
+ context = Context({})
+ template = Template(
+ self.template_extend % {'app': 'top-level'}
+ ).render(context)
+ previous_app = ''
+ for test_app in ['top-level'] + self.apps:
+ self.assertTrue(test_app in template)
+ if previous_app:
+ self.assertTrue(template.index(test_app) >
+ template.index(previous_app))
+ previous_app = test_app
@override_settings(
TEMPLATE_LOADERS=(
diff --git a/setup.py b/setup.py
index 470cb41..dd98b27 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@
from setuptools import setup
from setuptools import find_packages
-__version__ = '0.3'
+__version__ = '0.3.1'
__license__ = 'BSD License'
__author__ = 'Fantomas42'