Skip to content

Commit

Permalink
Delete deprecated argument (#42)
Browse files Browse the repository at this point in the history
* Delete deprecated argument

* Adds conditional assignment of function from_db_value depending on django version

* Cleaner solution

* Add django version code and import

* Change util to relative import

---------

Co-authored-by: Juan Alfaro <[email protected]>
  • Loading branch information
jfalfaro and Juan Alfaro authored Nov 22, 2024
1 parent fe68d29 commit ebae665
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
16 changes: 14 additions & 2 deletions djangocms_attributes_field/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions djangocms_attributes_field/utils.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit ebae665

Please sign in to comment.