Add note to bookmark

This commit is contained in:
Peter J. Holzer 2022-10-23 16:02:09 +02:00
parent b508381d40
commit 7ab635430a
2 changed files with 28 additions and 11 deletions

5
app.py
View File

@ -29,8 +29,11 @@ def book(id):
@app.route("/book/<id>/mark", methods=["POST"])
def bookmark(id):
page = request.form["page"]
note = request.form["note"]
csr = get_cursor()
csr.execute("insert into bookmarks(book, page) values(%s, %s)", (id, page,))
csr.execute(
"insert into bookmarks(book, page, note) values(%s, %s, %s)",
(id, page, note))
return redirect(url_for("book", id=id), code=303)
@app.route("/book/new", methods=["POST"])

View File

@ -6,29 +6,43 @@
<title> Lesetagebuch: {{book.title}} </title>
<style>
table.bookmarks {
width: clamp(24ch, 90vw, 80ch)
width: clamp(24ch, 90vw, 80ch);
border-collapse: collapse;
}
td.pagenr {
text-align: right;
}
table.bookmarks tbody {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>{{ book.title }}</h1>
<form method="post" action="{{ url_for('bookmark', id=book.id) }}">
<input name="page">
<input type="submit">
<input name="note">
<input type="submit" value="+">
</form>
<table class="bookmarks">
{% for bookmark in bookmarks %}
<tr>
<td class="timestamp">
{{bookmark.ts.strftime("%Y-%m-%d %H:%M%z")}}
</td>
<td class="pagenr">
{{bookmark.page}}
</td>
</tr>
<tbody>
<tr>
<td class="timestamp">
{{bookmark.ts.strftime("%Y-%m-%d %H:%M%z")}}
</td>
<td class="pagenr">
{{bookmark.page}}
</td>
</tr>
<tr>
<td colspan="2" class="note">
{% if bookmark.note %}
{{bookmark.note}}
{% endif %}
</td>
</tr>
</tbody>
{% endfor %}
</table>
</body>