From f449f69ae2bcf4ee33f4bd7999433791ca59bafb Mon Sep 17 00:00:00 2001 From: "Chirag B. Jadwani" Date: Wed, 20 Jan 2016 17:07:37 +0530 Subject: [PATCH] Fix errors in django 1.8 and below --- compressor/offline/django.py | 5 +++-- compressor/tests/test_offline.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compressor/offline/django.py b/compressor/offline/django.py index da780a7..0cae086 100644 --- a/compressor/offline/django.py +++ b/compressor/offline/django.py @@ -18,8 +18,9 @@ def handle_extendsnode(extendsnode, context): all blocks tags with the nodes of appropriate blocks. Also handles {{ block.super }} tags. """ - context.render_context.setdefault(BLOCK_CONTEXT_KEY, BlockContext()) - block_context = context.render_context.get(BLOCK_CONTEXT_KEY) + if BLOCK_CONTEXT_KEY not in context.render_context: + context.render_context[BLOCK_CONTEXT_KEY] = BlockContext() + block_context = context.render_context[BLOCK_CONTEXT_KEY] blocks = dict((n.name, n) for n in extendsnode.nodelist.get_nodes_by_type(BlockNode)) block_context.add_blocks(blocks) diff --git a/compressor/tests/test_offline.py b/compressor/tests/test_offline.py index d63b49d..cb94ec9 100644 --- a/compressor/tests/test_offline.py +++ b/compressor/tests/test_offline.py @@ -7,8 +7,9 @@ import unittest from importlib import import_module from mock import patch -from unittest import SkipTest +from unittest import SkipTest, skipIf +from django import VERSION as DJANGO_VERSION from django.core.management.base import CommandError from django.template import Template, Context from django.test import TestCase @@ -632,6 +633,7 @@ class OfflineCompressComplexTestCase(OfflineTestCaseMixin, TestCase): self.assertEqual(rendered_template, ''.join(result) + '\n') +@skipIf(DJANGO_VERSION[0] <= 1 and DJANGO_VERSION[1] < 9, "Needs Django >= 1.9, recursive templates were fixed in Django 1.9") class OfflineCompressExtendsRecursionTestCase(OfflineTestCaseMixin, TestCase): """ Test that templates extending templates with the same name