Skip to content

Commit

Permalink
Remove outdated django version comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Feb 23, 2024
1 parent be11bf1 commit cd9dccd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
2 changes: 0 additions & 2 deletions python/nav/django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@
'nav.django.legacy.LegacyCleanupMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
if django.VERSION[:2] == (1, 8): # Django <= 1.8
MIDDLEWARE_CLASSES = MIDDLEWARE

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
Expand Down
28 changes: 6 additions & 22 deletions python/nav/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,9 @@ class DictAsJsonField(models.TextField):
def db_type(self, connection):
return 'varchar'

if django.VERSION < (2,): # Django < 2.x
# pylint: disable=unused-argument
def from_db_value(self, value, expression, connection, context):
return self.to_python(value)

else:
# pylint: disable=unused-argument
def from_db_value(self, value, expression, connection):
return self.to_python(value)
# pylint: disable=unused-argument
def from_db_value(self, value, expression, connection):
return self.to_python(value)

def to_python(self, value):
if value:
Expand Down Expand Up @@ -128,15 +122,8 @@ def __init__(self, *args, **kwargs):
def db_type(self, connection):
return 'point'

if django.VERSION < (2,): # Django < 2.x

def from_db_value(self, value, expression, connection, context):
return self.to_python(value)

else:

def from_db_value(self, value, expression, connection):
return self.to_python(value)
def from_db_value(self, value, expression, connection):
return self.to_python(value)

def to_python(self, value):
if not value or isinstance(value, tuple):
Expand Down Expand Up @@ -196,10 +183,7 @@ def contribute_to_class(self, cls, name):
self.name = name
self.model = cls
self.cache_attr = "_%s_cache" % name
if django.VERSION[:2] == (1, 8): # Django <= 1.8
cls._meta.virtual_fields.append(self)
else:
cls._meta.private_fields.append(self)
cls._meta.private_fields.append(self)

if not cls._meta.abstract:
signals.pre_init.connect(self.instance_pre_init, sender=cls)
Expand Down

0 comments on commit cd9dccd

Please sign in to comment.