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

Compat for Django 1.9 and 1.10 #81

Open
wants to merge 15 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
24 changes: 24 additions & 0 deletions fake_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
],
},
},
]
15 changes: 11 additions & 4 deletions jingo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,6 +76,8 @@ def get_standard_processors():

_helpers_loaded = False

class TemplateDoesNotExist(Exception):
pass

class Template(jinja2.Template):

Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion jingo/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions jingo/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@

from __future__ import absolute_import, print_function, unicode_literals

from django.utils import six
import six


def __html__(self):
return six.text_type(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,
]
Expand Down
2 changes: 1 addition & 1 deletion jingo/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jingo/tests/test_monkey.py
Original file line number Diff line number Diff line change
@@ -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_
Expand Down
10 changes: 5 additions & 5 deletions jingo/tests/urls.py
Original file line number Diff line number Diff line change
@@ -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<num>\d+)/(?P<word>\w+)/$', lambda r: None, {}, "url-kwargs"),
)
urlpatterns = [
url(r'^url/(\d+)/(\w+)/$', lambda r: None, {}, "url-args"),
url(r'^url/(?P<num>\d+)/(?P<word>\w+)/$', lambda r: None, {}, "url-kwargs"),
]
10 changes: 6 additions & 4 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
15 changes: 14 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -9,6 +9,7 @@ deps =
jinja2
nose
mock
six

[testenv:py27-1.7]
basepython = python2.7
Expand All @@ -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 =
Expand All @@ -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 =
Expand Down