Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Django 1.8-1.10 #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ python:
- "3.4"

env:
- DJANGO="Django>=1.10,<1.11"
- DJANGO="Django>=1.9,<1.10"
- DJANGO="Django>=1.8,<1.9"
- DJANGO="Django>=1.7,<1.8"
- DJANGO="Django>=1.6,<1.7"
- DJANGO="Django>=1.5,<1.6"
Expand All @@ -20,8 +23,18 @@ script: 'python setup.py test'

matrix:
exclude:
- python: "2.6"
env: DJANGO="Django>=1.10,<1.11"
- python: "2.6"
env: DJANGO="Django>=1.9,<1.10"
- python: "2.6"
env: DJANGO="Django>=1.8,<1.9"
- python: "2.6"
env: DJANGO="Django>=1.7,<1.8"
- python: "3.3"
env: DJANGO="Django>=1.10,<1.11"
- python: "3.3"
env: DJANGO="Django>=1.9,<1.10"
- python: "3.3"
env: DJANGO="Django>=1.4,<1.5"
- python: "3.3"
Expand Down
16 changes: 13 additions & 3 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@


def main():
template_dirs = (
os.path.join(os.path.dirname(__file__), 'templatefinder', 'test_project', 'templates'),
)
settings.configure(
DATABASES={
'default': {
Expand All @@ -17,9 +20,16 @@ def main():
INSTALLED_APPS=(
'templatefinder.test_project.testapp',
),
TEMPLATE_DIRS=(
os.path.join(os.path.dirname(__file__), 'templatefinder', 'test_project', 'templates'),
)
TEMPLATE_DIRS=template_dirs,
TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': template_dirs,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
],
},
}]
)
if hasattr(django, 'setup'):
django.setup()
Expand Down
6 changes: 5 additions & 1 deletion templatefinder/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.conf import settings
from django.utils import unittest
try:
from django.utils import unittest
except ImportError:
# Django removed its unittest vendoring in 1.9
import unittest

from . import find_all_templates, flatten_template_loaders, template_choices

Expand Down
29 changes: 21 additions & 8 deletions templatefinder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
class Engine(object):
@staticmethod
def get_default():
return None
return Engine()
@property
def loaders(self):
return settings.TEMPLATE_LOADERS


__all__ = ('find_all_templates', 'flatten_template_loaders', 'template_choices')
Expand All @@ -42,23 +45,33 @@ def find_all_templates(pattern='*.html'):
.. important:: At the moment egg loader is not supported.
"""
templates = []
template_loaders = flatten_template_loaders(settings.TEMPLATE_LOADERS)
engine = Engine.get_default()
template_loaders = flatten_template_loaders(engine.loaders)
for loader_name in template_loaders:
module, klass = loader_name.rsplit('.', 1)
if loader_name in (
'django.template.loaders.app_directories.Loader',
'django.template.loaders.filesystem.Loader',
):
loader_class = getattr(import_module(module), klass)
if getattr(loader_class, '_accepts_engine_in_init', False):
loader = loader_class(Engine.get_default())
else:
try:
# Between 1.8 and 1.10, its possible to check
# _accepts_engine_in_init to see if it accepts one, but the
# normal suite of loaders we likely care about all want one.
loader = loader_class(engine)
except TypeError:
# Prior to the template refactor in 1.8, loaders never
# accepted an engine.
loader = loader_class()
for dir in loader.get_template_sources(''):
for root, dirnames, filenames in os.walk(dir):
for directory in loader.get_template_sources(''):
# In 1.9, Origin is always set.
# https://docs.djangoproject.com/en/1.9/releases/1.9/#template-loaderorigin-and-stringorigin-are-removed
if hasattr(directory, 'loader_name'):
directory = directory.name
for root, dirnames, filenames in os.walk(directory):
for basename in filenames:
filename = os.path.join(root, basename)
rel_filename = filename[len(dir)+1:]
rel_filename = filename[len(directory)+1:]
if fnmatch.fnmatch(filename, pattern) or \
fnmatch.fnmatch(basename, pattern) or \
fnmatch.fnmatch(rel_filename, pattern):
Expand Down
36 changes: 35 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py3.4-django1.7, py3.3-django1.7, py2.7-django1.7, py3.4-django1.6, py3.3-django1.6, py2.7-django1.6, py2.6-django1.6, py3.3-django1.5, py2.7-django1.5, py2.6-django1.5, py2.7-django1.4, py2.6-django1.4, py2.7-django1.3, py2.6-django1.3
envlist = py3.4-django1.10, py2.7-django1.10, py3.4-django1.9, py2.7-django1.9, py3.4-django1.8, py3.3-django1.8, py2.7-django1.8, py3.4-django1.7, py3.3-django1.7, py2.7-django1.7, py3.4-django1.6, py3.3-django1.6, py2.7-django1.6, py2.6-django1.6, py3.3-django1.5, py2.7-django1.5, py2.6-django1.5, py2.7-django1.4, py2.6-django1.4, py2.7-django1.3, py2.6-django1.3

[testenv]
commands = {envpython} setup.py test
Expand All @@ -8,6 +8,40 @@ commands = {envpython} setup.py test
;basepython = pypy
;deps = Django>=1.5,<1.6

; Django 1.10.x

[testenv:py3.4-django1.10]
basepython = python3.4
deps = Django>=1.10,<1.11

[testenv:py2.7-django1.10]
basepython = python2.7
deps = Django>=1.10,<1.11

; Django 1.9.x

[testenv:py3.4-django1.9]
basepython = python3.4
deps = Django>=1.9,<1.10

[testenv:py2.7-django1.9]
basepython = python2.7
deps = Django>=1.9,<1.10

; Django 1.8.x

[testenv:py3.4-django1.8]
basepython = python3.4
deps = Django>=1.8,<1.9

[testenv:py3.3-django1.8]
basepython = python3.3
deps = Django>=1.8,<1.9

[testenv:py2.7-django1.8]
basepython = python2.7
deps = Django>=1.8,<1.9

; Django 1.7.x

[testenv:py3.4-django1.7]
Expand Down