From 0ce7341dcc06debf3a4a7210a9bef85843062b7c Mon Sep 17 00:00:00 2001 From: Raffaele Salmaso Date: Mon, 19 Feb 2018 19:45:02 +0100 Subject: [PATCH] Move BuildAttrsCompat to wiki.compat --- src/wiki/compat.py | 21 +++++++++++++++++++++ src/wiki/core/compat.py | 18 ------------------ src/wiki/editors/markitup.py | 2 +- src/wiki/forms.py | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) delete mode 100644 src/wiki/core/compat.py diff --git a/src/wiki/compat.py b/src/wiki/compat.py index 83dd2629..81042f2d 100644 --- a/src/wiki/compat.py +++ b/src/wiki/compat.py @@ -1,3 +1,7 @@ +"""Abstraction layer to deal with Django related changes in order to keep +compatibility with several Django versions simultaneously.""" + + try: from django.urls import include, re_path as url except ImportError: @@ -5,5 +9,22 @@ except ImportError: __all__ = [ + 'BuildAttrsCompat', 'include', 'url' ] + + +# Django 1.11 Widget.build_attrs has a different signature, designed for the new +# template based rendering. The previous version was more useful for our needs, +# so we restore that version. +# When support for Django < 1.11 is dropped, we should look at using the +# new template based rendering, at which point this probably won't be needed at all. +class BuildAttrsCompat: + def build_attrs_compat(self, extra_attrs=None, **kwargs): + "Helper function for building an attribute dictionary." + attrs = self.attrs.copy() + if extra_attrs is not None: + attrs.update(extra_attrs) + if kwargs is not None: + attrs.update(kwargs) + return attrs diff --git a/src/wiki/core/compat.py b/src/wiki/core/compat.py deleted file mode 100644 index 087b6f40..00000000 --- a/src/wiki/core/compat.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Abstraction layer to deal with Django related changes in order to keep -compatibility with several Django versions simultaneously.""" - - -# Django 1.11 Widget.build_attrs has a different signature, designed for the new -# template based rendering. The previous version was more useful for our needs, -# so we restore that version. -# When support for Django < 1.11 is dropped, we should look at using the -# new template based rendering, at which point this probably won't be needed at all. -class BuildAttrsCompat: - def build_attrs_compat(self, extra_attrs=None, **kwargs): - "Helper function for building an attribute dictionary." - attrs = self.attrs.copy() - if extra_attrs is not None: - attrs.update(extra_attrs) - if kwargs is not None: - attrs.update(kwargs) - return attrs diff --git a/src/wiki/editors/markitup.py b/src/wiki/editors/markitup.py index 517925f3..0f10be62 100644 --- a/src/wiki/editors/markitup.py +++ b/src/wiki/editors/markitup.py @@ -4,7 +4,7 @@ from django.utils.encoding import force_text from django.utils.html import conditional_escape from django.utils.safestring import mark_safe -from wiki.core.compat import BuildAttrsCompat +from wiki.compat import BuildAttrsCompat from wiki.editors.base import BaseEditor diff --git a/src/wiki/forms.py b/src/wiki/forms.py index 304474ec..987c22fb 100644 --- a/src/wiki/forms.py +++ b/src/wiki/forms.py @@ -23,8 +23,8 @@ from django.utils.translation import gettext_lazy as _ from wiki import models from wiki.conf import settings +from wiki.compat import BuildAttrsCompat from wiki.core import permissions -from wiki.core.compat import BuildAttrsCompat from wiki.core.diff import simple_merge from wiki.core.plugins.base import PluginSettingsFormMixin from wiki.editors import getEditor -- 2.45.2