Upgrade to python 3.11. Update pre-commit. Small settings adjustments.

This commit is contained in:
Víðir Valberg Guðmundsson 2023-01-11 21:55:58 +01:00
parent e38bd56549
commit 26e06dfaea
12 changed files with 80 additions and 35 deletions

View file

@ -1,10 +1,7 @@
default_language_version: default_language_version:
python: python3 python: python3.11
exclude: ^.*\b(migrations)\b.*$
repos: repos:
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 rev: v4.4.0
hooks: hooks:
@ -18,21 +15,19 @@ repos:
- id: check-toml - id: check-toml
- id: end-of-file-fixer - id: end-of-file-fixer
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/pycqa/flake8 - repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 6.0.0 rev: 'v0.0.209'
hooks: hooks:
- id: flake8 - id: ruff
additional_dependencies: args:
- flake8-bugbear - --force-exclude
- flake8-comprehensions - --fix
- flake8-tidy-imports
args: [--max-line-length=88, --extend-exclude=src/project/settings/deployments/*]
- repo: https://github.com/asottile/reorder_python_imports - repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0 rev: v3.9.0
hooks: hooks:
- id: reorder-python-imports - id: reorder-python-imports
args: args:
- --py3-plus - --py310-plus
- --application-directories=.:src - --application-directories=.:src
exclude: migrations/ exclude: migrations/
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
@ -40,7 +35,7 @@ repos:
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: args:
- --py310-plus - --py311-plus
exclude: migrations/ exclude: migrations/
- repo: https://github.com/adamchainz/django-upgrade - repo: https://github.com/adamchainz/django-upgrade
rev: 1.12.0 rev: 1.12.0
@ -48,3 +43,21 @@ repos:
- id: django-upgrade - id: django-upgrade
args: args:
- --target-version=4.1 - --target-version=4.1
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
hooks:
- id: add-trailing-comma
args:
- --py36-plus
- repo: https://github.com/hadialqattan/pycln
rev: v2.1.2
hooks:
- id: pycln
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black

View file

@ -1,4 +1,4 @@
FROM python:3.10-slim-bullseye FROM python:3.11-slim-bullseye
ENV PYTHONFAULTHANDLER=1 \ ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \ PYTHONUNBUFFERED=1 \

View file

@ -18,6 +18,9 @@ setup_venv:
pre_commit_install: pre_commit_install:
venv/bin/pre-commit install venv/bin/pre-commit install
pre_commit_run_all:
venv/bin/pre-commit run --all-files
makemigrations: makemigrations:
${MANAGE_COMMAND} makemigrations ${EXTRA_ARGS} ${MANAGE_COMMAND} makemigrations ${EXTRA_ARGS}

View file

@ -37,7 +37,9 @@ class Transaction(CreatedModifiedAbstract):
""" """
account = models.ForeignKey( account = models.ForeignKey(
Account, on_delete=models.PROTECT, related_name="transactions" Account,
on_delete=models.PROTECT,
related_name="transactions",
) )
amount = MoneyField( amount = MoneyField(
verbose_name=_("amount"), verbose_name=_("amount"),
@ -61,7 +63,9 @@ class Order(CreatedModifiedAbstract):
description = models.CharField(max_length=1024, verbose_name=_("description")) description = models.CharField(max_length=1024, verbose_name=_("description"))
price = MoneyField( price = MoneyField(
verbose_name=_("price (excl. VAT)"), max_digits=16, decimal_places=2 verbose_name=_("price (excl. VAT)"),
max_digits=16,
decimal_places=2,
) )
vat = MoneyField(verbose_name=_("VAT"), max_digits=16, decimal_places=2) vat = MoneyField(verbose_name=_("VAT"), max_digits=16, decimal_places=2)

View file

@ -10,6 +10,6 @@ if __name__ == "__main__":
raise ImportError( raise ImportError(
"Couldn't import Django. Are you sure it's installed and " "Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you " "available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?" "forget to activate a virtual environment?",
) )
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)

View file

@ -19,8 +19,8 @@ class Member(User):
Membership.objects.filter( Membership.objects.filter(
user=models.OuterRef("pk"), user=models.OuterRef("pk"),
period=get_current_subscription_period().id, period=get_current_subscription_period().id,
) ),
) ),
) )
objects = QuerySet.as_manager() objects = QuerySet.as_manager()
@ -92,7 +92,8 @@ class Membership(CreatedModifiedAbstract):
) )
period = models.ForeignKey( period = models.ForeignKey(
"membership.SubscriptionPeriod", on_delete=models.PROTECT "membership.SubscriptionPeriod",
on_delete=models.PROTECT,
) )
def __str__(self): def __str__(self):

View file

@ -29,7 +29,8 @@ class Permission:
def persist_permission(self): def persist_permission(self):
content_type, _ = ContentType.objects.get_or_create( content_type, _ = ContentType.objects.get_or_create(
app_label=self.app_label, model=self.model app_label=self.app_label,
model=self.model,
) )
DjangoPermission.objects.get_or_create( DjangoPermission.objects.get_or_create(
content_type=content_type, content_type=content_type,

View file

@ -19,12 +19,15 @@ def get_subscription_periods() -> list[SubscriptionPeriod]:
def get_current_subscription_period() -> SubscriptionPeriod | None: def get_current_subscription_period() -> SubscriptionPeriod | None:
with contextlib.suppress(SubscriptionPeriod.DoesNotExist): with contextlib.suppress(SubscriptionPeriod.DoesNotExist):
return SubscriptionPeriod.objects.prefetch_related( return SubscriptionPeriod.objects.prefetch_related(
"membership_set", "membership_set__user" "membership_set",
"membership_set__user",
).get(period__contains=timezone.now()) ).get(period__contains=timezone.now())
def get_memberships( def get_memberships(
*, user: User | None = None, period: SubscriptionPeriod | None = None *,
user: User | None = None,
period: SubscriptionPeriod | None = None,
) -> Membership.QuerySet: ) -> Membership.QuerySet:
memberships = Membership.objects.select_related("membership_type").all() memberships = Membership.objects.select_related("membership_type").all()

View file

@ -53,7 +53,7 @@ def members_admin(request):
label=_("View"), label=_("View"),
url_name="admin-members-detail", url_name="admin-members-detail",
url_kwargs={"member_id": "id"}, url_kwargs={"member_id": "id"},
) ),
], ],
) )

View file

@ -17,7 +17,8 @@ DEBUG = env.bool("DEBUG", default=False)
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=["*"]) ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=["*"])
CSRF_TRUSTED_ORIGINS = env.list( CSRF_TRUSTED_ORIGINS = env.list(
"CSRF_TRUSTED_ORIGINS", default=["http://localhost:8000"] "CSRF_TRUSTED_ORIGINS",
default=["http://localhost:8000"],
) )
ADMINS = [tuple(x.split(":")) for x in env.list("DJANGO_ADMINS", default=[])] ADMINS = [tuple(x.split(":")) for x in env.list("DJANGO_ADMINS", default=[])]
@ -26,7 +27,7 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# Application definition # Application definition
INSTALLED_APPS = [ DJANGO_APPS = [
"django.contrib.admin", "django.contrib.admin",
"django.contrib.auth", "django.contrib.auth",
"django.contrib.contenttypes", "django.contrib.contenttypes",
@ -34,13 +35,24 @@ INSTALLED_APPS = [
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"django.contrib.sites", "django.contrib.sites",
]
THIRD_PARTY_APPS = [
"allauth", "allauth",
"allauth.account", "allauth.account",
]
LOCAL_APPS = [
"utils", "utils",
"accounting", "accounting",
"membership", "membership",
] ]
INSTALLED_APPS = [
*DJANGO_APPS,
*THIRD_PARTY_APPS,
*LOCAL_APPS,
]
DATABASES = {"default": env.dj_db_url("DATABASE_URL")} DATABASES = {"default": env.dj_db_url("DATABASE_URL")}
@ -68,9 +80,9 @@ TEMPLATES = [
"django.template.context_processors.request", "django.template.context_processors.request",
"django.contrib.auth.context_processors.auth", "django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages", "django.contrib.messages.context_processors.messages",
] ],
},
}, },
}
] ]
AUTHENTICATION_BACKENDS = ( AUTHENTICATION_BACKENDS = (
@ -101,7 +113,8 @@ SITE_ID = 1
LOGIN_REDIRECT_URL = "/" LOGIN_REDIRECT_URL = "/"
EMAIL_BACKEND = env.str( EMAIL_BACKEND = env.str(
"EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend" "EMAIL_BACKEND",
default="django.core.mail.backends.console.EmailBackend",
) )
DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL", default="") DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL", default="")
# Parse email URLs, e.g. "smtp://" # Parse email URLs, e.g. "smtp://"
@ -137,8 +150,11 @@ ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
ACCOUNT_USERNAME_REQUIRED = False ACCOUNT_USERNAME_REQUIRED = False
if DEBUG: if DEBUG:
INSTALLED_APPS += ["debug_toolbar"] INSTALLED_APPS += ["debug_toolbar", "django_browser_reload"]
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] MIDDLEWARE += [
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django_browser_reload.middleware.BrowserReloadMiddleware",
]
# Always show DDT in development for any IP, not just 127.0.0.1 or # Always show DDT in development for any IP, not just 127.0.0.1 or
# settings.INTERNAL_IPS. This is useful in a docker setup where the # settings.INTERNAL_IPS. This is useful in a docker setup where the
# requesting IP isn't static. # requesting IP isn't static.

View file

@ -26,6 +26,7 @@ urlpatterns = [
] ]
if settings.DEBUG: if settings.DEBUG:
urlpatterns += [ urlpatterns = [
path("__debug__/", include("debug_toolbar.urls")), path("__debug__/", include("debug_toolbar.urls")),
] path("__reload__/", include("django_browser_reload.urls")),
] + urlpatterns

View file

@ -9,6 +9,9 @@
{% for column in columns %} {% for column in columns %}
<th scope="col">{{ column }}</th> <th scope="col">{{ column }}</th>
{% endfor %} {% endfor %}
{% if row_actions %}
<th scope="col">{% trans "Actions" %}</th>
{% endif %}
</tr> </tr>
</thead> </thead>
{% for row in rows %} {% for row in rows %}