feat: enhance color handling in templates and dashboard with hex support

This commit is contained in:
2026-05-10 12:55:39 +02:00
parent 8f8c3655db
commit 565c4078bb
5 changed files with 39 additions and 8 deletions
+17 -2
View File
@@ -32,6 +32,17 @@ def get_html_template(content) -> str:
return HTML_TEMPLATE.format(content=content)
def _as_hex_color(value: int | str | None) -> str:
if isinstance(value, int):
return f"#{value:06X}"
if isinstance(value, str):
try:
return f"#{parse_color(value):06X}"
except ValueError:
return "#000000"
return "#000000"
def create_app(
*,
get_state: Callable[[], dict],
@@ -77,13 +88,14 @@ def create_app(
blocks = []
for key, tpl in templates.items():
text = (tpl.get("text") or "").replace("'", "'")
color = tpl.get("color")
color_hex = _as_hex_color(tpl.get("color"))
image_url = tpl.get("image_url") or ""
blocks.append(
"<fieldset style='margin-bottom:16px;'>"
f"<legend><strong>{key}</strong></legend>"
f"<label>Text<br><textarea name='{key}__text' rows='3' style='width:100%'>{text}</textarea></label><br>"
f"<label>Color<br><input name='{key}__color' value='{color}' style='width:200px'></label><br>"
f"<label>Color<br><input type='color' name='{key}__color_picker' value='{color_hex}' oninput=\"this.form['{key}__color'].value=this.value\"></label><br>"
f"<label>Color value<br><input name='{key}__color' value='{color_hex}' style='width:200px'></label><br>"
f"<label>Image URL (optional)<br><input name='{key}__image_url' value='{image_url}' style='width:100%'></label>"
"</fieldset>"
)
@@ -108,6 +120,9 @@ def create_app(
for key in current.keys():
text = request.form.get(f"{key}__text", "").strip()
color_raw = request.form.get(f"{key}__color", "").strip()
if not color_raw:
color_raw = request.form.get(
f"{key}__color_picker", "").strip()
image_url = request.form.get(f"{key}__image_url", "").strip()
if not text: