most of way through editing publisher, author, genre on book... decided now is time to make book<->publisher a normal 1-to-m as it should be
This commit is contained in:
33
main.py
33
main.py
@@ -141,7 +141,7 @@ class Book(db.Model):
|
||||
return
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, author: {}, title: {}, year_published: {}, rating: {}, condition: {}, owned: {}, covertype: {}, notes: {}, blurb: {}, created: {}, modified: {}, publisher: {}, parent: {}>".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 "<id: {}, author: {}, title: {}, year_published: {}, rating: {}, condition: {}, owned: {}, covertype: {}, notes: {}, blurb: {}, created: {}, modified: {}, publisher: {}, genre: {}, parent: {}>".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():
|
||||
|
||||
Reference in New Issue
Block a user