diff --git a/.github/contributors.json b/.github/contributors.json index 50b2820f7..b135fe90f 100644 --- a/.github/contributors.json +++ b/.github/contributors.json @@ -1639,4 +1639,4 @@ "github_login": "mcastle", "twitter_username": "" } -] +] \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 562c5f500..91d08b1d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,8 +74,8 @@ jobs: args: "frontend_pipeline=Gulp" - name: Webpack args: "frontend_pipeline=Webpack use_heroku=y" - - name: Email - args: "ci_tool=Github project_name='Something superduper long - the great amazing project' project_slug=my_awesome_project" + - name: Email Username + args: "username_type=email ci_tool=Github project_name='Something superduper long - the great amazing project' project_slug=my_awesome_project" name: "Bare metal ${{ matrix.script.name }}" runs-on: ubuntu-latest diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a19e230b2..b913b67f3 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -2317,4 +2317,4 @@ guidance and advice. - Jannis Leidel - Nate Aune -- Barry Morrison +- Barry Morrison \ No newline at end of file diff --git a/README.md b/README.md index 8afb48195..879b2b2cf 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,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 Select an editor to use. The choices are: diff --git a/cookiecutter.json b/cookiecutter.json index e0bca40b5..ca33a455b 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", "editor": ["None", "PyCharm", "VS Code"], @@ -38,7 +39,6 @@ "use_sentry": "n", "use_whitenoise": "n", "use_heroku": "n", - "username_type": ["email"], "ci_tool": ["None", "Travis", "Gitlab", "Github", "Drone"], "keep_local_envs_in_vcs": "y", "debug": "n" diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 818922723..21059d3a2 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 80a6c0bd8..9e9af5f2d 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -449,8 +449,8 @@ def main(): if "{{ cookiecutter.open_source_license}}" != "GPLv3": remove_gplv3_files() - # if "{{ cookiecutter.username_type }}" == "username": - # remove_custom_user_manager_files() + if "{{ cookiecutter.username_type }}" == "username": + remove_custom_user_manager_files() if "{{ cookiecutter.editor }}" != "PyCharm": remove_pycharm_files() diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index 30af1a4ea..9669d78ba 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -43,6 +43,7 @@ def context(): SUPPORTED_COMBINATIONS = [ + {"username_type": "username"}, {"username_type": "email"}, {"open_source_license": "MIT"}, {"open_source_license": "BSD"}, diff --git a/{{cookiecutter.project_slug}}/compose/production/django/entrypoint b/{{cookiecutter.project_slug}}/compose/production/django/entrypoint index bf1a6696c..dd07f2d2a 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/entrypoint +++ b/{{cookiecutter.project_slug}}/compose/production/django/entrypoint @@ -7,8 +7,7 @@ set -o nounset {% if cookiecutter.use_celery == 'y' %} # N.B. If only .env files supported variable expansion... - export CELERY_BROKER_URL="${REDIS_URL}" -# Updated in .envs +export CELERY_BROKER_URL="${REDIS_URL}" {% endif %} if [ -z "${POSTGRES_USER}" ]; then @@ -16,7 +15,6 @@ if [ -z "${POSTGRES_USER}" ]; then export POSTGRES_USER="${base_postgres_image_default_user}" fi export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" -# Updated in .envs python << END import sys diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index 0cb095284..8b6cd5148 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -325,13 +325,15 @@ CELERY_TASK_SEND_SENT_EVENT = True # ------------------------------------------------------------------------------ ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True) # https://docs.allauth.org/en/latest/account/configuration.html -ACCOUNT_AUTHENTICATION_METHOD = "email" +ACCOUNT_AUTHENTICATION_METHOD = "{{cookiecutter.username_type}}" # https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_EMAIL_REQUIRED = True +{%- if cookiecutter.username_type == "email" %} # https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_USERNAME_REQUIRED = False # https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_USER_MODEL_USERNAME_FIELD = None +{%- endif %} # https://docs.allauth.org/en/latest/account/configuration.html ACCOUNT_EMAIL_VERIFICATION = "mandatory" # https://docs.allauth.org/en/latest/account/configuration.html diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 7d8256934..98a883b62 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -41,12 +41,12 @@ django_settings_module = "config.settings.test" # ==== djLint ==== [tool.djlint] -blank_line_after_tag = "load,extends,endblock" +blank_line_after_tag = "load,extends" close_void_tags = true -format_css = false -format_js = false +format_css = true +format_js = true # TODO: remove T002 when fixed https://github.com/djlint/djLint/issues/687 -ignore = "H006,H030,H031,T002,H020,H023,H033,D018" +ignore = "H006,H030,H031,T002" include = "H017,H035" indent = 2 max_line_length = 119 @@ -65,10 +65,6 @@ extend-exclude = [ "*/migrations/*.py", "staticfiles/*", ] -# Same as Django: https://github.com/cookiecutter/cookiecutter-django/issues/4792. -line-length = 88 -indent-width = 4 -target-version = "py312" [tool.ruff.lint] select = [ diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index 03220b9c8..f4c8124e1 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -52,5 +52,5 @@ django-webpack-loader==3.1.1 # https://github.com/django-webpack/django-webpack # Project # ------------------------------------------------------------------------------ -fontawesomefree==6.5.2 # https://github.com/FortAwesome/Font-Awesome -django-import-export==4.0.8 # https://github.com/django-import-export/django-import-export +fontawesomefree==6.6.0 # https://github.com/FortAwesome/Font-Awesome +django-import-export==4.1.1 # https://github.com/django-import-export/django-import-export diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/users/user_detail.html b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/users/user_detail.html index 458d180bf..ab9c70e66 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/users/user_detail.html +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/users/user_detail.html @@ -4,7 +4,11 @@ {% block title %} User: {% endraw %} + {% if cookiecutter.username_type == "email" %} {% raw %}{{ object.first_name }}{% endraw %} + {% else %} + {% raw %}{{ object.username }}{% endraw %} + {% endif %} {% raw %} {% endblock title %} {% block content %} @@ -13,11 +17,20 @@
{{ object.first_name }}
+ {%- endraw %} + {%- endif %}