Add new book
This commit is contained in:
parent
2fdcc2f6c1
commit
b508381d40
9
app.py
9
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)
|
||||
|
|
|
@ -14,5 +14,9 @@
|
|||
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<form action="/book/new" method="POST">
|
||||
<input name="title">
|
||||
<input type="submit" value="+">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue