Skip to content

Commit

Permalink
fixup! fixup! [WIP] pre-commit and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Jan 6, 2025
1 parent d93cb58 commit ec91456
Show file tree
Hide file tree
Showing 47 changed files with 189 additions and 140 deletions.
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ select = [
"E",
# https://docs.astral.sh/ruff/rules/#pyflakes-f
"F",
# https://docs.astral.sh/ruff/rules/#isort-i
"I",
]
ignore = [
# Whitespace before ':' (conflicts with Black)
Expand Down
4 changes: 3 additions & 1 deletion src/open_inwoner/accounts/gateways.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def send(self, to, token, **kwargs):
)
except messagebird.client.ErrorException as e:
for error in e.errors:
logger.critical(f"Could not send SMS to {to}:\n{error}")
logger.critical(
("Could not send SMS to {to}:\n{error}").format(to=to, error=error)
)
raise GatewayError()
else:
logging.debug('Sent SMS to %s: "%s"', to, self.get_message(token))
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/accounts/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_by_kvk(self, kvk):

def eherkenning_create(self, kvk, **kwargs):
return super().create(
email=f"user-{kvk}@localhost",
email="user-{}@localhost".format(kvk),
login_type=LoginTypeChoices.eherkenning,
kvk=kvk,
)
Expand Down
6 changes: 4 additions & 2 deletions src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def get_callback_view(self):

def generate_uuid_image_name(instance, filename):
filename, file_extension = os.path.splitext(filename)
return f"profile/{uuid4()}{file_extension.lower()}"
return "profile/{uuid}{file_extension}".format(
uuid=uuid4(), file_extension=file_extension.lower()
)


class User(AbstractBaseUser, PermissionsMixin):
Expand Down Expand Up @@ -881,7 +883,7 @@ def get_full_name(self):
"""
Returns the first_name plus the last_name of the invitee, with a space in between.
"""
full_name = f"{self.invitee_first_name} {self.invitee_last_name}"
full_name = "{} {}".format(self.invitee_first_name, self.invitee_last_name)
return full_name.strip()

def save(self, **kwargs):
Expand Down
3 changes: 1 addition & 2 deletions src/open_inwoner/accounts/notifications/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import Callable
from typing import Any
from typing import Any, Callable

import celery

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_send_emails_about_expiring_actions(self):

email1, email2 = mail.outbox

for email, recipient in zip([email1, email2], [joe, schmoe], strict=False):
for email, recipient in zip([email1, email2], [joe, schmoe]):
self.assertEqual(
email.subject, "Acties verlopen vandaag op Open Inwoner Platform"
)
Expand Down
3 changes: 1 addition & 2 deletions src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from collections.abc import Iterable
from typing import Protocol
from typing import Iterable, Protocol

from django.contrib.auth.mixins import AccessMixin
from django.core.exceptions import ImproperlyConfigured
Expand Down
8 changes: 4 additions & 4 deletions src/open_inwoner/accounts/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def form_valid(self, form):
else:
self.log_user_action(
user,
f"SMS bericht met code is verzonden aan {user.phonenumber}",
"SMS bericht met code is verzonden aan {}".format(user.phonenumber),
)

messages.debug(self.request, gateway.get_message(token))
Expand Down Expand Up @@ -255,7 +255,7 @@ def post(self, request):
else:
self.log_user_action(
user,
f"SMS bericht met code is verzonden aan {user.phonenumber}",
"SMS bericht met code is verzonden aan {}".format(user.phonenumber),
)

messages.debug(self.request, gateway.get_message(token))
Expand Down Expand Up @@ -333,7 +333,7 @@ def render_next_step(self, form, **kwargs):

self.log_user_action(
self.user_cache,
f"SMS bericht met code is verzonden aan {phonenumber}",
"SMS bericht met code is verzonden aan {}".format(phonenumber),
)

return super().render_next_step(form, **kwargs)
Expand All @@ -345,7 +345,7 @@ def done(self, form_list, **kwargs):
self.request.user = self.user_cache
self.log_change(
self.user_cache,
f"Telefoonnummer gewijzigd: {phonenumber}",
"Telefoonnummer gewijzigd: {}".format(phonenumber),
)

self.user_cache.save()
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from collections.abc import Sequence
from typing import Sequence

from django.urls import reverse
from django.utils.functional import cached_property
Expand Down
9 changes: 5 additions & 4 deletions src/open_inwoner/cms/cases/views/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import enum
import functools
import logging
from collections.abc import Callable
from dataclasses import dataclass
from typing import TypedDict
from typing import Callable, TypedDict

from django.http import HttpRequest
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -226,7 +225,9 @@ def resolve_cases(
case = futures[task]["case"]
group = futures[task]["api_group"]
logger.exception(
f"Error while resolving case {case} with API group {group}"
"Error while resolving case {case} with API group {group}".format(
case=case, group=group
)
)

return resolved_cases
Expand Down Expand Up @@ -264,7 +265,7 @@ def resolve_case(self, case: Zaak, group: ZGWApiGroupConfig) -> Zaak:
):
try:
update_case = task.result()
if callable(update_case):
if hasattr(update_case, "__call__"):
update_case(case)
except BaseException:
logger.exception("Error in resolving case", stack_info=True)
Expand Down
33 changes: 21 additions & 12 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import datetime as dt
import logging
from collections import defaultdict
from collections.abc import Iterable
from datetime import datetime
from typing import Protocol
from typing import Iterable, Protocol

from django.conf import settings
from django.contrib import messages
Expand Down Expand Up @@ -317,7 +316,7 @@ def get_second_status_preview(self, statustypen: list) -> StatusType | None:
# only 1 statustype for `self.case`
# (this scenario is blocked by openzaak, but not part of the zgw standard)
if len(statustype_numbers) < 2:
logger.info(f"Case {self.case} has only one statustype")
logger.info("Case {case} has only one statustype".format(case=self.case))
return

statustype_numbers.sort()
Expand Down Expand Up @@ -367,7 +366,9 @@ def sync_statuses_with_status_types(
# Workaround: OIP requests the current zaak.status individually and adds the retrieved information to the statustype mapping

logger.info(
f"Issue #2037 -- Retrieving status individually for case {self.case.identification} because of eSuite"
"Issue #2037 -- Retrieving status individually for case {} because of eSuite".format(
self.case.identification
)
)
self.case.status = zaken_client.fetch_single_status(self.case.status)
status_types_mapping[self.case.status.statustype].append(self.case.status)
Expand Down Expand Up @@ -458,7 +459,9 @@ def is_file_upload_enabled_for_case_type(self) -> bool:
).exists()
)
logger.info(
f"Case {self.case.url} has case type file upload: {case_upload_enabled}"
"Case {url} has case type file upload: {case_upload_enabled}".format(
url=self.case.url, case_upload_enabled=case_upload_enabled
)
)
return case_upload_enabled

Expand All @@ -471,18 +474,26 @@ def is_file_upload_enabled_for_statustype(self) -> bool:
except AttributeError as e:
logger.exception(e)
logger.info(
f"Could not retrieve status type for case {self.case}; "
"the status has not been resolved to a ZGW model object."
"Could not retrieve status type for case {case}; "
"the status has not been resolved to a ZGW model object.".format(
case=self.case
)
)
return True
except KeyError as e:
logger.exception(e)
logger.info(
f"Could not retrieve status type config for url {self.case.status.statustype.url}"
"Could not retrieve status type config for url {url}".format(
url=self.case.status.statustype.url
)
)
return True
logger.info(
f"Case {self.case.url} status type {self.case.status.statustype} has status type file upload: {enabled_for_status_type}"
"Case {url} status type {status_type} has status type file upload: {enabled_for_status_type}".format(
url=self.case.url,
status_type=self.case.status.statustype,
enabled_for_status_type=enabled_for_status_type,
)
)
return enabled_for_status_type

Expand Down Expand Up @@ -652,9 +663,7 @@ def get_case_document_files(

config = OpenZaakConfig.get_solo()
documents = []
for case_info_obj, info_obj in zip(
case_info_objects, info_objects, strict=False
):
for case_info_obj, info_obj in zip(case_info_objects, info_objects):
if not info_obj:
continue
if not is_info_object_visible(
Expand Down
4 changes: 3 additions & 1 deletion src/open_inwoner/components/templatetags/string_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def optional_paragraph(optional_text: str) -> str:
if not optional_text:
return ""
return format_html(
f'<p class="utrecht-paragraph">{linebreaksbr(optional_text)}</p>'
'<p class="utrecht-paragraph">{optional_text}</p>'.format(
optional_text=linebreaksbr(optional_text)
)
)


Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@
)

if ALLOWED_HOSTS:
BASE_URL = f"https://{ALLOWED_HOSTS[0]}"
BASE_URL = "https://{}".format(ALLOWED_HOSTS[0])
else:
BASE_URL = "https://example.com"

Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/conf/local_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
PLAYWRIGHT_MULTI_ONLY_DEFAULT = True

# Enable django-debug-toolbar
from .dev import INSTALLED_APPS, MIDDLEWARE # noqa: E402
from .dev import INSTALLED_APPS, MIDDLEWARE

INSTALLED_APPS += ["debug_toolbar"]
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
Expand Down
9 changes: 8 additions & 1 deletion src/open_inwoner/configurations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,14 @@ def report_contrast_ratio(self, request, obj):
def check_contrast_ratio(label1, color1, label2, color2, expected_ratio):
ratio = get_contrast_ratio(color1, color2)
if ratio < expected_ratio:
message = f"'{label1}' ({color1}) en '{label2}' ({color2}) hebben niet genoeg contrast: {round(ratio, 1)}:1 waar {expected_ratio}:1 wordt verwacht."
message = "'{label1}' ({color1}) en '{label2}' ({color2}) hebben niet genoeg contrast: {ratio}:1 waar {expected}:1 wordt verwacht.".format(
label1=label1,
color1=color1,
label2=label2,
color2=color2,
ratio=round(ratio, 1),
expected=expected_ratio,
)
self.message_user(request, message, messages.WARNING)

check_contrast_ratio(
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/configurations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ class CustomFontSet(models.Model):
def update_filename(self, filename: str, new_name: str, path: str) -> str:
ext = filename.split(".")[1]
filename = f"{new_name}.{ext}"
return f"{path}/{filename}"
return "{path}/{filename}".format(path=path, filename=filename)

def update_filename_body(self, filename: str) -> str:
return CustomFontSet.update_filename(
Expand Down
18 changes: 9 additions & 9 deletions src/open_inwoner/openklant/api_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses
from dataclasses import dataclass
from datetime import datetime
from typing import NotRequired, TypedDict
from typing import NotRequired, Optional, TypedDict, Union

from zgw_consumers.api_models.base import ZGWModel

Expand Down Expand Up @@ -63,11 +63,11 @@ class ContactMoment(ZGWModel):
# eSuite OAS (compatible)
url: str
bronorganisatie: str
registratiedatum: datetime | None = None
registratiedatum: Optional[datetime] = None
kanaal: str = ""
tekst: str = ""
# NOTE annoyingly we can't put MedewerkerIdentificatie here as type because of
medewerker_identificatie: dict | None = None
medewerker_identificatie: Optional[dict] = None

# modification to API for eSuite usefulness *AFWIJKING*
identificatie: str = ""
Expand All @@ -79,8 +79,8 @@ class ContactMoment(ZGWModel):
# open-klant OAS
voorkeurskanaal: str = ""
voorkeurstaal: str = ""
vorig_contactmoment: str | None = None
volgend_contactmoment: str | None = None
vorig_contactmoment: Optional[str] = None
volgend_contactmoment: Optional[str] = None
onderwerp_links: list[str] = dataclasses.field(default_factory=list)

initiatiefnemer: str = ""
Expand Down Expand Up @@ -124,8 +124,8 @@ class KlantContactMoment(ZGWModel):

# eSuite OAS (compatible)
url: str
contactmoment: str | ContactMoment
klant: str | Klant
contactmoment: Union[str, ContactMoment]
klant: Union[str, Klant]
rol: str

# open-klant non-standard *AFWIJKING*
Expand All @@ -138,6 +138,6 @@ class ObjectContactMoment(ZGWModel):
Contactmomenten API
"""

contactmoment: str | ContactMoment
object: str | Klant
contactmoment: Union[str, ContactMoment]
object: Union[str, Klant]
object_type: str
3 changes: 1 addition & 2 deletions src/open_inwoner/openklant/services.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import datetime
import logging
import uuid
from collections.abc import Iterable
from datetime import timedelta
from typing import Literal, NotRequired, Protocol, Self
from typing import Iterable, Literal, NotRequired, Protocol, Self

import glom
from ape_pie.client import APIClient
Expand Down
4 changes: 3 additions & 1 deletion src/open_inwoner/openklant/tests/test_openklant2_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ def test_update_partij_from_user(self):
)


QUESTION_DATE = datetime.datetime(2024, 10, 2, 14, 0, 25, 587564, tzinfo=datetime.UTC)
QUESTION_DATE = datetime.datetime(
2024, 10, 2, 14, 0, 25, 587564, tzinfo=datetime.timezone.utc
)


@tag("openklant2")
Expand Down
Loading

0 comments on commit ec91456

Please sign in to comment.