diff --git a/djangocms_attributes_field/fields.py b/djangocms_attributes_field/fields.py index a30b52b..5f9e63a 100644 --- a/djangocms_attributes_field/fields.py +++ b/djangocms_attributes_field/fields.py @@ -9,6 +9,7 @@ from django.utils.html import conditional_escape, mark_safe from django.utils.translation import gettext_lazy as _ +from .utils import DJANGO_2_2 from .widgets import AttributesWidget regex_key_validator = RegexValidator(regex=r'^[a-z][-a-z0-9_:]*\Z', @@ -125,8 +126,19 @@ def formfield(self, **kwargs): defaults["excluded_keys"] = self.excluded_keys return super().formfield(**defaults) - def from_db_value(self, value, - expression=None, connection=None, context=None): + # This was added to keep backwards compatibility with Django 2.2 while also + # avoiding a RemovedInDjango30Warning caused by the deprecation of + # context argument + if DJANGO_2_2: + def from_db_value(self, value, + expression=None, connection=None, context=None): + self._from_db_value(value) + else: + def from_db_value(self, value, + expression=None, connection=None): + self._from_db_value(value) + + def _from_db_value(self, value): """ This is a temporary workaround for #7 taken from https://bitbucket.org/schinckel/django-jsonfield/pull-requests/32/make-from_db_value-compatible-with/diff diff --git a/djangocms_attributes_field/utils.py b/djangocms_attributes_field/utils.py new file mode 100644 index 0000000..e2f73ae --- /dev/null +++ b/djangocms_attributes_field/utils.py @@ -0,0 +1,11 @@ +from platform import python_version +from django import get_version + +from distutils.version import LooseVersion + + +DJANGO_VERSION = get_version() +PYTHON_VERSION = python_version() + +# These means "less than or equal to DJANGO_FOO_BAR" +DJANGO_2_2 = LooseVersion(DJANGO_VERSION) < LooseVersion('3.0')