diff --git a/app.py b/app.py index b0a3506..a33d785 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ -from flask import Flask, render_template, redirect, url_for, request, abort, g +from flask import Flask, render_template, redirect, request, g, flash +import secrets import json from book import Book @@ -7,12 +8,16 @@ import isbn_db app = Flask(__name__) app.config["DATABASE"] = "data/books.sqlite" +app.config["SECRET_KEY"] = secrets.token_hex() @app.route("/submit-isbn") def submit_isbn(): if "isbn" not in request.args: return "/submit-isbn?isbn=xxxxxx" + if request.args["isbn"] == "": + return "Pas d'ISBN spécifié" + try: book = Book(request.args["isbn"]) except ValueError: @@ -29,6 +34,11 @@ def submit_isbn(): return f"{book.title} ajouté (plusieurs occurrences)" return f"{book.title} ajouté" +@app.route("/web-submit-isbn") +def web_submit_isbn(): + flash(submit_isbn()) + return redirect("/") + @app.route("/") def index(): return render_template("index.html", books=isbn_db.get_all_books()) @@ -65,6 +75,21 @@ def update_book(): isbn_db.update_book(book) return redirect("/") +@app.route("/export-csv") +def export_csv(): + books = isbn_db.get_all_books() + + csv = "ISBN;Titre;Auteur;Éditeur;Date;Nombre\n" + for book in books: + csv += f"{book.isbn};{book.title};{book.author};{book.publisher};{book.publish_date};{book.count}\n" + + # return as file with a good filename + return app.response_class( + csv, + mimetype="text/csv", + headers={"Content-Disposition": "attachment;filename=books.csv"} + ) + @app.after_request def after_request(response): """Automatically close db after each request""" diff --git a/static/style.css b/static/style.css index 495ba2e..b1c8cae 100644 --- a/static/style.css +++ b/static/style.css @@ -1,4 +1,4 @@ -@import url('/static/font/iosevka.css'); +/*@import url('/static/font/iosevka.css');*/ /** Color Schemes */ /* Themes used: Catppuccin Latte & Moccha @@ -32,6 +32,7 @@ --color-base: #1e1e2e; --color-mantle: #181825; --color-crust: #11111b; + --color-action: #333d5d; --font-family: Iosevka Web; } @@ -64,6 +65,7 @@ --color-base: #eff1f5; --color-mantle: #e6e9ef; --color-crust: #dce0e8; + --color-action: #cdd6f4; } } @@ -183,7 +185,7 @@ input[type=number] { padding-bottom: 10px; } -button { +button, input[type="submit"] { color: inherit; background-color: var(--color-crust); border-color: var(--color-crust); @@ -192,9 +194,15 @@ button { border-width: 2px; padding: 5px; font-family: inherit; + width: unset; } -button:hover { +dialog > button, dialog > form > input[type="submit"] { + background-color: var(--color-base); + border-color: var(--color-base); +} + +button:hover, input[type="submit"]:hover { border-color: var(--color-lavender); } @@ -247,7 +255,7 @@ table { margin: 3px; border-radius: 3px; box-shadow: 1px 2px 2px rgba(0, 0, 0, 0.2); - background-color: #cdd6f4; + background-color: var(--color-action); } th { @@ -263,7 +271,7 @@ table tr:nth-child(even) td{ dialog { /* Geometry */ - border-width: 2px; + border-width: 1px; border-radius: 3px; /* Colors */ @@ -271,4 +279,9 @@ dialog { color: var(--color-text); min-width: 75vw; +} + +#add-book { + max-width: 300px; + margin: auto; } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 3cd298d..9d7a1ee 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,6 @@ {% extends 'base.html' %} -{% block title %}Table{% endblock %} +{% block title %}Liste des livres{% endblock %} {% block header %}
ISBN | @@ -50,7 +57,7 @@{{ book.author }} |
{{ book.publish_date }} |
{{ book.publisher }} |
- {{ book.count }} | +{{ book.count }} |
@@ -58,4 +65,6 @@ |
---|