From 56ee8c56baf2aade7fac95ba3ae29d472f49b1f7 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 5 Jan 2020 08:40:57 +0100 Subject: [PATCH] Fix #1122 (Uploading books with applied language restriction leads no longer to error 500) --- cps/editbooks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 91134db6..7b78cf97 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -656,10 +656,16 @@ def upload(): db_language = db.Languages(input_language) db.session.add(db_language) + # If the language of the file is excluded from the users view, it's not imported, to allow the user to view + # the book it's language is set to the filter language + if db_language != current_user.filter_language() and current_user.filter_language() != "all": + db_language = db.session.query(db.Languages).\ + filter(db.Languages.lang_code == current_user.filter_language()).first() + # combine path and normalize path from windows systems path = os.path.join(author_dir, title_dir).replace('\\', '/') db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1), - series_index, datetime.datetime.now(), path, has_cover, db_author, [], db_language) + series_index, datetime.datetime.now(), path, has_cover, db_author, [], db_language) db_book.authors.append(db_author) if db_series: db_book.series.append(db_series) @@ -688,7 +694,9 @@ def upload(): # save data to database, reread data db.session.commit() db.update_title_sort(config) - book = db.session.query(db.Books).filter(db.Books.id == book_id).filter(common_filters()).first() + # Reread book. It's important not to filter the result, as it could have language which hide it from + # current users view (tags are not stored/extracted from metadata and could also be limited) + book = db.session.query(db.Books).filter(db.Books.id == book_id).first() # upload book to gdrive if nesseccary and add "(bookid)" to folder name if config.config_use_google_drive: