From cf2677c7ba2c875d53df1556162983aa98d8dfa0 Mon Sep 17 00:00:00 2001 From: jpt Date: Sat, 5 Apr 2025 17:11:04 -0500 Subject: [PATCH] more config --- README.md | 35 ++++++++++++++++++++++++++++++ config/settings.py | 51 ++++++++++++++++++++++++++++++++++++++------ config/urls.py | 23 ++++++-------------- pyproject.toml | 1 + uv.lock | 53 +++++++++++++++++++++++++++++++++++++++------- 5 files changed, 133 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 3b9022b..a85cb37 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,38 @@ Ignored: - _staticfiles + +## Projects + +### environ + +Configured per instructions, used to set up settings. + +### whitenoise + +Configured per instructions. + +### django-typer + +minimal config; done + +### django-structlog + +TODO: needs defaults + +### django-allauth + +Configured for email login. + +### pytest-django + +??? + +### django-debug-toolbar + +Configured per instructions. + +## Options + +TODO: whitenoise Compression setting +TODO: prerolled Auth options diff --git a/config/settings.py b/config/settings.py index eddac90..1d8674e 100644 --- a/config/settings.py +++ b/config/settings.py @@ -19,6 +19,10 @@ DATABASES = {"default": env.db()} ALLOWED_HOSTS = [] +INTERNAL_IPS = ["127.0.0.1"] + +# Debug Toolbar +IS_TESTING = "test" in sys.argv # Static Settings ------ @@ -31,6 +35,11 @@ INSTALLED_APPS = [ "django.contrib.messages", "whitenoise.runserver_nostatic", "django.contrib.staticfiles", + "allauth", + "allauth.account", + "django_structlog", + "django_typer", + "debug_toolbar", ] MIDDLEWARE = [ @@ -42,8 +51,17 @@ MIDDLEWARE = [ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "django_structlog.middlewares.RequestMiddleware", + "allauth.account.middleware.AccountMiddleware", ] +if DEBUG and not IS_TESTING: + INSTALLED_APPS += "debug_toolbar" + MIDDLEWARE.insert( + 2, + "debug_toolbar.middleware.DebugToolbarMiddleware", + ) + TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", @@ -61,8 +79,19 @@ TEMPLATES = [ WSGI_APPLICATION = "config.wsgi.application" ROOT_URLCONF = "config.urls" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" +LANGUAGE_CODE = "en-us" +TIME_ZONE = "UTC" +USE_I18N = True +USE_TZ = True +# Authentication ----- + +AUTHENTICATION_BACKENDS = [ + "django.contrib.auth.backends.ModelBackend", + "allauth.account.auth_backends.AuthenticationBackend", +] + AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", @@ -78,12 +107,22 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] - -LANGUAGE_CODE = "en-us" -TIME_ZONE = "UTC" -USE_I18N = True -USE_TZ = True - +ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1 +ACCOUNT_EMAIL_VERIFICATION = "mandatory" +ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED = True +ACCOUNT_EMAIL_UNKNOWN_ACCOUNTS = False +ACCOUNT_LOGIN_BY_CODE_ENABLED = True +ACCOUNT_LOGIN_METHODS = {"email"} +ACCOUNT_LOGIN_ON_PASSWORD_RESET = True +ACCOUNT_PRESERVE_USERNAME_CASING = False +ACCOUNT_SIGNUP_FIELDS = ["email*", "password1*", "password2*"] +ACCOUNT_SIGNUP_FORM_HONEYPOT_FIELD = "user_name" +ACCOUNT_USERNAME_BLACKLIST = ["admin"] +ACCOUNT_USER_MODEL_USERNAME_FIELD = None +# ACCOUNT_SIGNUP_FORM_CLASS = "" +# ACCOUNT_EMAIL_SUBJECT_PREFIX = "[Site] " +# ACCOUNT_LOGIN_BY_CODE_REQUIRED = False +# ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https" # Static File Config (per whitenoise) ----- diff --git a/config/urls.py b/config/urls.py index 4dac845..e8e9f50 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,21 +1,12 @@ -""" -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.2/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" - +from django.conf import settings from django.contrib import admin -from django.urls import path +from django.urls import path, include +from debug_toolbar.toolbar import debug_toolbar_urls urlpatterns = [ path("admin/", admin.site.urls), + path("accounts/", include("allauth.urls")), ] + +if settings.DEBUG and not settings.IS_TESTING: + urlpatterns += debug_toolbar_urls() diff --git a/pyproject.toml b/pyproject.toml index 1f333f8..d59041b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ dependencies = [ "django-structlog>=9.1.0,<10", "django-typer>=3.1.0,<4", "pytest-django>=4.11.1,<5", + "rich>=14.0.0", "ruff>=0.11.4", "whitenoise>=6.9.0,<7", ] diff --git a/uv.lock b/uv.lock index 1125b84..6e09979 100644 --- a/uv.lock +++ b/uv.lock @@ -132,15 +132,11 @@ dependencies = [ { name = "django-structlog" }, { name = "django-typer" }, { name = "pytest-django" }, + { name = "rich" }, { name = "ruff" }, { name = "whitenoise" }, ] -[package.dev-dependencies] -dev = [ - { name = "ruff" }, -] - [package.metadata] requires-dist = [ { name = "django", specifier = ">=5.2,<6" }, @@ -150,13 +146,11 @@ requires-dist = [ { name = "django-structlog", specifier = ">=9.1.0,<10" }, { name = "django-typer", specifier = ">=3.1.0,<4" }, { name = "pytest-django", specifier = ">=4.11.1,<5" }, + { name = "rich", specifier = ">=14.0.0" }, { name = "ruff", specifier = ">=0.11.4" }, { name = "whitenoise", specifier = ">=6.9.0,<7" }, ] -[package.metadata.requires-dev] -dev = [{ name = "ruff", specifier = ">=0.11.4" }] - [[package]] name = "iniconfig" version = "2.1.0" @@ -166,6 +160,27 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/2c/e1/e6716421ea10d38022b952c159d5161ca1193197fb744506875fbb87ea7b/iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760", size = 6050 }, ] +[[package]] +name = "markdown-it-py" +version = "3.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mdurl" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/38/71/3b932df36c1a044d397a1f92d1cf91ee0a503d91e470cbd670aa66b07ed0/markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb", size = 74596 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/42/d7/1ec15b46af6af88f19b8e5ffea08fa375d433c998b8a7639e76935c14f1f/markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1", size = 87528 }, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979 }, +] + [[package]] name = "packaging" version = "24.2" @@ -184,6 +199,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/88/5f/e351af9a41f866ac3f1fac4ca0613908d9a41741cfcf2228f4ad853b697d/pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669", size = 20556 }, ] +[[package]] +name = "pygments" +version = "2.19.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7c/2d/c3338d48ea6cc0feb8446d8e6937e1408088a72a39937982cc6111d17f84/pygments-2.19.1.tar.gz", hash = "sha256:61c16d2a8576dc0649d9f39e089b5f02bcd27fba10d8fb4dcc28173f7a45151f", size = 4968581 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/8a/0b/9fcc47d19c48b59121088dd6da2488a49d5f72dacf8262e2790a1d2c7d15/pygments-2.19.1-py3-none-any.whl", hash = "sha256:9ea1544ad55cecf4b8242fab6dd35a93bbce657034b0611ee383099054ab6d8c", size = 1225293 }, +] + [[package]] name = "pytest" version = "8.3.5" @@ -220,6 +244,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/08/bd/ccd7416fdb30f104ddf6cfd8ee9f699441c7d9880a26f9b3089438adee05/python_ipware-3.0.0-py3-none-any.whl", hash = "sha256:fc936e6e7ec9fcc107f9315df40658f468ac72f739482a707181742882e36b60", size = 10761 }, ] +[[package]] +name = "rich" +version = "14.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markdown-it-py" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a1/53/830aa4c3066a8ab0ae9a9955976fb770fe9c6102117c8ec4ab3ea62d89e8/rich-14.0.0.tar.gz", hash = "sha256:82f1bc23a6a21ebca4ae0c45af9bdbc492ed20231dcb63f297d6d1021a9d5725", size = 224078 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0d/9b/63f4c7ebc259242c89b3acafdb37b41d1185c07ff0011164674e9076b491/rich-14.0.0-py3-none-any.whl", hash = "sha256:1c9491e1951aac09caffd42f448ee3d04e58923ffe14993f6e83068dc395d7e0", size = 243229 }, +] + [[package]] name = "ruff" version = "0.11.4"