fixed BUG-33 - complex book/sub_book/series addition

This commit is contained in:
2023-07-01 16:06:55 +10:00
parent fa2d570612
commit a72912b15f
2 changed files with 8 additions and 10 deletions

9
BUGs
View File

@@ -1,4 +1,4 @@
#### BUGS (next-33) #### BUGS (next-34)
BUG-7: if you remove a series from a book, it won't appear in the series drop-down if it is the first 'missing' book in that series -- either reset the list, or show all series always? BUG-7: if you remove a series from a book, it won't appear in the series drop-down if it is the first 'missing' book in that series -- either reset the list, or show all series always?
@@ -12,10 +12,3 @@ BUG-31: series does not have 'series_num', so a book in 2 series, means he o
outer has explicity overall ordering of books in both series, so outer has explicity overall ordering of books in both series, so
should be ok? should be ok?
BUG-33: adding diamond throne to sparhawk novels -> I think I'm readding bsl links -> official error:
book(671) is Elenium (parent_book), series(49) is Elenium series...
DETAIL: Key (book_id, series_id)=(671, 49) already exists.
[SQL: INSERT INTO book_series_link (book_id, series_id, book_num) VALUES (%(book_id__0)s, %(series_id__0)s, %(book_num__0)s), (%(book_id__1)s, %(series_id__1)s, %(book_num__1)s), (%(book_id__2)s, %(series_id__2)s, %(book_num__2)s), (%(book_id__3)s, %(series_id__3)s, %(book_num__3)s)]
[parameters: {'book_id__0': 671, 'book_num__0': None, 'series_id__0': '141', 'book_id__1': '672', 'book_num__1': '1', 'series_id__1': '141', 'book_id__2': 671, 'book_num__2': None, 'series_id__2': '49', 'book_id__3': '672', 'book_num__3': '1', 'series_id__3': '49'}]

View File

@@ -21,7 +21,9 @@ app = Flask(__name__)
# local DB conn string # local DB conn string
if os.environ['FLASK_ENV'] == "production": if os.environ['FLASK_ENV'] == "production":
DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@bookdb:5432/library' DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@bookdb:5432/library'
app.config['FLASK_ENV']="production"
elif os.environ['FLASK_ENV'] == "container": elif os.environ['FLASK_ENV'] == "container":
app.config['FLASK_ENV']="dev"
DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@bookdb_dev:5432/library' DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@bookdb_dev:5432/library'
else: else:
DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@127.0.0.1:55432/library' DB_URL = 'postgresql+psycopg2://ddp:blahdeblah@127.0.0.1:55432/library'
@@ -661,8 +663,7 @@ def new_book():
def ClearAuthorsForBook(id): def ClearAuthorsForBook(id):
with db.engine.connect() as conn: bals=Book_Author_Link.query.filter(Book_Author_Link.book_id == id).delete()
res = conn.exec_driver_sql( f"delete from book_author_link where book_id = {id}" )
db.session.commit() db.session.commit()
# helper function to reduce code size for /book/<id>/ route - handles deleting book # helper function to reduce code size for /book/<id>/ route - handles deleting book
@@ -778,11 +779,14 @@ def book(id):
# either we are a normal book (no parent/child), OR not removing a series, might be adding though, so easiest is to # either we are a normal book (no parent/child), OR not removing a series, might be adding though, so easiest is to
# delete all bsls and then add them back based on the request.form # delete all bsls and then add them back based on the request.form
Book_Series_Link.query.filter(Book_Series_Link.book_id == book.id ).delete() Book_Series_Link.query.filter(Book_Series_Link.book_id == book.id ).delete()
if book.IsChild():
Book_Series_Link.query.filter(Book_Series_Link.book_id == book.parent[0].id ).delete()
cnt=1 cnt=1
for field in request.form: for field in request.form:
if 'bsl-book_id-' in field and field != 'bsl-book_id-NUM': if 'bsl-book_id-' in field and field != 'bsl-book_id-NUM':
cnt=int(re.findall( '\d+', field )[0]) cnt=int(re.findall( '\d+', field )[0])
print( f"here: field={field}, cnt={cnt}" )
if book.IsParent(): if book.IsParent():
newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'], newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'],
series_id=request.form[f'bsl-series_id-{cnt}'] ) series_id=request.form[f'bsl-series_id-{cnt}'] )
@@ -792,6 +796,7 @@ def book(id):
book_num=request.form[f'bsl-book_num-{cnt}'] ) book_num=request.form[f'bsl-book_num-{cnt}'] )
# add the contains (null for book_num) bsl for the parent book # add the contains (null for book_num) bsl for the parent book
if book.IsChild(): if book.IsChild():
print( f"FINAL: pid={book.parent[0].id}, sid={request.form[f'bsl-series_id-{cnt}']}" )
parent_bsl=Book_Series_Link( book_id=book.parent[0].id, series_id=request.form[f'bsl-series_id-{cnt}'] ) parent_bsl=Book_Series_Link( book_id=book.parent[0].id, series_id=request.form[f'bsl-series_id-{cnt}'] )
db.session.add(parent_bsl) db.session.add(parent_bsl)
db.session.add(newbsl) db.session.add(newbsl)