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:
17
app/main.py
17
app/main.py
@@ -358,6 +358,17 @@ def _parse_tags(raw: str) -> list[str]:
|
|||||||
return [t.strip() for t in raw.split(",") if t.strip()][:8]
|
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)
|
@app.get("/links/{link_id}/edit", response_class=HTMLResponse)
|
||||||
def edit_link_form(
|
def edit_link_form(
|
||||||
link_id: int,
|
link_id: int,
|
||||||
@@ -371,8 +382,7 @@ def edit_link_form(
|
|||||||
if not link:
|
if not link:
|
||||||
return Response(status_code=404)
|
return Response(status_code=404)
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"_link_card_edit.html",
|
"_link_card_edit.html", _edit_context(request, db, user, link)
|
||||||
{"request": request, "link": link, "ai_enabled": config.AI_ENABLED},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -469,6 +479,5 @@ def reanalyze_link(
|
|||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(link)
|
db.refresh(link)
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"_link_card_edit.html",
|
"_link_card_edit.html", _edit_context(request, db, user, link)
|
||||||
{"request": request, "link": link, "ai_enabled": config.AI_ENABLED},
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,11 +21,21 @@
|
|||||||
<div style="display:flex; gap:12px; flex-wrap:wrap;">
|
<div style="display:flex; gap:12px; flex-wrap:wrap;">
|
||||||
<div class="field" style="flex:1 1 160px;">
|
<div class="field" style="flex:1 1 160px;">
|
||||||
<label>Kategorie</label>
|
<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>
|
||||||
<div class="field" style="flex:1 1 160px;">
|
<div class="field" style="flex:1 1 160px;">
|
||||||
<label>Hersteller / Quelle</label>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user