Add new book

This commit is contained in:
Peter J. Holzer 2022-10-23 15:47:06 +02:00
parent 2fdcc2f6c1
commit b508381d40
2 changed files with 13 additions and 0 deletions

9
app.py
View File

@ -33,6 +33,15 @@ def bookmark(id):
csr.execute("insert into bookmarks(book, page) values(%s, %s)", (id, page,))
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

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