Merge pull request #457 from uadnan/master
Django 1.9+ Support for template_loader (fix for #456)
This commit is contained in:
commit
8a4d0d6d21
|
@ -10,7 +10,6 @@ addons:
|
|||
install: pip install -q tox-travis
|
||||
env:
|
||||
- DJANGO=1.8
|
||||
- DJANGO=1.9
|
||||
- DJANGO=1.10
|
||||
- DJANGO=1.11
|
||||
matrix:
|
||||
|
|
|
@ -10,8 +10,8 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
|
|||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
import os
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
|
||||
|
@ -28,7 +28,6 @@ ALLOWED_HOSTS = []
|
|||
|
||||
DEFAULT_FILE_STORAGE = 'tenant_schemas.storage.TenantFileSystemStorage'
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
SHARED_APPS = (
|
||||
|
@ -74,7 +73,6 @@ ROOT_URLCONF = 'dts_test_project.urls'
|
|||
|
||||
WSGI_APPLICATION = 'dts_test_project.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
|
||||
|
||||
|
@ -111,6 +109,16 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
|||
'django.contrib.messages.context_processors.messages',
|
||||
)
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'OPTIONS': {
|
||||
'context_processors': TEMPLATE_CONTEXT_PROCESSORS
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.8/topics/i18n/
|
||||
|
||||
|
@ -124,7 +132,6 @@ USE_L10N = True
|
|||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.8/howto/static-files/
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import re
|
||||
import warnings
|
||||
|
||||
import django.db.utils
|
||||
import psycopg2
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
||||
import django.db.utils
|
||||
|
||||
from tenant_schemas.utils import get_public_schema_name, get_limit_set_calls
|
||||
from tenant_schemas.postgresql_backend.introspection import DatabaseSchemaIntrospection
|
||||
from tenant_schemas.utils import get_limit_set_calls, get_public_schema_name
|
||||
|
||||
|
||||
ORIGINAL_BACKEND = getattr(settings, 'ORIGINAL_BACKEND', 'django.db.backends.postgresql_psycopg2')
|
||||
# Django 1.9+ takes care to rename the default backend to 'django.db.backends.postgresql'
|
||||
|
|
|
@ -4,16 +4,28 @@ multi-tenant setting
|
|||
"""
|
||||
|
||||
import hashlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.template.base import TemplateDoesNotExist, Template
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils._os import safe_join
|
||||
from django.db import connection
|
||||
from django.template import TemplateDoesNotExist
|
||||
from django.template.base import Template
|
||||
from django.template.loaders.base import Loader as BaseLoader
|
||||
from django.utils._os import safe_join
|
||||
from django.utils.encoding import force_bytes
|
||||
|
||||
from tenant_schemas.postgresql_backend.base import FakeTenant
|
||||
|
||||
try:
|
||||
from django.template import Origin
|
||||
|
||||
def make_origin(engine, name, loader, template_name, dirs):
|
||||
return Origin(name=name, template_name=template_name, loader=loader)
|
||||
|
||||
except ImportError: # Django 1.8 backwards compatibility
|
||||
def make_origin(engine, name, loader, template_name, dirs):
|
||||
return engine.make_origin(name, loader, template_name, dirs)
|
||||
|
||||
|
||||
class CachedLoader(BaseLoader):
|
||||
is_usable = True
|
||||
|
@ -50,7 +62,7 @@ class CachedLoader(BaseLoader):
|
|||
except TemplateDoesNotExist:
|
||||
pass
|
||||
else:
|
||||
origin = self.engine.make_origin(display_name, loader, name, dirs)
|
||||
origin = make_origin(self.engine, display_name, loader, name, dirs)
|
||||
result = template, origin
|
||||
break
|
||||
self.find_template_cache[key] = result
|
||||
|
@ -133,4 +145,5 @@ class FilesystemLoader(BaseLoader):
|
|||
else:
|
||||
error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
|
||||
raise TemplateDoesNotExist(error_msg)
|
||||
|
||||
load_template_source.is_usable = True
|
||||
|
|
|
@ -2,7 +2,6 @@ from django.conf import settings
|
|||
from django.core.management import call_command
|
||||
from django.db import connection
|
||||
from django.test import TestCase
|
||||
|
||||
from tenant_schemas.utils import get_public_schema_name, get_tenant_model
|
||||
|
||||
ALLOWED_TEST_DOMAIN = '.test.com'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from .test_routes import *
|
||||
from .test_tenants import *
|
||||
from .template_loader import *
|
||||
from .test_cache import *
|
||||
from .test_log import *
|
||||
from .test_routes import *
|
||||
from .test_tenants import *
|
||||
from .test_utils import *
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
from .test_cached_template_loader import CachedLoaderTests
|
|
@ -0,0 +1 @@
|
|||
Hello! (Django templates)
|
|
@ -0,0 +1,31 @@
|
|||
import os
|
||||
|
||||
from django.template.loader import get_template
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
|
||||
|
||||
@override_settings(
|
||||
TEMPLATES=[
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [
|
||||
os.path.join(os.path.dirname(__file__), "templates")
|
||||
],
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
],
|
||||
'loaders': [
|
||||
('tenant_schemas.template_loaders.CachedLoader', (
|
||||
'tenant_schemas.template_loaders.FilesystemLoader',
|
||||
'django.template.loaders.filesystem.Loader'
|
||||
))
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
)
|
||||
class CachedLoaderTests(SimpleTestCase):
|
||||
def test_get_template(self):
|
||||
template = get_template("hello.html")
|
||||
self.assertEqual(template.render(), "Hello! (Django templates)\n")
|
4
tox.ini
4
tox.ini
|
@ -1,10 +1,9 @@
|
|||
[tox]
|
||||
envlist = py{27,35}-dj{18,19,110,111}-{standard,parallel}
|
||||
envlist = py{27,35}-dj{18,110,111}-{standard,parallel}
|
||||
|
||||
[travis:env]
|
||||
DJANGO =
|
||||
1.8: dj18-{standard,parallel}
|
||||
1.9: dj19-{standard,parallel}
|
||||
1.10: dj110-{standard,parallel}
|
||||
1.11: dj111-{standard,parallel}
|
||||
|
||||
|
@ -16,7 +15,6 @@ deps =
|
|||
mock
|
||||
tblib
|
||||
dj18: Django~=1.8.0
|
||||
dj19: Django~=1.9.0
|
||||
dj110: Django~=1.10.0
|
||||
dj111: Django~=1.11.0
|
||||
|
||||
|
|
Loading…
Reference in New Issue