Add category
This commit is contained in:
parent
dd07544a44
commit
583ae8cd80
@ -42,6 +42,11 @@ def submit_isbn():
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if "no-search" in request.args:
|
||||||
|
isbn_db.add_book(book)
|
||||||
|
announce_book(book)
|
||||||
|
return "À rajouter manuellement"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
book.load(loader="google_books", config=current_app.config)
|
book.load(loader="google_books", config=current_app.config)
|
||||||
print("Got ", book, "[Google]")
|
print("Got ", book, "[Google]")
|
||||||
@ -67,7 +72,11 @@ def web_submit_isbn():
|
|||||||
|
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
def index():
|
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"])
|
@bp.route("/delete-book", methods=["POST"])
|
||||||
@ -88,7 +97,7 @@ def delete_book():
|
|||||||
|
|
||||||
@bp.route("/update-book", methods=["POST"])
|
@bp.route("/update-book", methods=["POST"])
|
||||||
def update_book():
|
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]:
|
if True in [i not in request.form for i in attributes]:
|
||||||
return "missing an attribute"
|
return "missing an attribute"
|
||||||
|
|
||||||
@ -104,7 +113,8 @@ def update_book():
|
|||||||
publisher=form_data["publisher"],
|
publisher=form_data["publisher"],
|
||||||
publish_date=form_data["publish_date"],
|
publish_date=form_data["publish_date"],
|
||||||
author=form_data["author"],
|
author=form_data["author"],
|
||||||
count=int(form_data["count"])
|
count=int(form_data["count"]),
|
||||||
|
category=form_data["category"]
|
||||||
)
|
)
|
||||||
isbn_db.update_book(book)
|
isbn_db.update_book(book)
|
||||||
announce_book(book, msg_type="update_book")
|
announce_book(book, msg_type="update_book")
|
||||||
|
@ -18,6 +18,7 @@ class Book:
|
|||||||
self.publisher = None
|
self.publisher = None
|
||||||
self.publish_date = None
|
self.publish_date = None
|
||||||
self.author = None
|
self.author = None
|
||||||
|
self.category = None
|
||||||
self.count = -1
|
self.count = -1
|
||||||
|
|
||||||
def _openlibrary_load(self, _):
|
def _openlibrary_load(self, _):
|
||||||
@ -74,12 +75,13 @@ class Book:
|
|||||||
self.author = item["volumeInfo"]["authors"][0]
|
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.title = title
|
||||||
self.publisher = publisher
|
self.publisher = publisher
|
||||||
self.publish_date = publish_date
|
self.publish_date = publish_date
|
||||||
self.author = author
|
self.author = author
|
||||||
self.count = count
|
self.count = count
|
||||||
|
self.category = category
|
||||||
|
|
||||||
def load(self, config, loader="openlibrary"):
|
def load(self, config, loader="openlibrary"):
|
||||||
if loader == "openlibrary":
|
if loader == "openlibrary":
|
||||||
@ -101,5 +103,6 @@ class Book:
|
|||||||
"publisher": self.publisher,
|
"publisher": self.publisher,
|
||||||
"publish_date": self.publish_date,
|
"publish_date": self.publish_date,
|
||||||
"author": self.author,
|
"author": self.author,
|
||||||
"count": self.count
|
"category": self.category,
|
||||||
|
"count": self.count,
|
||||||
}
|
}
|
@ -36,7 +36,8 @@ def get_book(isbn):
|
|||||||
publisher=data["publisher"],
|
publisher=data["publisher"],
|
||||||
publish_date=data["publish_date"],
|
publish_date=data["publish_date"],
|
||||||
author=data["author"],
|
author=data["author"],
|
||||||
count=data["count"]
|
count=data["count"],
|
||||||
|
category=data["category"] if data["category"] != "" else None
|
||||||
)
|
)
|
||||||
return book
|
return book
|
||||||
|
|
||||||
@ -77,10 +78,10 @@ def add_book(book):
|
|||||||
db = get_db()
|
db = get_db()
|
||||||
db.execute(
|
db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO book (isbn, count, title, author, publisher, publish_date)
|
INSERT INTO book (isbn, count, title, author, publisher, publish_date, category)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
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()
|
db.commit()
|
||||||
return "added"
|
return "added"
|
||||||
@ -89,10 +90,10 @@ def update_book(book):
|
|||||||
db = get_db()
|
db = get_db()
|
||||||
db.execute(
|
db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE book SET count=?, title=?, author=?, publisher=?, publish_date=?
|
UPDATE book SET count=?, title=?, author=?, publisher=?, publish_date=?, category=?
|
||||||
WHERE isbn=?
|
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()
|
db.commit()
|
||||||
return "updated"
|
return "updated"
|
||||||
@ -108,6 +109,8 @@ def get_all_books():
|
|||||||
count += 1
|
count += 1
|
||||||
if book.publisher is None:
|
if book.publisher is None:
|
||||||
count += 1
|
count += 1
|
||||||
|
if book.category is None:
|
||||||
|
count += 1
|
||||||
return -count
|
return -count
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
@ -126,8 +129,20 @@ def get_all_books():
|
|||||||
publisher=data_row["publisher"],
|
publisher=data_row["publisher"],
|
||||||
publish_date=data_row["publish_date"],
|
publish_date=data_row["publish_date"],
|
||||||
author=data_row["author"],
|
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)
|
books.append(book)
|
||||||
|
|
||||||
return sorted(books, key=count_none)
|
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]
|
||||||
|
@ -6,5 +6,6 @@ CREATE TABLE book (
|
|||||||
title TEXT,
|
title TEXT,
|
||||||
author TEXT,
|
author TEXT,
|
||||||
publisher TEXT,
|
publisher TEXT,
|
||||||
publish_date TEXT
|
publish_date TEXT,
|
||||||
|
category TEXT DEFAULT '',
|
||||||
);
|
);
|
@ -39,6 +39,7 @@ function viewAddBook(book) {
|
|||||||
'<td>'+p(book.author)+book.author+'</p></td>'+
|
'<td>'+p(book.author)+book.author+'</p></td>'+
|
||||||
'<td>'+p(book.publish_date)+book.publish_date+'</p></td>'+
|
'<td>'+p(book.publish_date)+book.publish_date+'</p></td>'+
|
||||||
'<td>'+p(book.publisher)+book.publisher+'</p></td>'+
|
'<td>'+p(book.publisher)+book.publisher+'</p></td>'+
|
||||||
|
'<td>'+p(book.category)+book.category+'</p></td>'+
|
||||||
'<td>'+pc(book.count)+book.count+'</p></td>'+
|
'<td>'+pc(book.count)+book.count+'</p></td>'+
|
||||||
'<td>'+
|
'<td>'+
|
||||||
' <button class="action" onclick="openEditBookDialog('+book.isbn+')">✏️</button>'+
|
' <button class="action" onclick="openEditBookDialog('+book.isbn+')">✏️</button>'+
|
||||||
@ -76,7 +77,8 @@ function viewUpdateBook(book) {
|
|||||||
cells[2].innerHTML = p(book.author)+book.author+'</p>';
|
cells[2].innerHTML = p(book.author)+book.author+'</p>';
|
||||||
cells[3].innerHTML = p(book.publish_date)+book.publish_date+'</p>';
|
cells[3].innerHTML = p(book.publish_date)+book.publish_date+'</p>';
|
||||||
cells[4].innerHTML = p(book.publisher)+book.publisher+'</p>';
|
cells[4].innerHTML = p(book.publisher)+book.publisher+'</p>';
|
||||||
cells[5].innerHTML = pc(book.count)+book.count+'</p>';
|
cells[5].innerHTML = p(book.category)+book.category+'</p>';
|
||||||
|
cells[6].innerHTML = pc(book.count)+book.count+'</p>';
|
||||||
|
|
||||||
blink(rows[i], "var(--color-action)");
|
blink(rows[i], "var(--color-action)");
|
||||||
return;
|
return;
|
||||||
|
@ -15,7 +15,8 @@ function getBookData(isbn) {
|
|||||||
var author = cells[2].innerText;
|
var author = cells[2].innerText;
|
||||||
var date = cells[3].innerText;
|
var date = cells[3].innerText;
|
||||||
var publisher = cells[4].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 the data
|
||||||
return {
|
return {
|
||||||
@ -23,6 +24,7 @@ function getBookData(isbn) {
|
|||||||
author: author,
|
author: author,
|
||||||
date: date,
|
date: date,
|
||||||
publisher: publisher,
|
publisher: publisher,
|
||||||
|
category: category,
|
||||||
quantity: quantity
|
quantity: quantity
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -41,6 +43,7 @@ function openEditBookDialog(isbn) {
|
|||||||
document.getElementById("edit-author").value = bookData.author;
|
document.getElementById("edit-author").value = bookData.author;
|
||||||
document.getElementById("edit-date").value = bookData.date;
|
document.getElementById("edit-date").value = bookData.date;
|
||||||
document.getElementById("edit-publisher").value = bookData.publisher;
|
document.getElementById("edit-publisher").value = bookData.publisher;
|
||||||
|
document.getElementById("edit-category").value = bookData.category;
|
||||||
document.getElementById("edit-quantity").value = bookData.quantity;
|
document.getElementById("edit-quantity").value = bookData.quantity;
|
||||||
editDialog.showModal();
|
editDialog.showModal();
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,7 +132,7 @@ form {
|
|||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input, select {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
background-color: var(--color-mantle);
|
background-color: var(--color-mantle);
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
@ -148,7 +148,7 @@ input:placeholder-shown {
|
|||||||
font-style: oblique;
|
font-style: oblique;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:hover {
|
input:hover, select:hover {
|
||||||
background-color: var(--color-crust);
|
background-color: var(--color-crust);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,15 @@
|
|||||||
<input type="text" id="edit-date" name="publish_date"><br>
|
<input type="text" id="edit-date" name="publish_date"><br>
|
||||||
<label for="edit-publisher">Éditeur:</label><br>
|
<label for="edit-publisher">Éditeur:</label><br>
|
||||||
<input type="text" id="edit-publisher" name="publisher"><br>
|
<input type="text" id="edit-publisher" name="publisher"><br>
|
||||||
|
<label for="edit-category">Catégorie:</label><br>
|
||||||
|
<select id="edit-category" name="category">
|
||||||
|
<option value="">- Pas de catégorie -</option>
|
||||||
|
{% for category in categories %}
|
||||||
|
{% if category != "" %}
|
||||||
|
<option value="{{ category }}">{{ category }}</option>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</select><br>
|
||||||
<label for="edit-quantity">Quantité:</label><br>
|
<label for="edit-quantity">Quantité:</label><br>
|
||||||
<input type="number" id="edit-quantity" name="count"><br>
|
<input type="number" id="edit-quantity" name="count"><br>
|
||||||
<input type="submit" value="Mettre à jour">
|
<input type="submit" value="Mettre à jour">
|
||||||
@ -50,6 +59,7 @@
|
|||||||
<th>Auteur</th>
|
<th>Auteur</th>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Éditeur</th>
|
<th>Éditeur</th>
|
||||||
|
<th>Catégorie</th>
|
||||||
<th>Quantité</th>
|
<th>Quantité</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -60,6 +70,7 @@
|
|||||||
<td><p {% if book.author == None %}class="red"{% endif %}>{{ book.author }}</p></td>
|
<td><p {% if book.author == None %}class="red"{% endif %}>{{ book.author }}</p></td>
|
||||||
<td><p {% if book.publish_date == None %}class="red"{% endif %}>{{ book.publish_date }}</p></td>
|
<td><p {% if book.publish_date == None %}class="red"{% endif %}>{{ book.publish_date }}</p></td>
|
||||||
<td><p {% if book.publisher == None %}class="red"{% endif %}>{{ book.publisher }}</p></td>
|
<td><p {% if book.publisher == None %}class="red"{% endif %}>{{ book.publisher }}</p></td>
|
||||||
|
<td><p {% if book.category == None %}class="red"{% endif %}>{{ book.category }}</p></td>
|
||||||
<td><p {% if book.count != 1 %}class="red"{% endif %}>{{ book.count }}</p></td>
|
<td><p {% if book.count != 1 %}class="red"{% endif %}>{{ book.count }}</p></td>
|
||||||
<td>
|
<td>
|
||||||
<button class="action" onclick='openEditBookDialog("{{ book.isbn }}")'>✏️</button>
|
<button class="action" onclick='openEditBookDialog("{{ book.isbn }}")'>✏️</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user