diff --git a/fake_settings.py b/fake_settings.py index 8ed2717..5ab1314 100644 --- a/fake_settings.py +++ b/fake_settings.py @@ -7,6 +7,9 @@ 'django.contrib.admin.apps.SimpleAdminConfig', 'jingo.tests.jinja_app', 'jingo.tests.django_app', + 'django.contrib.sites', + 'django.contrib.contenttypes', + 'django.contrib.auth', ) TEMPLATE_LOADERS = ( 'jingo.Loader', @@ -18,3 +21,24 @@ ROOT_URLCONF = 'jingo.tests.urls' SECRET_KEY = 'jingo' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [path('jingo/tests/templates'),], + 'OPTIONS': { + 'debug': True, + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + 'loaders': [ + 'jingo.Loader', + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + ], + }, + }, +] diff --git a/jingo/__init__.py b/jingo/__init__.py index 503200a..7914e91 100644 --- a/jingo/__init__.py +++ b/jingo/__init__.py @@ -5,11 +5,15 @@ import functools import logging import re +from copy import deepcopy from django.apps import apps from django.conf import settings -from django.template.base import Origin, TemplateDoesNotExist -from django.template.loader import BaseLoader +from django.template.base import Origin +try: + from django.template.loader import BaseLoader +except ImportError: + from django.template.loaders.base import Loader as BaseLoader try: from importlib import import_module @@ -72,6 +76,8 @@ def get_standard_processors(): _helpers_loaded = False +class TemplateDoesNotExist(Exception): + pass class Template(jinja2.Template): @@ -94,7 +100,8 @@ class FakeRequestContext: context = FakeRequestContext() # Used by debug_toolbar. - if settings.TEMPLATE_DEBUG: + TEMPLATES_copy = deepcopy(settings.TEMPLATES) + if TEMPLATES_copy[0]['OPTIONS']['debug']: from django.test import signals self.origin = Origin(self.filename) signals.template_rendered.send(sender=self, template=self, @@ -235,7 +242,7 @@ def wrapper(*args, **kw): class Loader(BaseLoader): is_usable = True - def __init__(self): + def __init__(self, args=None): if has_engine: super(Loader, self).__init__(Engine.get_default()) else: diff --git a/jingo/ext.py b/jingo/ext.py index 10294c9..cfed547 100644 --- a/jingo/ext.py +++ b/jingo/ext.py @@ -10,7 +10,7 @@ from django.core.urlresolvers import reverse from django.http import QueryDict from django.template.defaulttags import CsrfTokenNode -from django.utils import six +import six from django.utils.encoding import smart_str try: from django.utils.encoding import smart_unicode as smart_text diff --git a/jingo/monkey.py b/jingo/monkey.py index 231c338..6c6528c 100644 --- a/jingo/monkey.py +++ b/jingo/monkey.py @@ -20,7 +20,7 @@ from __future__ import absolute_import, print_function, unicode_literals -from django.utils import six +import six def __html__(self): @@ -28,15 +28,15 @@ def __html__(self): def patch(): - from django.forms import forms, formsets, util, widgets + from django.forms import forms, formsets, utils, widgets # Add __html__ methods to these classes: classes = [ forms.BaseForm, forms.BoundField, formsets.BaseFormSet, - util.ErrorDict, - util.ErrorList, + utils.ErrorDict, + utils.ErrorList, widgets.Media, widgets.RadioFieldRenderer, ] diff --git a/jingo/tests/test_helpers.py b/jingo/tests/test_helpers.py index ce387cc..c6202d5 100644 --- a/jingo/tests/test_helpers.py +++ b/jingo/tests/test_helpers.py @@ -7,7 +7,7 @@ from datetime import datetime from collections import namedtuple -from django.utils import six +import six from jinja2 import Markup try: from unittest.mock import patch diff --git a/jingo/tests/test_monkey.py b/jingo/tests/test_monkey.py index c9e4bee..dc0217c 100644 --- a/jingo/tests/test_monkey.py +++ b/jingo/tests/test_monkey.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django import forms -from django.utils import six +import six from jinja2 import escape from nose.tools import eq_ diff --git a/jingo/tests/urls.py b/jingo/tests/urls.py index f062720..e256c9b 100644 --- a/jingo/tests/urls.py +++ b/jingo/tests/urls.py @@ -1,9 +1,9 @@ from __future__ import unicode_literals -from django.conf.urls import patterns +from django.conf.urls import url -urlpatterns = patterns('', - (r'^url/(\d+)/(\w+)/$', lambda r: None, {}, "url-args"), - (r'^url/(?P\d+)/(?P\w+)/$', lambda r: None, {}, "url-kwargs"), -) +urlpatterns = [ + url(r'^url/(\d+)/(\w+)/$', lambda r: None, {}, "url-args"), + url(r'^url/(?P\d+)/(?P\w+)/$', lambda r: None, {}, "url-kwargs"), +] diff --git a/run_tests.py b/run_tests.py index 14186d5..0ba13d2 100644 --- a/run_tests.py +++ b/run_tests.py @@ -10,9 +10,11 @@ os.environ['PYTHONPATH'] = os.pathsep.join([ROOT, os.path.join(ROOT, 'examples')]) +import django +if hasattr(django, 'setup'): + django.setup() + +from django.contrib.contenttypes.models import ContentType + if __name__ == '__main__': - if hasattr(django, 'setup'): - # Django's app registry was added in 1.7. We need to call `setup` to - # initiate it. - django.setup() nose.main() diff --git a/setup.py b/setup.py index 0fbc4ea..4ffb440 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ packages=['jingo'], include_package_data=True, zip_safe=False, - install_requires=['jinja2'], + install_requires=['jinja2', 'six'], classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Web Environment', diff --git a/tox.ini b/tox.ini index d3805bc..9d46902 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27-1.7, py27-1.8, py33-1.7, py33-1.8, py34-1.7, py34-1.8 +envlist = py27-1.7, py27-1.8, py27-1.9, py33-1.7, py33-1.8, py34-1.7, py34-1.8, py34-1.9 toxworkdir = {homedir}/.tox-jingo [testenv] @@ -9,6 +9,7 @@ deps = jinja2 nose mock + six [testenv:py27-1.7] basepython = python2.7 @@ -22,6 +23,12 @@ deps = Django>=1.8,<1.9 {[testenv]deps} +[testenv:py27-1.9] +basepython = python2.7 +deps = + Django>=1.9,<1.10 + {[testenv]deps} + [testenv:py33-1.7] basepython = python3.3 deps = @@ -46,6 +53,12 @@ deps = Django>=1.8,<1.9 {[testenv]deps} +[testenv:py34-1.9] +basepython = python3.4 +deps = + Django>=1.9,<1.10 + {[testenv]deps} + [testenv:py35-1.8] basepython = python3.5 deps =