diff --git a/app.py b/app.py index 20c6bb2..307aa2f 100644 --- a/app.py +++ b/app.py @@ -483,29 +483,39 @@ async def upload(project_id: int = Form(...), title: str = Form(""), file: Uploa @app.get("/library", response_class=HTMLResponse) -def library(project_id: Optional[int] = None): +def library(project_id: Optional[str] = None, q_title: str = "", q_content: str = ""): + title_q = (q_title or "").strip() + content_q = (q_content or "").strip() + project_id_int = int(project_id) if (project_id and str(project_id).strip()) else None + + where = [] + params = [] + if project_id_int: + where.append("d.project_id=?") + params.append(project_id_int) + if title_q: + where.append("LOWER(d.title) LIKE LOWER(?)") + params.append(f"%{title_q}%") + if content_q: + where.append("LOWER(d.content_md) LIKE LOWER(?)") + params.append(f"%{content_q}%") + + where_sql = ("WHERE " + " AND ".join(where)) if where else "" + with db() as c: projects = c.execute("SELECT id,name FROM projects ORDER BY name").fetchall() - if project_id: - docs = c.execute( - """ - SELECT d.id,d.kind,d.title,d.created_at,p.name AS project - FROM documents d JOIN projects p ON p.id=d.project_id - WHERE d.project_id=? ORDER BY d.id DESC - """, - (project_id,), - ).fetchall() - else: - docs = c.execute( - """ - SELECT d.id,d.kind,d.title,d.created_at,p.name AS project - FROM documents d JOIN projects p ON p.id=d.project_id - ORDER BY d.id DESC LIMIT 200 - """ - ).fetchall() + docs = c.execute( + f""" + SELECT d.id,d.kind,d.title,d.created_at,p.name AS project + FROM documents d JOIN projects p ON p.id=d.project_id + {where_sql} + ORDER BY d.id DESC LIMIT 500 + """, + tuple(params), + ).fetchall() p_opts = "" + "".join( - [f"" for p in projects] + [f"" for p in projects] ) items = "".join( [ @@ -523,10 +533,16 @@ def library(project_id: Optional[int] = None): project_js = json.dumps([{"value": p["id"], "label": p["name"]} for p in projects], ensure_ascii=False) body = f"""
Keine Einträge.
'}