Upgrade CC-Dj 2023-05-16 C / Custom User

This commit is contained in:
Alejandro Franco 2023-05-16 12:45:53 -06:00
parent 5b84e42ad2
commit b84bf7b24d
10 changed files with 9 additions and 22 deletions

View File

@ -119,10 +119,6 @@ Answer the prompts with your own desired [options](http://cookiecutter-django.re
4 - Apache Software License 2.0
5 - Not open source
Choose from 1, 2, 3, 4, 5 [1]: 1
Select username_type: # NOT USED FOR THIS TEMPLATE
1 - username
2 - email
Choose from 1, 2 [1]: 1
timezone [UTC]: America/Los_Angeles
windows [n]: n
use_pycharm [n]: y

View File

@ -13,7 +13,6 @@
"Apache Software License 2.0",
"Not open source"
],
"username_type": ["email"],
"timezone": "UTC",
"windows": "n",
"use_pycharm": "n",

View File

@ -24,13 +24,6 @@ author_name:
email:
The email address you want to identify yourself in the project.
username_type:
The type of username you want to use in the project. This can be either
``username`` or ``email``. If you choose ``username``, the ``email`` field
will be included. If you choose ``email``, the ``username`` field will be
excluded. It is best practice to always include an email field, so there is
no option for having just the ``username`` field.
domain_name:
The domain name you plan to use for your project once it goes live.
Note that it can be safely changed later on whenever you need to.

View File

@ -426,9 +426,6 @@ def main():
if "{{ cookiecutter.open_source_license}}" != "GPLv3":
remove_gplv3_files()
# if "{{ cookiecutter.username_type }}" == "username":
# remove_custom_user_manager_files()
if "{{ cookiecutter.use_pycharm }}".lower() == "n":
remove_pycharm_files()

View File

@ -43,8 +43,6 @@ def context():
SUPPORTED_COMBINATIONS = [
{"username_type": "username"},
{"username_type": "email"},
{"open_source_license": "MIT"},
{"open_source_license": "BSD"},
{"open_source_license": "GPLv3"},

View File

@ -1,3 +1,4 @@
import uuid
from django.contrib.auth import get_user_model
from rest_framework import status
from rest_framework.decorators import action
@ -16,8 +17,8 @@ class UserViewSet(RetrieveModelMixin, ListModelMixin, UpdateModelMixin, GenericV
lookup_field = "uuid"
def get_queryset(self, *args, **kwargs):
assert isinstance(self.request.user.id, int)
return self.queryset.filter(id=self.request.user.id)
assert isinstance(self.request.user.uuid, uuid.UUID)
return self.queryset.filter(uuid=self.request.user.uuid)
@action(detail=False)
def me(self, request):

View File

@ -8,7 +8,8 @@ from factory.django import DjangoModelFactory
class UserFactory(DjangoModelFactory):
email = Faker("email")
name = Faker("name")
first_name = Faker("name")
last_name = Faker("name")
@post_generation
def password(self, create: bool, extracted: Sequence[Any], **kwargs):

View File

@ -30,6 +30,6 @@ class TestUserViewSet:
assert response.data == {
"email": user.uuid,
"name": user.first_name,
"first_name": user.first_name,
"url": f"http://testserver/api/users/{user.uuid}/",
}

View File

@ -25,6 +25,8 @@ class TestUserAdminCreationForm:
form = UserAdminCreationForm(
{
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
"password1": user.password,
"password2": user.password,
}

View File

@ -5,7 +5,7 @@ from {{ cookiecutter.project_slug }}.users.models import User
def test_detail(user: User):
assert (
reverse("users:detail", kwargs={"username": user.uuid})
reverse("users:detail", kwargs={"uuid": user.uuid})
== f"/users/{user.uuid}/"
)
assert resolve(f"/users/{user.uuid}/").view_name == "users:detail"