pre-review fixes

This commit is contained in:
2026-07-25 16:42:39 -05:00
parent e030d0d4f3
commit 63295ab80e
8 changed files with 67 additions and 103 deletions

View File

@@ -2,7 +2,6 @@
from __future__ import annotations
import math
import os
import secrets
from pathlib import Path
@@ -55,53 +54,10 @@ def close_db(exc: BaseException | None = None) -> None:
repo.conn.close()
_SI_PREFIXES = [
(1e12, "T"),
(1e9, "G"),
(1e6, "M"),
(1e3, "k"),
]
def _si_format(value: object) -> str:
"""Format a number with SI prefixes for readability.
Handles string inputs (like dep.value) by trying float conversion first.
Non-numeric values are returned as-is.
"""
if isinstance(value, str):
try:
num = float(value)
except (ValueError, TypeError):
return value
elif isinstance(value, (int, float)):
num = float(value)
else:
return str(value)
if math.isnan(num) or math.isinf(num):
return str(value)
abs_num = abs(num)
if abs_num < 1000:
# Small numbers: drop trailing zeros, cap at 4 significant figures
if num == int(num) and abs_num < 100:
return str(int(num))
return f"{num:.4g}"
for threshold, prefix in _SI_PREFIXES:
if abs_num >= threshold:
scaled = num / threshold
return f"{scaled:.4g}{prefix}"
return f"{num:.4g}"
def create_app() -> Flask:
app = Flask(__name__)
app.secret_key = _load_or_generate_secret_key()
app.jinja_env.filters["si"] = _si_format
app.jinja_env.filters["qty"] = format_quantity
app.teardown_appcontext(close_db)

View File

@@ -59,12 +59,6 @@ def entity_detail(entity_id: int):
return render_template("entities/detail.html", entity=entity)
@bp.route("/<int:entity_id>/edit")
def entity_edit(entity_id: int):
"""Legacy route — redirect to detail page."""
return redirect(url_for("entities.entity_detail", entity_id=entity_id))
@bp.route("/<int:entity_id>/delete", methods=["POST"])
def entity_delete(entity_id: int):
repo = get_repo()

View File

@@ -31,7 +31,7 @@
<td>{{ e.description }}</td>
<td>{{ e.dependencies|length }}</td>
<td>
<a href="{{ url_for('entities.entity_edit', entity_id=e.id) }}" class="btn btn-sm">Edit</a>
<a href="{{ url_for('entities.entity_detail', entity_id=e.id) }}" class="btn btn-sm">Edit</a>
</td>
</tr>
{% endfor %}