diff --git a/.github/contributors.json b/.github/contributors.json index 596f2af8..057309a5 100644 --- a/.github/contributors.json +++ b/.github/contributors.json @@ -1115,7 +1115,7 @@ "twitter_username": "Qoyyuum" }, { - "name": "mfosterw", + "name": "Matthew Foster Walsh", "github_login": "mfosterw", "twitter_username": "" }, diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py index 9d6c7562..d0d1488f 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/admin.py @@ -1,19 +1,17 @@ from django.conf import settings from django.contrib import admin from django.contrib.auth import admin as auth_admin -from django.contrib.auth import decorators -from django.contrib.auth import get_user_model +from django.contrib.auth.decorators import login_required from django.utils.translation import gettext_lazy as _ from {{ cookiecutter.project_slug }}.users.forms import UserAdminChangeForm from {{ cookiecutter.project_slug }}.users.forms import UserAdminCreationForm - -User = get_user_model() +from {{ cookiecutter.project_slug }}.users.models import User if settings.DJANGO_ADMIN_FORCE_ALLAUTH: # Force the `admin` sign in process to go through the `django-allauth` workflow: # https://docs.allauth.org/en/latest/common/admin.html#admin - admin.site.login = decorators.login_required(admin.site.login) # type: ignore[method-assign] + admin.site.login = login_required(admin.site.login) # type: ignore[method-assign] @admin.register(User) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/serializers.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/serializers.py index ef2adb91..51e0859f 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/serializers.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/serializers.py @@ -1,12 +1,9 @@ -from django.contrib.auth import get_user_model from rest_framework import serializers -from {{ cookiecutter.project_slug }}.users.models import User as UserType - -User = get_user_model() +from {{ cookiecutter.project_slug }}.users.models import User -class UserSerializer(serializers.ModelSerializer[UserType]): +class UserSerializer(serializers.ModelSerializer[User]): class Meta: model = User {%- if cookiecutter.username_type == "email" %} diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py index 8bdf24b0..7a521cdf 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/api/views.py @@ -1,4 +1,3 @@ -from django.contrib.auth import get_user_model from rest_framework import status from rest_framework.decorators import action from rest_framework.mixins import ListModelMixin @@ -7,9 +6,9 @@ from rest_framework.mixins import UpdateModelMixin from rest_framework.response import Response from rest_framework.viewsets import GenericViewSet -from .serializers import UserSerializer +from {{ cookiecutter.project_slug }}.users.models import User -User = get_user_model() +from .serializers import UserSerializer class UserViewSet(RetrieveModelMixin, ListModelMixin, UpdateModelMixin, GenericViewSet): diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/forms.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/forms.py index ac5b647d..2d18de20 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/forms.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/forms.py @@ -1,13 +1,12 @@ from allauth.account.forms import SignupForm from allauth.socialaccount.forms import SignupForm as SocialSignupForm from django.contrib.auth import forms as admin_forms -from django.contrib.auth import get_user_model {%- if cookiecutter.username_type == "email" %} from django.forms import EmailField {%- endif %} from django.utils.translation import gettext_lazy as _ -User = get_user_model() +from {{ cookiecutter.project_slug }}.users.models import User class UserAdminChangeForm(admin_forms.UserChangeForm): diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tasks.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tasks.py index c99341c5..ecd14d2a 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tasks.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tasks.py @@ -1,8 +1,5 @@ -from django.contrib.auth import get_user_model - from config import celery_app - -User = get_user_model() +from {{ cookiecutter.project_slug }}.users.models import User @celery_app.task() diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/factories.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/factories.py index f614681b..136d0b1d 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/factories.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/factories.py @@ -1,11 +1,12 @@ from collections.abc import Sequence from typing import Any -from django.contrib.auth import get_user_model from factory import Faker from factory import post_generation from factory.django import DjangoModelFactory +from {{ cookiecutter.project_slug }}.users.models import User + class UserFactory(DjangoModelFactory): {%- if cookiecutter.username_type == "username" %} @@ -38,5 +39,5 @@ class UserFactory(DjangoModelFactory): instance.save() class Meta: - model = get_user_model() + model = User django_get_or_create = ["{{cookiecutter.username_type}}"] diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py index 6d26e9c7..3f20f268 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py @@ -1,4 +1,3 @@ -from django.contrib.auth import get_user_model from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.messages.views import SuccessMessageMixin from django.urls import reverse @@ -7,7 +6,7 @@ from django.views.generic import DetailView from django.views.generic import RedirectView from django.views.generic import UpdateView -User = get_user_model() +from {{ cookiecutter.project_slug }}.users.models import User class UserDetailView(LoginRequiredMixin, DetailView):