Skip to content

Commit afa829f

Browse files
committed
Remove Django EOL version copat code
1 parent 2b16b8c commit afa829f

File tree

8 files changed

+4
-39
lines changed

8 files changed

+4
-39
lines changed

mailauth/contrib/admin/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
import django
2-
3-
if django.VERSION < (4, 0):
4-
default_app_config = "mailauth.contrib.admin.apps.MailAuthAdmin"

mailauth/contrib/user/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
import django
2-
3-
if django.VERSION < (4, 0):
4-
default_app_config = "mailauth.contrib.user.apps.AuthConfig"

mailauth/contrib/wagtail/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
import django
2-
3-
if django.VERSION < (4, 0):
4-
default_app_config = "mailauth.contrib.wagtail.apps.MailAuthWagtail"

mailauth/signing.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import django
21
from django.contrib.auth import get_user_model
32
from django.core import signing
43

5-
if django.VERSION >= (4, 0):
6-
b62_encode = signing.b62_encode
7-
b62_decode = signing.b62_decode
8-
else:
9-
from django.utils import baseconv
10-
11-
b62_encode = baseconv.base62.encode
12-
b62_decode = baseconv.base62.decode
13-
14-
154
__all__ = (
165
"UserDoesNotExist",
176
"UserSigner",
@@ -39,7 +28,7 @@ def to_timestamp(value):
3928
"""
4029
if value is None:
4130
return ""
42-
return b62_encode(int(value.timestamp()))
31+
return signing.b62_encode(int(value.timestamp()))
4332

4433
def sign(self, user):
4534
"""
@@ -60,7 +49,7 @@ def sign(self, user):
6049

6150
def _make_hash_value(self, user):
6251
last_login = self.to_timestamp(user.last_login)
63-
user_pk = b62_encode(user.pk)
52+
user_pk = signing.b62_encode(user.pk)
6453
return self.sep.join((user_pk, last_login))
6554

6655
def unsign(self, value, max_age=None, single_use=True):
@@ -94,7 +83,7 @@ def unsign(self, value, max_age=None, single_use=True):
9483
"""
9584
result = super().unsign(value, max_age=max_age)
9685
user_pk, last_login = result.rsplit(self.sep, 2)
97-
user_pk = b62_decode(user_pk)
86+
user_pk = signing.b62_decode(user_pk)
9887
try:
9988
user = get_user_model()._default_manager.get(pk=user_pk)
10089
except get_user_model().DoesNotExist as e:

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ keywords = django, otp, password, email
2828
include_package_data = True
2929
packages = find:
3030
install_requires =
31-
django>=2.2
31+
django>=4.0
3232
setup_requires =
3333
setuptools_scm
3434
sphinx

tests/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import django
21
import pytest
32
from django.contrib.auth import get_user_model
43
from django.utils import timezone
@@ -37,8 +36,6 @@ def admin_user(db):
3736
@pytest.fixture()
3837
def signature():
3938
"""Return a signature matching the user fixture."""
40-
if django.VERSION < (3, 1):
41-
return "LZ:173QUS:1Hjptg:umUR9iKN1rxDezT-dZGwqcqsM5Y"
4239
return "LZ:173QUS:1Hjptg:6oq5DS1NJ7SxJ1o-CpfgaqrImVaRpkcHrzV9yltwcHM"
4340

4441

tests/contrib/auth/test_models.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import django
21
import pytest
32
from django.core.exceptions import FieldDoesNotExist
43

@@ -29,14 +28,12 @@ def test_get_session_auth_hash__unique(self, db):
2928

3029
assert spiderman.get_session_auth_hash() != ironman.get_session_auth_hash()
3130

32-
@pytest.mark.skipif(django.VERSION < (3, 1), reason="requires Django 3.1 or higher")
3331
def test_legacy_get_session_auth_hash__default(self, db):
3432
user = EmailUser(email="spiderman@avengers.com")
3533

3634
assert user.session_salt
3735
assert user._legacy_get_session_auth_hash()
3836

39-
@pytest.mark.skipif(django.VERSION < (3, 1), reason="requires Django 3.1 or higher")
4037
def test_legacy_get_session_auth_hash__value_error(self, db):
4138
user = EmailUser(email="spiderman@avengers.com", session_salt=None)
4239

@@ -45,7 +42,6 @@ def test_legacy_get_session_auth_hash__value_error(self, db):
4542

4643
assert "'session_salt' must be set" in str(e.value)
4744

48-
@pytest.mark.skipif(django.VERSION < (3, 1), reason="requires Django 3.1 or higher")
4945
def test_legacy_get_session_auth_hash__unique(self, db):
5046
spiderman = EmailUser(email="spiderman@avengers.com")
5147
ironman = EmailUser(email="ironman@avengers.com")

tests/testapp/settings.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import os
1414

1515
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16-
import django
1716

1817
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1918

@@ -125,10 +124,6 @@
125124
TIME_ZONE = "UTC"
126125

127126
USE_I18N = True
128-
129-
if django.VERSION < (4, 0):
130-
USE_L10N = True
131-
132127
USE_TZ = True
133128

134129

0 commit comments

Comments
 (0)