Remove code for old django versions

This commit is contained in:
Johannes Linke
2015-12-09 18:04:42 +01:00
parent d16d0b2968
commit 671cf7dce2
6 changed files with 14 additions and 66 deletions

View File

@@ -23,6 +23,7 @@ from compressor.filters import CachedCompilerFilter
from compressor.filters.css_default import CssAbsoluteFilter from compressor.filters.css_default import CssAbsoluteFilter
from compressor.storage import compressor_file_storage from compressor.storage import compressor_file_storage
from compressor.signals import post_compress 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 import get_class, get_mod_func, staticfiles
from compressor.utils.decorators import cached_property from compressor.utils.decorators import cached_property
@@ -31,18 +32,6 @@ SOURCE_HUNK, SOURCE_FILE = 'inline', 'file'
METHOD_INPUT, METHOD_OUTPUT = 'input', 'output' 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): class Compressor(object):
""" """
Base compressor object to be subclassed for content type Base compressor object to be subclassed for content type

View File

@@ -21,6 +21,7 @@ try:
except: except:
from django.utils.importlib import import_module 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.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.cache import get_offline_hexdigest, write_offline_manifest
from compressor.conf import settings from compressor.conf import settings
@@ -61,27 +62,6 @@ class Command(BaseCommand):
) )
def get_loaders(self): 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 = [] template_source_loaders = []
for e in engines.all(): for e in engines.all():
template_source_loaders.extend(e.engine.get_template_loaders(e.engine.loaders)) template_source_loaders.extend(e.engine.get_template_loaders(e.engine.loaders))
@@ -302,7 +282,5 @@ class Command(BaseCommand):
self.compress(sys.stdout, **options) 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

View File

@@ -1,7 +1,6 @@
from __future__ import absolute_import from __future__ import absolute_import
from copy import copy from copy import copy
import django
from django import template from django import template
from django.template import Context from django.template import Context
from django.template.base import Node, VariableNode, TextNode, NodeList from django.template.base import Node, VariableNode, TextNode, NodeList
@@ -101,9 +100,6 @@ class DjangoParser(object):
def parse(self, template_name): def parse(self, template_name):
try: 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: except template.TemplateSyntaxError as e:
raise TemplateSyntaxError(str(e)) raise TemplateSyntaxError(str(e))
@@ -120,7 +116,6 @@ class DjangoParser(object):
pass pass
def render_nodelist(self, template, context, node): def render_nodelist(self, template, context, node):
if django.VERSION >= (1, 8):
context.template = template context.template = template
return node.nodelist.render(context) return node.nodelist.render(context)
@@ -146,7 +141,7 @@ class DjangoParser(object):
return nodelist return nodelist
def walk_nodes(self, node, original=None): def walk_nodes(self, node, original=None):
if django.VERSION >= (1, 8) and original is None: if original is None:
original = node original = node
for node in self.get_nodelist(node, original): for node in self.get_nodelist(node, original):
if isinstance(node, CompressorNode) and node.is_offline_compression_enabled(forced=True): if isinstance(node, CompressorNode) and node.is_offline_compression_enabled(forced=True):

View File

@@ -47,9 +47,6 @@ TEMPLATE_DIRS = (
os.path.join(TEST_DIR, 'test_templates'), 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=!" SECRET_KEY = "iufoj=mibkpdz*%bob952x(%49rqgv8gg45k36kjcg76&-y5=!"
PASSWORD_HASHERS = ( PASSWORD_HASHERS = (

View File

@@ -1,5 +1,3 @@
import unittest
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
@@ -31,8 +29,6 @@ class StaticFilesTestCase(TestCase):
self.assertTrue(compressor.utils.staticfiles.finders is self.assertTrue(compressor.utils.staticfiles.finders is
django.contrib.staticfiles.finders) 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): def test_has_finders_from_staticfiles_if_configured_per_appconfig(self):
apps = get_apps_with_staticfiles_using_appconfig( apps = get_apps_with_staticfiles_using_appconfig(
settings.INSTALLED_APPS) settings.INSTALLED_APPS)

View File

@@ -1,19 +1,12 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
import django from django.apps import apps
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from compressor.conf import settings from compressor.conf import settings
def staticfiles_installed(): if apps.is_installed("django.contrib.staticfiles"):
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():
from django.contrib.staticfiles import finders # noqa from django.contrib.staticfiles import finders # noqa
if ("compressor.finders.CompressorFinder" if ("compressor.finders.CompressorFinder"