Remove code for old django versions
This commit is contained in:
@@ -23,6 +23,7 @@ from compressor.filters import CachedCompilerFilter
|
||||
from compressor.filters.css_default import CssAbsoluteFilter
|
||||
from compressor.storage import compressor_file_storage
|
||||
from compressor.signals import post_compress
|
||||
from django.template.loader import render_to_string
|
||||
from compressor.utils import get_class, get_mod_func, staticfiles
|
||||
from compressor.utils.decorators import cached_property
|
||||
|
||||
@@ -31,18 +32,6 @@ SOURCE_HUNK, SOURCE_FILE = 'inline', 'file'
|
||||
METHOD_INPUT, METHOD_OUTPUT = 'input', 'output'
|
||||
|
||||
|
||||
if django.VERSION < (1, 8):
|
||||
# Provide render_to_string that is similar to Django 1.8 version, for our
|
||||
# needs, using what < 1.8 provides:
|
||||
from django.template.loader import render_to_string as django_render_to_string
|
||||
|
||||
def render_to_string(template_name, context=None):
|
||||
return django_render_to_string(template_name, dictionary=context)
|
||||
|
||||
else:
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
|
||||
class Compressor(object):
|
||||
"""
|
||||
Base compressor object to be subclassed for content type
|
||||
|
@@ -21,6 +21,7 @@ try:
|
||||
except:
|
||||
from django.utils.importlib import import_module
|
||||
from django.template.loader import get_template # noqa Leave this in to preload template locations
|
||||
from django.template import engines
|
||||
|
||||
from compressor.cache import get_offline_hexdigest, write_offline_manifest
|
||||
from compressor.conf import settings
|
||||
@@ -61,30 +62,9 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
def get_loaders(self):
|
||||
if django.VERSION < (1, 8):
|
||||
from django.template.loader import template_source_loaders
|
||||
if template_source_loaders is None:
|
||||
try:
|
||||
from django.template.loader import (
|
||||
find_template as finder_func)
|
||||
except ImportError:
|
||||
from django.template.loader import (
|
||||
find_template_source as finder_func) # noqa
|
||||
try:
|
||||
# Force django to calculate template_source_loaders from
|
||||
# TEMPLATE_LOADERS settings, by asking to find a dummy template
|
||||
source, name = finder_func('test')
|
||||
except django.template.TemplateDoesNotExist:
|
||||
pass
|
||||
# Reload template_source_loaders now that it has been calculated ;
|
||||
# it should contain the list of valid, instanciated template loaders
|
||||
# to use.
|
||||
from django.template.loader import template_source_loaders
|
||||
else:
|
||||
from django.template import engines
|
||||
template_source_loaders = []
|
||||
for e in engines.all():
|
||||
template_source_loaders.extend(e.engine.get_template_loaders(e.engine.loaders))
|
||||
template_source_loaders = []
|
||||
for e in engines.all():
|
||||
template_source_loaders.extend(e.engine.get_template_loaders(e.engine.loaders))
|
||||
loaders = []
|
||||
# If template loader is CachedTemplateLoader, return the loaders
|
||||
# that it wraps around. So if we have
|
||||
@@ -302,7 +282,5 @@ class Command(BaseCommand):
|
||||
self.compress(sys.stdout, **options)
|
||||
|
||||
|
||||
if django.VERSION < (1, 7):
|
||||
Command.requires_model_validation = False
|
||||
else:
|
||||
Command.requires_system_checks = False
|
||||
|
||||
Command.requires_system_checks = False
|
||||
|
@@ -1,7 +1,6 @@
|
||||
from __future__ import absolute_import
|
||||
from copy import copy
|
||||
|
||||
import django
|
||||
from django import template
|
||||
from django.template import Context
|
||||
from django.template.base import Node, VariableNode, TextNode, NodeList
|
||||
@@ -101,10 +100,7 @@ class DjangoParser(object):
|
||||
|
||||
def parse(self, template_name):
|
||||
try:
|
||||
if django.VERSION < (1, 8):
|
||||
return get_template(template_name)
|
||||
else:
|
||||
return get_template(template_name).template
|
||||
return get_template(template_name).template
|
||||
except template.TemplateSyntaxError as e:
|
||||
raise TemplateSyntaxError(str(e))
|
||||
except template.TemplateDoesNotExist as e:
|
||||
@@ -120,8 +116,7 @@ class DjangoParser(object):
|
||||
pass
|
||||
|
||||
def render_nodelist(self, template, context, node):
|
||||
if django.VERSION >= (1, 8):
|
||||
context.template = template
|
||||
context.template = template
|
||||
return node.nodelist.render(context)
|
||||
|
||||
def render_node(self, template, context, node):
|
||||
@@ -146,7 +141,7 @@ class DjangoParser(object):
|
||||
return nodelist
|
||||
|
||||
def walk_nodes(self, node, original=None):
|
||||
if django.VERSION >= (1, 8) and original is None:
|
||||
if original is None:
|
||||
original = node
|
||||
for node in self.get_nodelist(node, original):
|
||||
if isinstance(node, CompressorNode) and node.is_offline_compression_enabled(forced=True):
|
||||
|
@@ -24,8 +24,8 @@ INSTALLED_APPS = [
|
||||
'sekizai',
|
||||
]
|
||||
|
||||
# currently, we can't use overextends and django 1.9 since that would
|
||||
# require updating the templates settings to the new format.
|
||||
# currently, we can't use overextends and django 1.9 since that would
|
||||
# require updating the templates settings to the new format.
|
||||
if django.VERSION < (1, 9):
|
||||
INSTALLED_APPS.append('overextends')
|
||||
|
||||
@@ -47,9 +47,6 @@ TEMPLATE_DIRS = (
|
||||
os.path.join(TEST_DIR, 'test_templates'),
|
||||
)
|
||||
|
||||
if django.VERSION[:2] < (1, 6):
|
||||
TEST_RUNNER = 'discover_runner.DiscoverRunner'
|
||||
|
||||
SECRET_KEY = "iufoj=mibkpdz*%bob952x(%49rqgv8gg45k36kjcg76&-y5=!"
|
||||
|
||||
PASSWORD_HASHERS = (
|
||||
|
@@ -1,5 +1,3 @@
|
||||
import unittest
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.conf import settings
|
||||
@@ -31,8 +29,6 @@ class StaticFilesTestCase(TestCase):
|
||||
self.assertTrue(compressor.utils.staticfiles.finders is
|
||||
django.contrib.staticfiles.finders)
|
||||
|
||||
@unittest.skipIf(django.VERSION < (1, 7),
|
||||
"No app registry in Django < 1.7")
|
||||
def test_has_finders_from_staticfiles_if_configured_per_appconfig(self):
|
||||
apps = get_apps_with_staticfiles_using_appconfig(
|
||||
settings.INSTALLED_APPS)
|
||||
|
@@ -1,19 +1,12 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import django
|
||||
from django.apps import apps
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from compressor.conf import settings
|
||||
|
||||
|
||||
def staticfiles_installed():
|
||||
if django.VERSION < (1, 7):
|
||||
return "django.contrib.staticfiles" in settings.INSTALLED_APPS
|
||||
from django.apps import apps
|
||||
return apps.is_installed("django.contrib.staticfiles")
|
||||
|
||||
|
||||
if staticfiles_installed():
|
||||
if apps.is_installed("django.contrib.staticfiles"):
|
||||
from django.contrib.staticfiles import finders # noqa
|
||||
|
||||
if ("compressor.finders.CompressorFinder"
|
||||
|
Reference in New Issue
Block a user