Add formatting and type checks

This commit is contained in:
StasonJatham committed 2026-05-22 17:05:06 +02:00
1 parent c0d82eaf26
commit 24747866bc
38 files changed
+800 -265

No files matched your search

+21 -14
View File
@@ -1,5 +1,7 @@
from __future__ import annotations
from collections.abc import Mapping
from ..services.ddns import DdnsService
from ..settings import DdnsSettings
from .components import (
@@ -19,7 +21,7 @@ def _render_management_page(
service: DdnsService,
settings: DdnsSettings,
management_slug: str,
account: dict[str, str | int | None],
account: Mapping[str, object],
csrf_token: str,
message: str | None = None,
request_ip: str | None = None,
@@ -37,11 +39,19 @@ def _render_management_page(
fritzbox_fields = _fritzbox_fields(update_url, hostname)
cname_record = f"your-subdomain.example.com. CNAME {hostname}."
manual_commands = _manual_update_commands(update_url, request_ip)
history_rows = "\n".join(_user_event_row(event) for event in service.store.list_update_events_for_hostname(str(account["hostname"]), 10)) or """
history_rows = (
"\n".join(
_user_event_row(event)
for event in service.store.list_update_events_for_hostname(str(account["hostname"]), 10)
)
or """
<tr><td colspan="6" class="empty">No router updates yet.</td></tr>
"""
)
message_html = _management_message(message)
dashboard_password_panel = _dashboard_password_panel(management_slug, csrf_token, bool(account.get("dashboard_password_hash")))
dashboard_password_panel = _dashboard_password_panel(
management_slug, csrf_token, bool(account.get("dashboard_password_hash"))
)
return _page(
"KarlDNS management",
trusted(f"""
@@ -143,11 +153,12 @@ def _render_management_page(
extra_styles=trusted('<link href="/admin.css?v=5" rel="stylesheet">'),
)
def _render_pending_management_page(
service: DdnsService,
settings: DdnsSettings,
management_slug: str,
account: dict[str, str | int | None],
account: Mapping[str, object],
csrf_token: str,
message: str | None = None,
request_ip: str | None = None,
@@ -224,13 +235,11 @@ def _render_pending_management_page(
def _management_message(message: str | None) -> SafeHtml:
if not message:
return trusted("")
return trusted(
f"""
return trusted(f"""
<div class="alert alert-info mb-0 rounded-0 border-start-0 border-end-0" role="status">
<div class="container">{escape(message)}</div>
</div>
"""
)
""")
def _dashboard_password_panel(management_slug: str, csrf_token: str, password_enabled: bool) -> SafeHtml:
@@ -254,8 +263,7 @@ def _dashboard_password_panel(management_slug: str, csrf_token: str, password_en
<input class="form-control" id="dashboard-current-password" name="current_dashboard_password" type="password" autocomplete="current-password" required>
</div>
"""
return trusted(
f"""
return trusted(f"""
<section class="dashboard-section">
<div class="container">
<div class="dashboard-settings-grid">
@@ -285,13 +293,12 @@ def _dashboard_password_panel(management_slug: str, csrf_token: str, password_en
</div>
</div>
</section>
"""
)
""")
def _render_management_unlock_page(
management_slug: str,
account: dict[str, str | int | None],
account: Mapping[str, object],
csrf_token: str,
message: str | None = None,
) -> str:
@@ -333,7 +340,7 @@ def _render_management_unlock_page(
)
def _user_event_row(event: dict[str, str | int | None]) -> str:
def _user_event_row(event: Mapping[str, object]) -> str:
created = escape(event.get("created_at") or "-")
raw_status = str(event.get("status") or "")
status = escape(_event_label(raw_status))