Skip to content

Commit

Permalink
Merge branch 'release/v0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Feb 1, 2016
2 parents ebd016f + 0c5f8ba commit a645b58
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 20 deletions.
3 changes: 3 additions & 0 deletions app_namespace/demo/application_appconfig/__init__.py
@@ -0,0 +1,3 @@
"""
demo.application_extension
"""
7 changes: 7 additions & 0 deletions 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'
@@ -0,0 +1,8 @@
{% extends ":application/template.html" %}

{% block list %}
<li>
<code>application_appconfig:application/template.html</code>
</li>
{{ block.super }}
{% endblock%}
3 changes: 2 additions & 1 deletion app_namespace/demo/settings.py
Expand Up @@ -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']
25 changes: 25 additions & 0 deletions app_namespace/loader.py
Expand Up @@ -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:
Expand Down
31 changes: 13 additions & 18 deletions app_namespace/tests/tests.py
Expand Up @@ -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
Expand Down Expand Up @@ -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=(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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'
Expand Down

0 comments on commit a645b58

Please sign in to comment.