Skip to content

Commit

Permalink
Fix when app_namespace is not registered first, close #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Jun 29, 2016
1 parent f9e9e1a commit 3b93db2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app_namespace/loader.py
Expand Up @@ -89,7 +89,6 @@ def get_template_sources(self, template_name):
application.
"""
if ':' not in template_name:
self.reset()
return

app, template_path = template_name.split(':')
Expand All @@ -101,6 +100,7 @@ def get_template_sources(self, template_name):
loader=self)
return

self.reset()
for app in self.app_templates_dirs:
file_path = self.get_app_template_path(app, template_path)
if file_path in self._already_used:
Expand Down
1 change: 1 addition & 0 deletions app_namespace/tests/template.html
@@ -0,0 +1 @@
{% extends ":admin/base.html" %}
50 changes: 50 additions & 0 deletions app_namespace/tests/tests.py
Expand Up @@ -10,6 +10,7 @@
from django.template.engine import Engine
from django.template import TemplateDoesNotExist
from django.template.loaders import app_directories
from django.core.urlresolvers import reverse
from django.test.utils import override_settings

from app_namespace import Loader
Expand Down Expand Up @@ -309,3 +310,52 @@ def test_app_config_multiple_extend_empty_namespace(self):
def test_cached_multiple_extend_empty_namespace(self):
with self.assertRaises(RuntimeError):
self.multiple_extend_empty_namespace()


class ViewTestCase(TestCase):

def load_view_twice(self):
url = reverse('template-view')
r1 = self.client.get(url).content
r2 = self.client.get(url).content
self.assertEquals(r1, r2)

@override_settings(
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.abspath(os.path.dirname(__file__)),
],
'OPTIONS': {
'loaders': (
'app_namespace.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
}
}
]
)
def test_load_view_twice_app_namespace_first(self):
self.load_view_twice()

@override_settings(
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.abspath(os.path.dirname(__file__)),
],
'OPTIONS': {
'loaders': (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'app_namespace.Loader',
)
}
}
]
)
def test_load_view_twice_app_namespace_last(self):
self.load_view_twice()
4 changes: 4 additions & 0 deletions app_namespace/tests/urls.py
@@ -1,10 +1,14 @@
"""Urls for testing app_namespace"""
from django.conf.urls import url
from django.conf.urls import include
from django.views.generic import TemplateView
from django.contrib import admin

admin.autodiscover()

urlpatterns = [
url(r'^$', TemplateView.as_view(
template_name='template.html'),
name='template-view'),
url(r'^admin/', include(admin.site.urls)),
]

0 comments on commit 3b93db2

Please sign in to comment.