diff --git a/README b/README index cb5e477..7fdc859 100644 --- a/README +++ b/README @@ -26,10 +26,14 @@ python3 main.py ### TODO: - need to save a book - - still missing author, publisher, genre, notes, blurb. not sure about series/loan/subbook, etc. + - still missing publisher, notes, blurb. + - not sure about series/loan/subbook, etc. - need to create all classes (green + button) - need to delete all classes (and watch for referential integrity) + - need to add 1 author to book, book to sub_book, series + - need to delete 1 author from book - need to delete 1 book from sub_book, series, loan + - need to create/add books to loan - add stats page - show books on shelf list - show books to buy view / printable @@ -41,3 +45,14 @@ python3 main.py offer to move parent/child series orders as well to match (think Thomas Covenant) +### WARNING WARNING, edit book has broken publisher setting on GET of /book/, DONT SAVE, until FIX as per below ### + need to get publisher to be a single 1-to-many Foreign key, not linkage many-to-many table + think I recall add new field to book (new_pub_id) as Foreign key + use ORM to copy into new_pub_id, from publisher[0].id + rename publisher to old_pub_field + rename new_pub_id to publisher + TEST + delete book_publisher_link table + delete column old_pub_field + profit + diff --git a/main.py b/main.py index 4819b3a..5d33496 100644 --- a/main.py +++ b/main.py @@ -141,7 +141,7 @@ class Book(db.Model): return def __repr__(self): - return "".format(self.id, self.author, self.title, self.year_published, self.rating, self.condition, self.owned, self.covertype, self.notes, self.blurb, self.created, self.modified, self.publisher, self.parent ) + return "".format(self.id, self.author, self.title, self.year_published, self.rating, self.condition, self.owned, self.covertype, self.notes, self.blurb, self.created, self.modified, self.publisher, self.genre, self.parent ) class Book_Sub_Book_LinkSchema(ma.SQLAlchemyAutoSchema): class Meta: model = Book_Sub_Book_Link @@ -345,30 +345,37 @@ def book(id): book.rating = request.form['rating'] book.notes = request.form['notes'] book.blurb = request.form['blurb'] - ## TODO: - # process author, genre, publisher & series?, subbooks?, loan?, etc. + # set book genre (empty list, add any that are checked on - this allows us to remove unticked ones) + book.genre = [] + genre_list = GetGenres() + for genre in genre_list: + 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 + book.author=[] + while "author-{}".format( acnt ) in request.form: + book.author.append( Author.query.get( request.form["author-{}".format( acnt )] ) ) + acnt = acnt + 1 + + ## TODO: + # what about add/remove author, series?, subbooks?, loan?, etc. db.session.commit() message="Successfully Updated Book (id={})".format(id) else: alert="danger" print( book_form) - message="Shit broke in update of Book (id={}) {}".format(id, book_form.owned.data) + message="Err... Failed to update Book (id={})".format(id) else: - book_form=BookForm(request.form) - # set defaults for drop-down's based on this book + book_form=BookForm(obj=book) book_form.publisher.default = book.publisher[0].id - book_form.condition.default = book.condition - book_form.covertype.default = book.covertype - book_form.owned.default = book.owned - book_form.rating.default = book.rating - book_form.process() author_list = GetAuthors() genre_list = GetGenres() - publisher_list = GetPublishers() book_s = book_schema.dump(book) - return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, publisher_list=publisher_list, genre_list=genre_list, alert=alert, message=message ) + return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, alert=alert, message=message, n=book_form.notes ) @app.route("/", methods=["GET"]) def main_page(): diff --git a/templates/book.html b/templates/book.html index 98e3b30..7333dd0 100644 --- a/templates/book.html +++ b/templates/book.html @@ -1,7 +1,6 @@ {% extends "base.html" %} {% block main_content %} -

View/Edit Book

{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
{% if message|length %} @@ -19,16 +18,15 @@ {% if key == "genre" %}
{% for genre in genre_list %} - {% set gname=genre.name %}
- - +
{% endfor %}
@@ -44,10 +42,10 @@
{% endif %} - {% for auth in author_list %} {% set aname=auth.surname+", "+auth.firstnames %} -