From cf3c84b8d9794013cb562c843e42314543b3d381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Thu, 29 Feb 2024 21:30:11 +0100 Subject: [PATCH] More linting. --- src/accounting/models.py | 4 ++-- src/accounting/tests.py | 2 +- src/membership/__init__.py | 2 +- src/membership/apps.py | 2 +- src/membership/models.py | 6 +++--- src/membership/permissions.py | 6 +++--- src/project/urls.py | 5 +++-- src/utils/templatetags/utils.py | 1 + src/utils/view_utils.py | 5 ++++- 9 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/accounting/models.py b/src/accounting/models.py index c6d1362..9db46eb 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -88,7 +88,7 @@ class Order(CreatedModifiedAbstract): verbose_name = pgettext_lazy("accounting term", "Order") verbose_name_plural = pgettext_lazy("accounting term", "Orders") - def __str__(self): + def __str__(self) -> str: return f"Order ID {self.display_id}" @@ -113,7 +113,7 @@ class Payment(CreatedModifiedAbstract): description=order.description, ) - def __str__(self): + def __str__(self) -> str: return f"Payment ID {self.display_id}" class Meta: diff --git a/src/accounting/tests.py b/src/accounting/tests.py index 0aebd0c..d2ab2bd 100644 --- a/src/accounting/tests.py +++ b/src/accounting/tests.py @@ -9,7 +9,7 @@ from . import models @pytest.mark.django_db() -def test_balance(): +def test_balance() -> None: user = User.objects.create_user("test", "lala@adas.com", "1234") account = models.Account.objects.create(owner=user) assert account.balance == 0 diff --git a/src/membership/__init__.py b/src/membership/__init__.py index f9e27aa..f5e828a 100644 --- a/src/membership/__init__.py +++ b/src/membership/__init__.py @@ -1,4 +1,4 @@ -"""Membership application +"""Membership application. ====================== This application's domain relate to organizational structures and diff --git a/src/membership/apps.py b/src/membership/apps.py index 5248df4..b8459a2 100644 --- a/src/membership/apps.py +++ b/src/membership/apps.py @@ -5,7 +5,7 @@ from django.db.models.signals import post_migrate class MembershipConfig(AppConfig): name = "membership" - def ready(self): + def ready(self) -> None: from .permissions import persist_permissions post_migrate.connect(persist_permissions, sender=self) diff --git a/src/membership/models.py b/src/membership/models.py index d61e157..730133f 100644 --- a/src/membership/models.py +++ b/src/membership/models.py @@ -48,7 +48,7 @@ class SubscriptionPeriod(CreatedModifiedAbstract): ), ] - def __str__(self): + def __str__(self) -> str: return f"{self.period.lower} - {self.period.upper or _('next general assembly')}" @@ -94,7 +94,7 @@ class Membership(CreatedModifiedAbstract): on_delete=models.PROTECT, ) - def __str__(self): + def __str__(self) -> str: return f"{self.user} - {self.period}" @@ -109,5 +109,5 @@ class MembershipType(CreatedModifiedAbstract): name = models.CharField(verbose_name=_("name"), max_length=64) - def __str__(self): + def __str__(self) -> str: return self.name diff --git a/src/membership/permissions.py b/src/membership/permissions.py index 804bcef..657adcb 100644 --- a/src/membership/permissions.py +++ b/src/membership/permissions.py @@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _ PERMISSIONS = [] -def persist_permissions(sender, **kwargs): +def persist_permissions(sender, **kwargs) -> None: for permission in PERMISSIONS: permission.persist_permission() @@ -23,10 +23,10 @@ class Permission: PERMISSIONS.append(self) @property - def path(self): + def path(self) -> str: return f"{self.app_label}.{self.codename}" - def persist_permission(self): + def persist_permission(self) -> None: content_type, _ = ContentType.objects.get_or_create( app_label=self.app_label, model=self.model, diff --git a/src/project/urls.py b/src/project/urls.py index 17e788b..8de19c6 100644 --- a/src/project/urls.py +++ b/src/project/urls.py @@ -1,4 +1,4 @@ -"""URLs for the membersystem""" +"""URLs for the membersystem.""" from django.conf import settings from django.contrib import admin from django.urls import include @@ -15,4 +15,5 @@ if settings.DEBUG: urlpatterns = [ path("__debug__/", include("debug_toolbar.urls")), path("__reload__/", include("django_browser_reload.urls")), - ] + urlpatterns + *urlpatterns, + ] diff --git a/src/utils/templatetags/utils.py b/src/utils/templatetags/utils.py index 8050639..90ab6ef 100644 --- a/src/utils/templatetags/utils.py +++ b/src/utils/templatetags/utils.py @@ -18,3 +18,4 @@ def active_path(context, path_name, class_name) -> str | None: if is_path or is_base_path: return class_name + return None diff --git a/src/utils/view_utils.py b/src/utils/view_utils.py index b48d126..3de84c3 100644 --- a/src/utils/view_utils.py +++ b/src/utils/view_utils.py @@ -1,17 +1,20 @@ import contextlib from dataclasses import dataclass +from typing import TYPE_CHECKING from typing import Any from django.contrib.sites.shortcuts import get_current_site from django.core.exceptions import FieldError from django.core.paginator import Paginator -from django.db.models import Model from django.http import HttpRequest from django.http import HttpResponse from django.urls import reverse from zen_queries import queries_disabled from zen_queries import render as zen_queries_render +if TYPE_CHECKING: + from django.db.models import Model + @dataclass class Row: