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:
17
README
17
README
@@ -26,10 +26,14 @@ python3 main.py
|
|||||||
|
|
||||||
### TODO:
|
### TODO:
|
||||||
- need to save a book
|
- 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 create all classes (green + button)
|
||||||
- need to delete all classes (and watch for referential integrity)
|
- 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 delete 1 book from sub_book, series, loan
|
||||||
|
- need to create/add books to loan
|
||||||
- add stats page
|
- add stats page
|
||||||
- show books on shelf list
|
- show books on shelf list
|
||||||
- show books to buy view / printable
|
- 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)
|
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/<id>, 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
|
||||||
|
|
||||||
|
|||||||
31
main.py
31
main.py
@@ -141,7 +141,7 @@ class Book(db.Model):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def __repr__(self):
|
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 Book_Sub_Book_LinkSchema(ma.SQLAlchemyAutoSchema):
|
||||||
class Meta: model = Book_Sub_Book_Link
|
class Meta: model = Book_Sub_Book_Link
|
||||||
@@ -345,30 +345,37 @@ def book(id):
|
|||||||
book.rating = request.form['rating']
|
book.rating = request.form['rating']
|
||||||
book.notes = request.form['notes']
|
book.notes = request.form['notes']
|
||||||
book.blurb = request.form['blurb']
|
book.blurb = request.form['blurb']
|
||||||
|
# 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:
|
## TODO:
|
||||||
# process author, genre, publisher & series?, subbooks?, loan?, etc.
|
# what about add/remove author, series?, subbooks?, loan?, etc.
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
message="Successfully Updated Book (id={})".format(id)
|
message="Successfully Updated Book (id={})".format(id)
|
||||||
else:
|
else:
|
||||||
alert="danger"
|
alert="danger"
|
||||||
print( book_form)
|
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:
|
else:
|
||||||
book_form=BookForm(request.form)
|
book_form=BookForm(obj=book)
|
||||||
# set defaults for drop-down's based on this book
|
|
||||||
book_form.publisher.default = book.publisher[0].id
|
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()
|
author_list = GetAuthors()
|
||||||
genre_list = GetGenres()
|
genre_list = GetGenres()
|
||||||
publisher_list = GetPublishers()
|
|
||||||
|
|
||||||
book_s = book_schema.dump(book)
|
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"])
|
@app.route("/", methods=["GET"])
|
||||||
def main_page():
|
def main_page():
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block main_content %}
|
{% block main_content %}
|
||||||
|
|
||||||
<h3><center>View/Edit Book</center></h3>
|
|
||||||
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
{% if message|length %}
|
{% if message|length %}
|
||||||
@@ -19,16 +18,15 @@
|
|||||||
{% if key == "genre" %}
|
{% if key == "genre" %}
|
||||||
<div class="form-row col-lg-10">
|
<div class="form-row col-lg-10">
|
||||||
{% for genre in genre_list %}
|
{% for genre in genre_list %}
|
||||||
{% set gname=genre.name %}
|
|
||||||
<div class="form-control col" style="margin-left:5px;margin-right:-5px;">
|
<div class="form-control col" style="margin-left:5px;margin-right:-5px;">
|
||||||
<input id="{{gname}}" name="{{gname}}" type="checkbox"
|
<input id="genre-{{genre.id}}" name="genre-{{genre.id}}" type="checkbox"
|
||||||
{% for book_g in books.genre %}
|
{% for book_g in books.genre %}
|
||||||
{% if book_g['name'] == gname %}
|
{% if book_g['name'] == genre.name %}
|
||||||
checked
|
checked
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
></input>
|
></input>
|
||||||
<label style="display:inline" for="{{gname}}" class="col-form-label">{{gname}}</label>
|
<label style="display:inline" for="{{genre.name}}" class="col-form-label">{{genre.name}}</label>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@@ -44,10 +42,10 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<select class="form-control" id="author[{{cnt.idx}}]">
|
<select class="form-control" name="author-{{cnt.idx}}" id="author-{{cnt.idx}}">
|
||||||
{% for auth in author_list %}
|
{% for auth in author_list %}
|
||||||
{% set aname=auth.surname+", "+auth.firstnames %}
|
{% set aname=auth.surname+", "+auth.firstnames %}
|
||||||
<option id="{{auth.id}}" value="{{auth.id}}"
|
<option value="{{auth.id}}"
|
||||||
{% if books.author[cnt.idx].id == auth.id %}
|
{% if books.author[cnt.idx].id == auth.id %}
|
||||||
selected
|
selected
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user