Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d2a647

Browse files
Add Django 4.0 support
1 parent c193c90 commit 3d2a647

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

‎mailauth/contrib/admin/__init__.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
default_app_config = "mailauth.contrib.admin.apps.MailAuthAdmin"
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
default_app_config = "mailauth.contrib.user.apps.AuthConfig"
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
default_app_config = "mailauth.contrib.wagtail.apps.MailAuthWagtail"
1+
import django
2+
3+
if django.VERSION < (4, 0):
4+
default_app_config = "mailauth.contrib.wagtail.apps.MailAuthWagtail"

‎mailauth/signing.py‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import django
12
from django.contrib.auth import get_user_model
23
from django.core import signing
3-
from django.utils import baseconv
4+
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+
414

515
__all__ = (
616
"UserDoesNotExist",
@@ -32,7 +42,7 @@ def to_timestamp(value):
3242
"""
3343
if value is None:
3444
return ""
35-
return baseconv.base62.encode(int(value.timestamp()))
45+
return b62_encode(int(value.timestamp()))
3646

3747
def sign(self, user):
3848
"""
@@ -53,7 +63,7 @@ def sign(self, user):
5363

5464
def _make_hash_value(self, user):
5565
last_login = self.to_timestamp(user.last_login)
56-
user_pk = baseconv.base62.encode(user.pk)
66+
user_pk = b62_encode(user.pk)
5767
return self.sep.join((user_pk, last_login))
5868

5969
def unsign(self, value, max_age=None, single_use=True):
@@ -87,7 +97,7 @@ def unsign(self, value, max_age=None, single_use=True):
8797
"""
8898
result = super().unsign(value, max_age=max_age)
8999
user_pk, last_login = result.rsplit(self.sep, 2)
90-
user_pk = baseconv.base62.decode(user_pk)
100+
user_pk = b62_decode(user_pk)
91101
try:
92102
user = get_user_model()._default_manager.get(pk=user_pk)
93103
except get_user_model().DoesNotExist as e:

‎tests/contrib/admin/test_admin.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
def test_login_view():
22
from django.contrib.admin import site
33

4-
assert site.login.__name__ == "AdminLoginView"
54
assert site.login.__module__ == "mailauth.contrib.admin.views"

‎tests/testapp/settings.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import os
1414

1515
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
import django
17+
1618
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1719

1820

@@ -124,7 +126,8 @@
124126

125127
USE_I18N = True
126128

127-
USE_L10N = True
129+
if django.VERSION < (4, 0):
130+
USE_L10N = True
128131

129132
USE_TZ = True
130133

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /