From 018499d7220afe5703fb778ed030a02b9f3b2c1a Mon Sep 17 00:00:00 2001 From: ridethepig Date: Sun, 13 Nov 2022 23:55:47 +0800 Subject: [PATCH] simple book page --- src/sql/db_create_sqlite.sql | 19 +++++++++++- src/templates/user/book.html | 59 ++++++++++++++++++++++++++++++++++++ src/user.py | 12 +++++++- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/templates/user/book.html diff --git a/src/sql/db_create_sqlite.sql b/src/sql/db_create_sqlite.sql index 8fdef97..9ccfa30 100644 --- a/src/sql/db_create_sqlite.sql +++ b/src/sql/db_create_sqlite.sql @@ -152,4 +152,21 @@ user_notecount int NOT NULL DEFAULT 0, CONSTRAINT `fk_user_stat_user` FOREIGN KEY (`user_id`) REFERENCES user(`user_id`) ON DELETE CASCADE, CONSTRAINT `ck_usedspace` CHECK (user_usedspace <= user_limit) ); --- insert into user_stat values (1,1,1,1,1,1); \ No newline at end of file +-- insert into user_stat values (1,1,1,1,1,1); + +drop view if exists `v_book_to_types`; +create view `v_book_to_types` as + select book_id, typetable.type_id as type_id, type_name from book_type natural join typetable; + +drop view if exists `v_type_to_book`; +create view `v_type_to_book` as + select book_id, + book_name, + book_isbn, + book_publisher, + book_lang, + book_author, + user_id, + type_id, + type_name + from book natural join book_type natural join typetable; \ No newline at end of file diff --git a/src/templates/user/book.html b/src/templates/user/book.html new file mode 100644 index 0000000..13b737e --- /dev/null +++ b/src/templates/user/book.html @@ -0,0 +1,59 @@ +{% extends 'base.html' %} + +{% block header %} + +{% endblock %} + +{% block content %} +
+
+
+ +
+
+
+
{{book['book_name']}}
+
+
+ {% for atype in booktype %} + {{atype['type_name']}} + {% endfor %} +
+ +
+
+
+{% endblock %} \ No newline at end of file diff --git a/src/user.py b/src/user.py index 6976631..2187460 100644 --- a/src/user.py +++ b/src/user.py @@ -172,7 +172,7 @@ def search(): querystring = "select * from book where user_id=%d" % (g.user['user_id']) queryval = "" elif bookattr == "分类": - querystring = "SELECT * from book WHERE user_id=%d AND book_id IN (select book_id from book_type, typetable where type_name LIKE \'%%%s%%\')" % (g.user['user_id'], queryval) + querystring = "SELECT * from v_type_to_book WHERE user_id=%d AND type_name LIKE \'%%%s%%\'" % (g.user['user_id'], queryval) else: querystring = "select * from book where user_id=%d and %s like \'%%%s%%\'" % (g.user['user_id'], queryattr, queryval) querystring += " limit %d offset %d" % (page_lim, page_off) @@ -188,3 +188,13 @@ def search(): cur_time=datetime.datetime.now(), error=error, queryresult=queryresult, next_page_link=next_page_link, prev_page_link=prev_page_link, page_last=page_last, page_first=(page==1), queryval=queryval, queryattr=attr_dict) + +@bp.route("/book//", methods=("GET", "POST")) +@login_required +def book(id): + db = get_db() + book = db.execute("select * from book where book_id=?", (id,)).fetchone() + booktype = db.execute("select * from v_book_to_types where book_id=?", (book['book_id'], )).fetchall() + return render_template("/user/book.html", + book=book, booktype=booktype, + cur_time=datetime.datetime.now()) \ No newline at end of file