Merge branch 'master' of git.hjp.at:hjp/lesetagebuch

This commit is contained in:
Peter J. Holzer 2022-10-23 20:55:53 +02:00
commit 93ec187805
3 changed files with 41 additions and 11 deletions

14
app.py
View File

@ -29,10 +29,22 @@ 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"])
def new_book():
title = request.form["title"]
csr = get_cursor()
csr.execute("insert into books(title, current) values(%s, true) returning *", (title,))
r = csr.fetchone()
return redirect(url_for("book", id=r.id), code=303)
def get_cursor():
db = get_db()
csr = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)

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>

View File

@ -14,5 +14,9 @@
{% endfor %}
</ul>
<form action="/book/new" method="POST">
<input name="title">
<input type="submit" value="+">
</form>
</body>
</html>