diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 714cd8ac..8100270b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: matrix: script: - name: Basic - args: "" + args: "ci_tool=Gitlab" - name: Celery & DRF args: "use_celery=y use_drf=y" - name: Gulp @@ -73,7 +73,9 @@ jobs: - name: Gulp args: "frontend_pipeline=Gulp" - name: Webpack - args: "frontend_pipeline=Webpack" + args: "frontend_pipeline=Webpack use_heroku=y" + - name: Email Username + args: "username_type=email ci_tool=Github" name: "Bare metal ${{ matrix.script.name }}" runs-on: ubuntu-latest diff --git a/README.md b/README.md index 10bf57c2..4216c2d4 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,10 @@ 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: + 1 - username + 2 - email + Choose from 1, 2 [1]: 1 timezone [UTC]: America/Los_Angeles windows [n]: n use_pycharm [n]: y diff --git a/cookiecutter.json b/cookiecutter.json index b24ce428..c9ad1939 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -13,6 +13,7 @@ "Apache Software License 2.0", "Not open source" ], + "username_type": ["username", "email"], "timezone": "UTC", "windows": "n", "use_pycharm": "n", diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 9b379f12..a1d78817 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -24,6 +24,13 @@ 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. diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index b28bb016..22cda531 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -45,6 +45,24 @@ def remove_gplv3_files(): os.remove(file_name) +def remove_custom_user_manager_files(): + os.remove( + os.path.join( + "{{cookiecutter.project_slug}}", + "users", + "managers.py", + ) + ) + os.remove( + os.path.join( + "{{cookiecutter.project_slug}}", + "users", + "tests", + "test_managers.py", + ) + ) + + def remove_pycharm_files(): idea_dir_path = ".idea" if os.path.exists(idea_dir_path): @@ -441,6 +459,9 @@ 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() diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index eb6c4710..cb5a99cd 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -36,6 +36,8 @@ def context(): SUPPORTED_COMBINATIONS = [ + {"username_type": "username"}, + {"username_type": "email"}, {"open_source_license": "MIT"}, {"open_source_license": "BSD"}, {"open_source_license": "GPLv3"}, diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index 441fe4a2..dbb396c6 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -312,9 +312,15 @@ CELERY_TASK_SEND_SENT_EVENT = True # ------------------------------------------------------------------------------ ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True) # https://django-allauth.readthedocs.io/en/latest/configuration.html -ACCOUNT_AUTHENTICATION_METHOD = "username" +ACCOUNT_AUTHENTICATION_METHOD = "{{cookiecutter.username_type}}" # https://django-allauth.readthedocs.io/en/latest/configuration.html ACCOUNT_EMAIL_REQUIRED = True +{%- if cookiecutter.username_type == "email" %} +# https://django-allauth.readthedocs.io/en/latest/configuration.html +ACCOUNT_USERNAME_REQUIRED = False +# https://django-allauth.readthedocs.io/en/latest/configuration.html +ACCOUNT_USER_MODEL_USERNAME_FIELD = None +{%- endif %} # https://django-allauth.readthedocs.io/en/latest/configuration.html ACCOUNT_EMAIL_VERIFICATION = "mandatory" # https://django-allauth.readthedocs.io/en/latest/configuration.html diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html index 05cc449d..ad51a6e1 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html @@ -92,8 +92,7 @@ {% if request.user.is_authenticated %}