diff --git a/main.py b/main.py index e152c53..e7a0c6e 100644 --- a/main.py +++ b/main.py @@ -200,7 +200,7 @@ def AddSubs(books): for row in subs: index = next((i for i, item in enumerate(books) if item.id == row.sub_book_id), -1) if index == -1: - continue + continue books[index].parent_id = row.book_id books[index].sub_book_num = row.sub_book_num @@ -361,15 +361,14 @@ def book(id): if "genre-{}".format(genre.id) in request.form: book.genre.append( genre ) # set book author (empty list, in form they are in author-0, author-1, ... author-n) - # so use while to find them all and append them back to now empty list - acnt=0 + # so use find them all and append them back to now empty list book.author=[] - while "author-{}".format( acnt ) in request.form: - book.author.append( Author.query.get( request.form["author-{}".format( acnt )] ) ) - acnt = acnt + 1 + for el in request.form: + if 'author-' in el: + book.author.append( Author.query.get( request.form[el] ) ) ## TODO: - # what about add/remove author, series?, subbooks?, loan?, etc. + # what about series?, subbooks?, loan?, etc. db.session.commit() message="Successfully Updated Book (id={})".format(id) else: diff --git a/templates/book.html b/templates/book.html index c7338f6..36dbbbf 100644 --- a/templates/book.html +++ b/templates/book.html @@ -1,6 +1,33 @@ {% extends "base.html" %} {% block main_content %} + + {% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
{% if message|length %} @@ -41,15 +68,13 @@ {% endfor %}
{% elif key == "author" %} -
+
{% set cnt = namespace(idx=0) %} {% for objects in books[key] %} -
+
{% if cnt.idx > 0 %}
- +
{% endif %}