Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Django 4 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion demo/demo/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.conf.urls import include, url
from django.conf.urls import include
from django.contrib import admin
from django.views.generic import TemplateView, RedirectView

from rest_framework_swagger.views import get_swagger_view

from rest_auth.four import url

urlpatterns = [
url(r'^$', TemplateView.as_view(template_name="home.html"), name='home'),
url(r'^signup/$', TemplateView.as_view(template_name="signup.html"),
Expand Down
17 changes: 17 additions & 0 deletions rest_auth/four.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
try:
from django.conf.urls import url
except ImportError:
# Compatibility for Django 4.
from django.urls import re_path as url

try:
from django.utils.translation import ugettext_lazy
except ImportError:
# Compatibility for Django 4.
from django.utils.translation import gettext_lazy as ugettext_lazy

try:
from django.utils.encoding import force_text
except ImportError:
# Compatibility for Django 4.
from django.utils.encoding import force_str as force_text
2 changes: 1 addition & 1 deletion rest_auth/registration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.http import HttpRequest
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model

try:
Expand All @@ -17,6 +16,7 @@
from rest_framework import serializers
from requests.exceptions import HTTPError

from rest_auth.four import ugettext_lazy as _

class SocialAccountSerializer(serializers.ModelSerializer):
"""
Expand Down
3 changes: 1 addition & 2 deletions rest_auth/registration/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from django.views.generic import TemplateView
from django.conf.urls import url

from .views import (
RegisterView,
VerifyEmailView,
ResendConfirmationEmailView,
)

from rest_auth.four import url

urlpatterns = [
url(r'^$', RegisterView.as_view(), name='rest_register'),
Expand Down
2 changes: 1 addition & 1 deletion rest_auth/registration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.conf import settings
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.debug import sensitive_post_parameters

from rest_framework.views import APIView
Expand All @@ -25,6 +24,7 @@
from rest_auth.app_settings import (TokenSerializer,
JWTSerializer,
create_token)
from rest_auth.four import ugettext_lazy as _
from rest_auth.models import TokenModel
from rest_auth.registration.serializers import (
VerifyEmailSerializer,
Expand Down
4 changes: 2 additions & 2 deletions rest_auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
from django.contrib.auth.tokens import default_token_generator
from django.utils.http import urlsafe_base64_decode as uid_decoder
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text

from rest_framework import serializers, exceptions
from rest_framework.exceptions import ValidationError

from .four import force_text
from .four import ugettext_lazy as _
from .models import TokenModel
from .utils import import_callable

Expand Down
2 changes: 1 addition & 1 deletion rest_auth/tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.conf import settings
from django.test.client import Client, MULTIPART_CONTENT
from django.utils.encoding import force_text

from rest_framework import status
from rest_framework import permissions
Expand All @@ -12,6 +11,7 @@
except ImportError:
from django.core.urlresolvers import reverse

from rest_auth.four import force_text

class CustomPermissionClass(permissions.BasePermission):
message = 'You shall not pass!'
Expand Down
2 changes: 1 addition & 1 deletion rest_auth/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from django.contrib.auth import get_user_model
from django.core import mail
from django.conf import settings
from django.utils.encoding import force_text

from allauth.account import app_settings as account_app_settings
from allauth.account.models import EmailAddress
from rest_framework import status
from rest_framework.test import APIRequestFactory

from rest_auth.four import force_text
from rest_auth.registration.views import RegisterView
from rest_auth.registration.app_settings import register_permission_classes

Expand Down
3 changes: 1 addition & 2 deletions rest_auth/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.conf.urls import url

from rest_auth.four import url
from rest_auth.views import (
LoginView, LogoutView, UserDetailsView, PasswordChangeView,
PasswordResetView, PasswordResetConfirmView
Expand Down
2 changes: 1 addition & 1 deletion rest_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.contrib.auth.signals import user_logged_in
from django.core.exceptions import ObjectDoesNotExist
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.debug import sensitive_post_parameters

from rest_framework import status
Expand All @@ -21,6 +20,7 @@
PasswordResetSerializer, PasswordResetConfirmSerializer,
PasswordChangeSerializer, JWTSerializer, create_token
)
from .four import ugettext_lazy as _
from .models import TokenModel
from .utils import jwt_encode

Expand Down