diff --git a/isbn_sort/app.py b/isbn_sort/app.py index 523302e..93c75ed 100644 --- a/isbn_sort/app.py +++ b/isbn_sort/app.py @@ -42,6 +42,11 @@ def submit_isbn(): except IndexError: pass + if "no-search" in request.args: + isbn_db.add_book(book) + announce_book(book) + return "À rajouter manuellement" + try: book.load(loader="google_books", config=current_app.config) print("Got ", book, "[Google]") @@ -67,7 +72,11 @@ def web_submit_isbn(): @bp.route("/") def index(): - return render_template("index.html", books=isbn_db.get_all_books()) + return render_template( + "index.html", + books=isbn_db.get_all_books(), + categories=isbn_db.get_categories() + ) @bp.route("/delete-book", methods=["POST"]) @@ -88,7 +97,7 @@ def delete_book(): @bp.route("/update-book", methods=["POST"]) def update_book(): - attributes = ["isbn", "count", "title", "author", "publisher", "publish_date"] + attributes = ["isbn", "count", "title", "author", "publisher", "publish_date", "category"] if True in [i not in request.form for i in attributes]: return "missing an attribute" @@ -104,7 +113,8 @@ def update_book(): publisher=form_data["publisher"], publish_date=form_data["publish_date"], author=form_data["author"], - count=int(form_data["count"]) + count=int(form_data["count"]), + category=form_data["category"] ) isbn_db.update_book(book) announce_book(book, msg_type="update_book") diff --git a/isbn_sort/book.py b/isbn_sort/book.py index b273399..35a1417 100644 --- a/isbn_sort/book.py +++ b/isbn_sort/book.py @@ -18,6 +18,7 @@ class Book: self.publisher = None self.publish_date = None self.author = None + self.category = None self.count = -1 def _openlibrary_load(self, _): @@ -74,12 +75,13 @@ class Book: self.author = item["volumeInfo"]["authors"][0] - def _manual_load(self, title, publisher=None, publish_date=None, author=None, count=-1): + def _manual_load(self, title, publisher=None, publish_date=None, author=None, count=-1, category=None): self.title = title self.publisher = publisher self.publish_date = publish_date self.author = author self.count = count + self.category = category def load(self, config, loader="openlibrary"): if loader == "openlibrary": @@ -101,5 +103,6 @@ class Book: "publisher": self.publisher, "publish_date": self.publish_date, "author": self.author, - "count": self.count + "category": self.category, + "count": self.count, } \ No newline at end of file diff --git a/isbn_sort/isbn_db.py b/isbn_sort/isbn_db.py index 95c67bc..516a816 100644 --- a/isbn_sort/isbn_db.py +++ b/isbn_sort/isbn_db.py @@ -36,7 +36,8 @@ def get_book(isbn): publisher=data["publisher"], publish_date=data["publish_date"], author=data["author"], - count=data["count"] + count=data["count"], + category=data["category"] if data["category"] != "" else None ) return book @@ -77,10 +78,10 @@ def add_book(book): db = get_db() db.execute( """ - INSERT INTO book (isbn, count, title, author, publisher, publish_date) - VALUES (?, ?, ?, ?, ?, ?) + INSERT INTO book (isbn, count, title, author, publisher, publish_date, category) + VALUES (?, ?, ?, ?, ?, ?, ?) """, - (book.isbn, book.count, book.title, book.author, book.publisher, book.publish_date) + (book.isbn, book.count, book.title, book.author, book.publisher, book.publish_date, book.category) ) db.commit() return "added" @@ -89,10 +90,10 @@ def update_book(book): db = get_db() db.execute( """ - UPDATE book SET count=?, title=?, author=?, publisher=?, publish_date=? + UPDATE book SET count=?, title=?, author=?, publisher=?, publish_date=?, category=? WHERE isbn=? """, - (book.count, book.title, book.author, book.publisher, book.publish_date, book.isbn) + (book.count, book.title, book.author, book.publisher, book.publish_date, book.category, book.isbn) ) db.commit() return "updated" @@ -108,6 +109,8 @@ def get_all_books(): count += 1 if book.publisher is None: count += 1 + if book.category is None: + count += 1 return -count db = get_db() @@ -126,8 +129,20 @@ def get_all_books(): publisher=data_row["publisher"], publish_date=data_row["publish_date"], author=data_row["author"], - count=data_row["count"] + count=data_row["count"], + category=data_row["category"] if data_row["category"] != "" else None ) books.append(book) - return sorted(books, key=count_none) \ No newline at end of file + return sorted(books, key=count_none) + +def get_categories(): + db = get_db() + + data = db.execute( + """ + SELECT DISTINCT category FROM book + """ + ).fetchall() + + return [row["category"] for row in data] diff --git a/isbn_sort/schema.sql b/isbn_sort/schema.sql index c292837..985e746 100644 --- a/isbn_sort/schema.sql +++ b/isbn_sort/schema.sql @@ -6,5 +6,6 @@ CREATE TABLE book ( title TEXT, author TEXT, publisher TEXT, - publish_date TEXT + publish_date TEXT, + category TEXT DEFAULT '', ); \ No newline at end of file diff --git a/isbn_sort/static/dynamicUpdate.js b/isbn_sort/static/dynamicUpdate.js index f01100d..96ea2d3 100644 --- a/isbn_sort/static/dynamicUpdate.js +++ b/isbn_sort/static/dynamicUpdate.js @@ -39,6 +39,7 @@ function viewAddBook(book) { ''+p(book.author)+book.author+'

'+ ''+p(book.publish_date)+book.publish_date+'

'+ ''+p(book.publisher)+book.publisher+'

'+ + ''+p(book.category)+book.category+'

'+ ''+pc(book.count)+book.count+'

'+ ''+ ' '+ @@ -76,7 +77,8 @@ function viewUpdateBook(book) { cells[2].innerHTML = p(book.author)+book.author+'

'; cells[3].innerHTML = p(book.publish_date)+book.publish_date+'

'; cells[4].innerHTML = p(book.publisher)+book.publisher+'

'; - cells[5].innerHTML = pc(book.count)+book.count+'

'; + cells[5].innerHTML = p(book.category)+book.category+'

'; + cells[6].innerHTML = pc(book.count)+book.count+'

'; blink(rows[i], "var(--color-action)"); return; diff --git a/isbn_sort/static/main.js b/isbn_sort/static/main.js index ed60133..4192507 100644 --- a/isbn_sort/static/main.js +++ b/isbn_sort/static/main.js @@ -15,7 +15,8 @@ function getBookData(isbn) { var author = cells[2].innerText; var date = cells[3].innerText; var publisher = cells[4].innerText; - var quantity = cells[5].innerText; + var category = cells[5].innerText; + var quantity = cells[6].innerText; // Return the data return { @@ -23,6 +24,7 @@ function getBookData(isbn) { author: author, date: date, publisher: publisher, + category: category, quantity: quantity }; } @@ -41,6 +43,7 @@ function openEditBookDialog(isbn) { document.getElementById("edit-author").value = bookData.author; document.getElementById("edit-date").value = bookData.date; document.getElementById("edit-publisher").value = bookData.publisher; + document.getElementById("edit-category").value = bookData.category; document.getElementById("edit-quantity").value = bookData.quantity; editDialog.showModal(); } else { diff --git a/isbn_sort/static/style.css b/isbn_sort/static/style.css index e9eca37..e85bb0a 100644 --- a/isbn_sort/static/style.css +++ b/isbn_sort/static/style.css @@ -132,7 +132,7 @@ form { margin-top: 5px; } -input { +input, select { color: inherit; background-color: var(--color-mantle); border-radius: 3px; @@ -148,7 +148,7 @@ input:placeholder-shown { font-style: oblique; } -input:hover { +input:hover, select:hover { background-color: var(--color-crust); } diff --git a/isbn_sort/templates/index.html b/isbn_sort/templates/index.html index 4255d1f..c486c3e 100644 --- a/isbn_sort/templates/index.html +++ b/isbn_sort/templates/index.html @@ -20,6 +20,15 @@


+
+


@@ -50,6 +59,7 @@ Auteur Date Éditeur + Catégorie Quantité Actions @@ -60,6 +70,7 @@

{{ book.author }}

{{ book.publish_date }}

{{ book.publisher }}

+

{{ book.category }}

{{ book.count }}