Suggest existing categories/manufacturers when editing

The category and manufacturer fields in the edit form now offer the
already-used values via a datalist dropdown, while still allowing a
new value to be typed. Both edit entry points (open edit form and AI
re-describe) pass the current lists.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Erik Thiele
2026-07-20 22:13:08 +02:00
parent fdfddf8ccf
commit 8e9b49e57b
2 changed files with 25 additions and 6 deletions

View File

@@ -358,6 +358,17 @@ def _parse_tags(raw: str) -> list[str]:
return [t.strip() for t in raw.split(",") if t.strip()][:8]
def _edit_context(request: Request, db: Session, user: User, link: Link) -> dict:
existing = facets(db, user)
return {
"request": request,
"link": link,
"ai_enabled": config.AI_ENABLED,
"all_categories": [name for name, _ in existing["categories"]],
"all_manufacturers": [name for name, _ in existing["manufacturers"]],
}
@app.get("/links/{link_id}/edit", response_class=HTMLResponse)
def edit_link_form(
link_id: int,
@@ -371,8 +382,7 @@ def edit_link_form(
if not link:
return Response(status_code=404)
return templates.TemplateResponse(
"_link_card_edit.html",
{"request": request, "link": link, "ai_enabled": config.AI_ENABLED},
"_link_card_edit.html", _edit_context(request, db, user, link)
)
@@ -469,6 +479,5 @@ def reanalyze_link(
db.commit()
db.refresh(link)
return templates.TemplateResponse(
"_link_card_edit.html",
{"request": request, "link": link, "ai_enabled": config.AI_ENABLED},
"_link_card_edit.html", _edit_context(request, db, user, link)
)

View File

@@ -21,11 +21,21 @@
<div style="display:flex; gap:12px; flex-wrap:wrap;">
<div class="field" style="flex:1 1 160px;">
<label>Kategorie</label>
<input type="text" name="category" value="{{ link.category }}">
<input type="text" name="category" value="{{ link.category }}"
list="cats-{{ link.id }}" placeholder="wählen oder neu eingeben"
autocomplete="off">
<datalist id="cats-{{ link.id }}">
{% for name in all_categories %}<option value="{{ name }}"></option>{% endfor %}
</datalist>
</div>
<div class="field" style="flex:1 1 160px;">
<label>Hersteller / Quelle</label>
<input type="text" name="manufacturer" value="{{ link.manufacturer }}">
<input type="text" name="manufacturer" value="{{ link.manufacturer }}"
list="mans-{{ link.id }}" placeholder="wählen oder neu eingeben"
autocomplete="off">
<datalist id="mans-{{ link.id }}">
{% for name in all_manufacturers %}<option value="{{ name }}"></option>{% endfor %}
</datalist>
</div>
</div>