Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.1
python-django-sekizai
django-sekizai-django2.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File django-sekizai-django2.patch of Package python-django-sekizai
From 27fce391e724531e0fa6edb22cc56c665b3ec39c Mon Sep 17 00:00:00 2001 From: Tim Graham <timograham@gmail.com> Date: Fri, 14 Sep 2018 15:43:11 -0400 Subject: [PATCH] Add support for Django 1.11, 2.0, and 2.1 Drop support for older versions. --- .travis.yml | 39 ++++------------- docs/index.rst | 22 +++++----- runtests.py | 37 ++++------------ sekizai/helpers.py | 14 ++----- sekizai/templatetags/sekizai_tags.py | 8 +--- sekizai/tests.py | 63 ++++++++++------------------ setup.py | 5 +++ 7 files changed, 60 insertions(+), 128 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 272d321..88f98e0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -24,15 +24,14 @@ blocks get rendered and at different places in your templates append to those blocks. This is especially useful for css and javascript. Your sub-templates can now define css and Javascript files to be included, and the css will be nicely put at the top and the Javascript to the bottom, just like you should. Also -sekizai will ignore any duplicate content in a single block. +sekizai will ignore any duplicate content in a single block. ************ Dependencies ************ -* Python 2.7, 3.3, 3.4 or 3.5. -* Django 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9 or 1.10. +* Django 1.11, 2.0, or 2.1. * django-classy-tags 0.3.1 or higher. ***** @@ -47,15 +46,10 @@ steps: * Put 'sekizai' into your ``INSTALLED_APPS`` setting. * Use one of the following: - * For Django versions before 1.10, add - ``sekizai.context_processors.sekizai`` to your - ``TEMPLATE_CONTEXT_PROCESSORS`` setting and use + * Add ``sekizai.context_processors.sekizai`` to your + ``TEMPLATES['OPTIONS']['context_processors']`` setting and use ``django.template.RequestContext`` when rendering your templates. - For Django versions after 1.10, add ``sekizai.context_processors.sekizai`` - to your ``TEMPLATES['OPTIONS']['context_processors']`` setting and use - ``django.template.RequestContext`` when rendering your templates. - or * Use ``sekizai.context.SekizaiContext`` when rendering your templates. @@ -137,7 +131,7 @@ Restrictions .. warning:: ``{% render_block %}`` tags **must not** be placed inside a template tag block (a template tag which has an - end tag, such as ``{% block %}...{% endblock %}`` or ``{% if %}...{% endif %}``). + end tag, such as ``{% block %}...{% endblock %}`` or ``{% if %}...{% endif %}``). .. warning:: @@ -434,6 +428,12 @@ And here's the rendered template:: Changelog ********* +0.11.0 +====== + +* Added support for Django 1.11, 2.0, and 2.1 +* Removed support for Django < 1.11 + 0.10.0 ====== diff --git a/runtests.py b/runtests.py index dfd0d45..1a0db34 100644 --- a/runtests.py +++ b/runtests.py @@ -4,8 +4,6 @@ urlpatterns = [] -TEMPLATE_DEBUG = True - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', @@ -13,59 +11,38 @@ } } - INSTALLED_APPS = [ 'sekizai', ] -TEMPLATE_DIRS = [ - os.path.join(os.path.dirname(__file__), 'sekizai', 'test_templates'), -] - -TEMPLATE_CONTEXT_PROCESSORS = [ - 'sekizai.context_processors.sekizai', -] - - ROOT_URLCONF = 'runtests' - TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': TEMPLATE_DIRS, + 'DIRS': [os.path.join(os.path.dirname(__file__), 'sekizai', 'test_templates')], 'OPTIONS': { - 'context_processors': TEMPLATE_CONTEXT_PROCESSORS, - 'debug': TEMPLATE_DEBUG + 'context_processors': ['sekizai.context_processors.sekizai'], + 'debug': True, }, }, ] def runtests(): - from django import VERSION + from django import setup from django.conf import settings - if VERSION[0] == 1 and VERSION[1] < 6: - runner = 'django.test.simple.DjangoTestSuiteRunner' - else: - runner = 'django.test.runner.DiscoverRunner' + from django.test.utils import get_runner settings.configure( INSTALLED_APPS=INSTALLED_APPS, ROOT_URLCONF=ROOT_URLCONF, DATABASES=DATABASES, - TEST_RUNNER=runner, - TEMPLATE_DIRS=TEMPLATE_DIRS, - TEMPLATE_CONTEXT_PROCESSORS=TEMPLATE_CONTEXT_PROCESSORS, - TEMPLATE_DEBUG=TEMPLATE_DEBUG, - MIDDLEWARE_CLASSES=[], + TEST_RUNNER='django.test.runner.DiscoverRunner', TEMPLATES=TEMPLATES, ) - if VERSION[1] >= 7: - from django import setup - setup() + setup() # Run the test suite, including the extra validation tests. - from django.test.utils import get_runner TestRunner = get_runner(settings) test_runner = TestRunner(verbosity=1, interactive=False, failfast=False) diff --git a/sekizai/helpers.py b/sekizai/helpers.py index 9678c56..c77a2cd 100644 --- a/sekizai/helpers.py +++ b/sekizai/helpers.py @@ -5,11 +5,6 @@ from django.template.loader import get_template from django.template.loader_tags import BlockNode, ExtendsNode -try: - from django.template import engines -except ImportError: - engines = None - def _get_nodelist(tpl): if isinstance(tpl, Template): @@ -29,12 +24,9 @@ def is_variable_extend_node(node): def get_context(): - if engines is not None: - context = Context() - context.template = Template('') - return context - else: - return Context() + context = Context() + context.template = Template('') + return context def _extend_blocks(extend_node, blocks): diff --git a/sekizai/templatetags/sekizai_tags.py b/sekizai/templatetags/sekizai_tags.py index 8ae5607..82e5a65 100644 --- a/sekizai/templatetags/sekizai_tags.py +++ b/sekizai/templatetags/sekizai_tags.py @@ -29,12 +29,8 @@ def validate_context(context): try: template_debug = context.template.engine.debug except AttributeError: - try: - # Get the default engine debug value - template_debug = template.Engine.get_default().debug - except AttributeError: - # Django 1.9 and below fallback - template_debug = settings.TEMPLATE_DEBUG + # Get the default engine debug value + template_debug = template.Engine.get_default().debug if get_varname() in context: return True diff --git a/sekizai/tests.py b/sekizai/tests.py index 8e55f61..d02b1fb 100644 --- a/sekizai/tests.py +++ b/sekizai/tests.py @@ -8,8 +8,10 @@ from django import template from django.conf import settings from django.template.loader import render_to_string +from django.template.engine import Engine import pep8 +from sekizai import context_processors from sekizai.context import SekizaiContext from sekizai.helpers import get_namespaces from sekizai.helpers import get_varname @@ -171,57 +173,40 @@ def update_template_debug(debug=True): :return: SettingsOverride object """ - if django.VERSION[0] == 1 and django.VERSION[1] < 8: - return SettingsOverride(TEMPLATE_DEBUG=debug) - else: - # Create our overridden template settings with debug turned off. - templates_override = settings.TEMPLATES - templates_override[0]['OPTIONS'].update({ - 'debug': debug - }) - - from django.template.engine import Engine - # Engine gets created based on template settings initial value so - # changing the settings after the fact won't update, so do it - # manually. Necessary when testing validate_context - # with render method and want debug off. - Engine.get_default().debug = debug - return SettingsOverride(TEMPLATES=templates_override) + # Create our overridden template settings with debug turned off. + templates_override = settings.TEMPLATES + templates_override[0]['OPTIONS'].update({'debug': debug}) + # Engine gets created based on template settings initial value so + # changing the settings after the fact won't update, so do it + # manually. Necessary when testing validate_context + # with render method and want debug off. + Engine.get_default().debug = debug + return SettingsOverride(TEMPLATES=templates_override) class SekizaiTestCase(TestCase): - @classmethod - def setUpClass(cls): - cls._template_dirs = settings.TEMPLATE_DIRS - template_dir = os.path.join( - os.path.dirname(__file__), - 'test_templates' - ) - settings.TEMPLATE_DIRS = list(cls._template_dirs) + [template_dir] - - @classmethod - def tearDownClass(cls): - settings.TEMPLATE_DIRS = cls._template_dirs - def _render(self, tpl, ctx=None, ctxclass=SekizaiContext): - ctx = ctx or {} - return render_to_string(tpl, ctxclass(ctx)) + def _render(self, tpl, ctx=None, sekizai_context=True): + ctx = dict(ctx) if ctx else {} + if sekizai_context: + ctx.update(context_processors.sekizai()) + return render_to_string(tpl, ctx) - def _get_bits(self, tpl, ctx=None, ctxclass=SekizaiContext): + def _get_bits(self, tpl, ctx=None, sekizai_context=True): ctx = ctx or {} - rendered = self._render(tpl, ctx, ctxclass) + rendered = self._render(tpl, ctx, sekizai_context) bits = [ bit for bit in [bit.strip('\n') for bit in rendered.split('\n')] if bit ] return bits, rendered - def _test(self, tpl, res, ctx=None, ctxclass=SekizaiContext): + def _test(self, tpl, res, ctx=None, sekizai_context=True): """ Helper method to render template and compare it's bits """ ctx = ctx or {} - bits, rendered = self._get_bits(tpl, ctx, ctxclass) + bits, rendered = self._get_bits(tpl, ctx, sekizai_context) differ = BitDiff(res) result = differ.test(bits) self.assertTrue(result.status, result.message) @@ -267,10 +252,8 @@ def test_sekizai_context_required(self): Test that the template tags properly fail if not used with either SekizaiContext or the context processor. """ - self.assertRaises( - template.TemplateSyntaxError, - self._render, 'basic.html', {}, template.Context - ) + with self.assertRaises(template.TemplateSyntaxError): + self._render('basic.html', {}, sekizai_context=False) def test_complex_template_inheritance(self): """ @@ -383,7 +366,7 @@ def test_validate_context(self): self.assertEqual(validate_context(django_ctx), False) self.assertEqual(validate_context(sekizai_ctx), True) bits = ['some content', 'more content', 'final content'] - self._test('basic.html', bits, ctxclass=template.Context) + self._test('basic.html', bits, sekizai_context=False) def test_post_processor_null(self): bits = ['header', 'footer'] diff --git a/setup.py b/setup.py index 2891107..1df6515 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ zip_safe=False, include_package_data=True, install_requires=[ + 'django>=1.11', 'django-classy-tags>=0.3.1', ], test_suite='runtests.main', @@ -21,6 +22,9 @@ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Framework :: Django', + 'Framework :: Django :: 1.11', + 'Framework :: Django :: 2.0', + 'Framework :: Django :: 2.1', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', @@ -29,5 +33,6 @@ 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', ] )
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor