Apply ruff formatting and fix unused import linting errors

Remove unused imports flagged by ruff (F401), apply ruff format across all
files, and restore members.signals side-effect import with noqa: F401 so the
post_save signal that auto-creates Member profiles continues to fire.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 08:55:28 +02:00
parent 6c0115d4a2
commit ef05a6523d
28 changed files with 194 additions and 204 deletions

View File

@@ -2,4 +2,4 @@ from django.apps import AppConfig
class ThemeConfig(AppConfig):
name = 'theme'
name = "theme"

View File

@@ -5,29 +5,33 @@ from django import template
register = template.Library()
def calculate_brightness(background_color: dict) -> float:
"""Calculates the brightness of a background image."""
r_coefficient = 0.241
g_coefficient = 0.691
b_coefficient = 0.068
return sqrt(r_coefficient ** 2 * background_color["R"] + g_coefficient ** 2 * background_color["G"] + b_coefficient ** 2 * background_color["B"]) * 100
return sqrt(r_coefficient**2 * background_color["R"] + g_coefficient**2 * background_color["G"] + b_coefficient**2 * background_color["B"]) * 100
def foreground(background_color: dict) -> dict:
"""Calculates the foreground color based on the background."""
black = {"R": 0, "G": 0, "B": 0}
white = {"R": 255, "G": 255, "B": 255}
return black if calculate_brightness(background_color) > 210 else white
def background(text: str) -> dict:
"""Calculates the background color based on the text."""
hash_value = md5(text.encode("utf-8")).hexdigest()
hash_value_values = (hash_value[:8], hash_value[8:16], hash_value[16:24])
background_color = tuple(int(value, 16) % 256 for value in hash_value_values)
return {"R": background_color[0], "G": background_color[1], "B": background_color[2]}
@register.inclusion_tag("templatetags/avatar.html")
def avatar(first_name: str = "", last_name: str = "", initials: str = "", width: str = "md", button: bool = False) -> dict:
if initials:
@@ -36,14 +40,14 @@ def avatar(first_name: str = "", last_name: str = "", initials: str = "", width:
else:
display_name = f"{first_name[0]}{last_name[0]}"
full_name = f"{first_name} {last_name}"
avatar_background = background(full_name)
avatar_foreground = foreground(avatar_background)
return {
"name": display_name,
"width": width,
"button": button,
"background": "#%02x%02x%02x" % (avatar_background["R"], avatar_background["G"], avatar_background["B"]), # noqa: UP031
"foreground": "#%02x%02x%02x" % (avatar_foreground["R"], avatar_foreground["G"], avatar_foreground["B"]), # noqa: UP031
}
}

View File

@@ -4,40 +4,41 @@ from typing import Optional
register = template.Library()
@register.inclusion_tag("templatetags/field.html")
def form_field(field: BoundField, label: Optional[str] = None, help_text: Optional[str] = None, show_label: bool = True, show_help_text: bool = True, show_placeholder: bool = True, show_as_toggle: bool = False, size: str = "full") -> dict:
if label is not None:
field.label = label
if help_text is not None:
field.help_text = help_text
field_type = None
match field.widget_type:
case "select" | "nullbooleanselect" | "radioselect" | "selectmultiple":
field_type = "select"
case "checkbox":
field_type = "checkbox"
case "textarea" | "markdownx":
field_type = "textarea"
case "clearablefile":
field_type = "file"
case _:
field_type = "input"
size_modifier = None
match size:
case "extra-small":
size_modifier = "xs"
case "small":
size_modifier = "sm"
case _:
pass
return {"field": field, "field_type": field_type, "size_modifier": size_modifier, "show_label": show_label, "show_help_text": show_help_text, "show_placeholder": show_placeholder, "show_as_toggle": show_as_toggle}
return {"field": field, "field_type": field_type, "size_modifier": size_modifier, "show_label": show_label, "show_help_text": show_help_text, "show_placeholder": show_placeholder, "show_as_toggle": show_as_toggle}

View File

@@ -5,13 +5,14 @@ from django.http import HttpRequest
register = template.Library()
@register.simple_tag
def url_replace(request: HttpRequest, field: str, value: str | int, default_field: Optional[str] = None, default_value: Optional[str | int] = None) -> str:
"""Updates the given field in the GET parameters with the supplied field. If it does not exist, the field is added."""
dict_ = request.GET.copy()
dict_[field] = value
if default_field is not None and default_field not in dict_.keys():
dict_[default_field] = default_value
return dict_.urlencode()
return dict_.urlencode()