From 725c362663e710500e66673a5f57f02ddf08e36c Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Tue, 24 Nov 2020 18:12:28 +1100 Subject: [PATCH] cleaned up tabs on comments in main.py, allowed series edit page to stretch full page, shrank font for books in series table, added move up/down buttons (non-functional as yet), and visualised books being in more than one series --- main.py | 19 +++++++------- templates/books_for_series.html | 46 +++++++++++++++++++++------------ templates/series.html | 14 +++++----- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/main.py b/main.py index 9709b07..b2de82a 100644 --- a/main.py +++ b/main.py @@ -147,8 +147,8 @@ books_schema = BookSchema(many=True) def books(): books = Book.query.all() - # ignore ORM, its too slow. Just select sub_book data and hand add it to - # the books object, and use it in jinja2 to indent/order the books/sub books + # ignore ORM, its too slow. Just select sub_book data and hand add it to + # the books object, and use it in jinja2 to indent/order the books/sub books subs = db.engine.execute ( "select * from book_sub_book_link" ) for row in subs: index = next((i for i, item in enumerate(books) if item.id == row.sub_book_id), -1) @@ -165,18 +165,19 @@ def books_for_loan(id): @app.route("/books_for_series/", methods=["GET"]) def books_for_series(id): books = Book.query.join(Book_Series_Link).filter(Book_Series_Link.series_id==id).order_by(Book.id).all() - return render_template("books_for_series.html", books=books, series_id=id) + series = Series.query.get(id) + return render_template("books_for_series.html", books=books, series=series) @app.route("/book/", methods=["GET"]) def book(id): book = Book.query.get(id) book_s = book_schema.dump(book) - ###### - ### - ### okay, this manual hacking of sub_book is currently going to be needed, because in the jinja2 I want to list the book, and more than just the id number of the sub_book, I want the details... (sub_book_schema needs a book relationship BUT, dependencies mean I can't define a book schema inside sub_book schema, and I am definitely not sure how to join it anyway... for another time. - ### - ##### + ###### + ### + ### okay, this manual hacking of sub_book is currently going to be needed, because in the jinja2 I want to list the book, and more than just the id number of the sub_book, I want the details... (sub_book_schema needs a book relationship BUT, dependencies mean I can't define a book schema inside sub_book schema, and I am definitely not sure how to join it anyway... for another time. + ### + ##### # force sub books for jinja2 to be able to use subs = db.engine.execute ( "select bsb.book_id, bsb.sub_book_id, bsb.sub_book_num, book.title, book.rating, book.year_published, book.notes, bal.author_id as author_id, author.surname||', '||author.firstnames as author from book_sub_book_link bsb, book, book_author_link bal, author where bsb.book_id = {} and book.id = bsb.sub_book_id and book.id = bal.book_id and bal.author_id = author.id".format( id ) ) sub_book=[] @@ -192,7 +193,7 @@ def book(id): book_s['sub_book'] = sub_book book_form=BookForm(request.form) - # set defaults for drop-down's based on this book + # set defaults for drop-down's based on this book book_form.condition.default = book.condition book_form.covertype.default = book.covertype book_form.owned.default = book.owned diff --git a/templates/books_for_series.html b/templates/books_for_series.html index f0f7038..4bed8ed 100644 --- a/templates/books_for_series.html +++ b/templates/books_for_series.html @@ -1,21 +1,33 @@ -

Books in Series

- - - - - - {% for book in books %} - - {% if book.sub_book_num is defined %} - - {% else %} - - {% endif %} - +
TitleBook Number
    {{book.title}}{{book.title}}{{ SeriesBookNum( series_id, book.id ) }} -
+ + + + + {% for book in books %} + + + - {% endfor %} - + {% endfor %} +
TitleBook Number
+ {% if SeriesBookNum( series.id, book.id ) == 1 %} + {% set ds="disabled" %} + {% endif %} + + {% if SeriesBookNum( series.id, book.id ) == series.num_books %} + {% set de="disabled" %} + {% endif %} + + {% if book.sub_book_num is defined %} +     {{book.title}} + {% else %} + {{book.title}} + {% endif %} + + {% for s in book.series %} + {{ SeriesBookNum( s.id, book.id ) }} of {{s.title}}
+ {% endfor %} +
diff --git a/templates/series.html b/templates/series.html index ea9f133..36a802c 100644 --- a/templates/series.html +++ b/templates/series.html @@ -1,14 +1,16 @@ {% extends "base.html" %} {% block main_content %} -
-

Series

+
+
+

Series

Books in Series

+
{% if message|length %}
{{message}}
{% endif %}
-
+
{{ series_form.csrf_token }} {{ series_form.id }} @@ -36,11 +38,11 @@ {{ series_form.submit( class="btn btn-primary col-lg-2" )}}
-
-
+
+
-
+
{% endblock main_content %}