From b508381d4031dbdd426b29603d11a26f7a15453e Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sun, 23 Oct 2022 15:47:06 +0200 Subject: [PATCH 1/2] Add new book --- app.py | 9 +++++++++ templates/home.html | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/app.py b/app.py index 23acef8..a39aa81 100644 --- a/app.py +++ b/app.py @@ -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) diff --git a/templates/home.html b/templates/home.html index 335f5ae..802bcb1 100644 --- a/templates/home.html +++ b/templates/home.html @@ -14,5 +14,9 @@ {% endfor %} +
+ + +
From 7ab635430aac39ca39ab8dbed2b4039a0b64faf4 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sun, 23 Oct 2022 16:02:09 +0200 Subject: [PATCH 2/2] Add note to bookmark --- app.py | 5 ++++- templates/book.html | 34 ++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index a39aa81..543e4e9 100644 --- a/app.py +++ b/app.py @@ -29,8 +29,11 @@ def book(id): @app.route("/book//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"]) diff --git a/templates/book.html b/templates/book.html index 7cad313..27bef4b 100644 --- a/templates/book.html +++ b/templates/book.html @@ -6,29 +6,43 @@ Lesetagebuch: {{book.title}}

{{ book.title }}

- + +
{% for bookmark in bookmarks %} - - - - + + + + + + + + + {% endfor %}
- {{bookmark.ts.strftime("%Y-%m-%d %H:%M%z")}} - - {{bookmark.page}} -
+ {{bookmark.ts.strftime("%Y-%m-%d %H:%M%z")}} + + {{bookmark.page}} +
+ {% if bookmark.note %} + {{bookmark.note}} + {% endif %} +