Merge branch 'test-reticulum-hash' of https://git.derickphan.com/lichenblankie/tinyweb into test-reticulum-hash
This commit is contained in:
commit
395e38d2ab
1 changed files with 24 additions and 4 deletions
28
handlers.py
28
handlers.py
|
|
@ -492,6 +492,8 @@ def handle_add_manual_submit(body):
|
|||
|
||||
|
||||
def handle_pages(query=None):
|
||||
msg = query.get("msg", [""])[0] if query else ""
|
||||
msg_html = f'<p class="success">{esc(msg)}</p>' if msg else ""
|
||||
page = _paginate(query or {})
|
||||
offset = (page - 1) * BROWSE_PER_PAGE
|
||||
db = get_db()
|
||||
|
|
@ -519,6 +521,7 @@ def handle_pages(query=None):
|
|||
return_db(db)
|
||||
return _respond(
|
||||
f"<h1>indexed pages ({total})</h1>"
|
||||
f"{msg_html}"
|
||||
f"<ul>{items}</ul>"
|
||||
f'{_page_nav(page, total, "/pages", BROWSE_PER_PAGE)}'
|
||||
f'<p><a href="/export">export</a> | <a href="/import">import</a></p>'
|
||||
|
|
@ -529,20 +532,27 @@ def handle_pages(query=None):
|
|||
def handle_edit_form(page_id, msg=""):
|
||||
db = get_db()
|
||||
try:
|
||||
row = db.execute("SELECT id, url, title, note FROM pages WHERE id = ?", (page_id,)).fetchone()
|
||||
row = db.execute("SELECT id, url, title, body, note, summary FROM pages WHERE id = ?", (page_id,)).fetchone()
|
||||
if not row:
|
||||
return _error(404)
|
||||
tags = ", ".join(_get_page_tags(page_id, db))
|
||||
finally:
|
||||
return_db(db)
|
||||
|
||||
return _respond(
|
||||
f"<h1>edit page</h1>"
|
||||
f"<p><b>{esc(row['title'])}</b><br>"
|
||||
f"<small>{esc(row['url'])}</small></p>"
|
||||
f'<form method="post" action="/edit/{row["id"]}">'
|
||||
f'{_csrf_field()}'
|
||||
f'<input name="note" value="{esc(row["note"])}" placeholder="why did you save this?" size="50"><br><br>'
|
||||
f'<input name="tags" value="{esc(tags)}" placeholder="tags (comma-separated)" size="50"><br><br>'
|
||||
f'<label>Title:</label><br>'
|
||||
f'<input name="title" value="{esc(row["title"])}" size="60"><br><br>'
|
||||
f'<label>Summary (shown in search results):</label><br>'
|
||||
f'<textarea name="summary" rows="3" cols="60">{esc(row["summary"] or "")}</textarea><br><br>'
|
||||
f'<label>Note (why you saved this):</label><br>'
|
||||
f'<input name="note" value="{esc(row["note"])}" size="50"><br><br>'
|
||||
f'<label>Tags (comma-separated):</label><br>'
|
||||
f'<input name="tags" value="{esc(tags)}" size="50"><br><br>'
|
||||
f'<button type="submit">save</button>'
|
||||
f"</form>"
|
||||
f"<p>{msg}</p>"
|
||||
|
|
@ -551,15 +561,25 @@ def handle_edit_form(page_id, msg=""):
|
|||
|
||||
|
||||
def handle_edit_submit(page_id, body):
|
||||
title = body.get("title", [""])[0].strip()
|
||||
summary = body.get("summary", [""])[0].strip()
|
||||
note = body.get("note", [""])[0].strip()
|
||||
tags = body.get("tags", [""])[0].strip()
|
||||
|
||||
db = get_db()
|
||||
try:
|
||||
db.execute("UPDATE pages SET note = ? WHERE id = ?", (note, page_id))
|
||||
db.execute(
|
||||
"UPDATE pages SET title = ?, summary = ?, note = ? WHERE id = ?",
|
||||
(title, summary, note, page_id)
|
||||
)
|
||||
|
||||
_set_page_tags(page_id, tags, db)
|
||||
|
||||
db.commit()
|
||||
|
||||
finally:
|
||||
return_db(db)
|
||||
|
||||
return _redirect("/pages")
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue