Commit ccca5d4d authored by Ozzieisaacs's avatar Ozzieisaacs

Merge branch 'master' into Develop

# Conflicts:
#	cps/templates/layout.html
parents 59b78f99 ba106578
...@@ -27,12 +27,12 @@ A clear and concise description of what you expected to happen. ...@@ -27,12 +27,12 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem. If applicable, add screenshots to help explain your problem.
**Environment (please complete the following information):** **Environment (please complete the following information):**
- OS: [e.g. Windows 10/raspian] - OS: [e.g. Windows 10/Raspberry Pi OS]
- Python version [e.g. python2.7] - Python version: [e.g. python2.7]
- Calibre-Web version [e.g. 0.6.5 or master@16.02.20, 19:55 ]: - Calibre-Web version: [e.g. 0.6.8 or 087c4c59 (git rev-parse --short HEAD)]:
- Docker container [ None/Technosoft2000/Linuxuser]: - Docker container: [None/Technosoft2000/Linuxuser]:
- Special Hardware [e.g. Rasperry Pi Zero] - Special Hardware: [e.g. Rasperry Pi Zero]
- Browser [e.g. chrome, safari] - Browser: [e.g. Chrome 83.0.4103.97, Safari 13.3.7, Firefox 68.0.1 ESR]
**Additional context** **Additional context**
Add any other context about the problem here. [e.g. access via reverse proxy] Add any other context about the problem here. [e.g. access via reverse proxy, database background sync, special database location]
...@@ -34,7 +34,7 @@ from flask import Blueprint, flash, redirect, url_for, abort, request, make_resp ...@@ -34,7 +34,7 @@ from flask import Blueprint, flash, redirect, url_for, abort, request, make_resp
from flask_login import login_required, current_user, logout_user from flask_login import login_required, current_user, logout_user
from flask_babel import gettext as _ from flask_babel import gettext as _
from sqlalchemy import and_ from sqlalchemy import and_
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError, OperationalError, InvalidRequestError
from sqlalchemy.sql.expression import func from sqlalchemy.sql.expression import func
from . import constants, logger, helper, services from . import constants, logger, helper, services
...@@ -613,80 +613,86 @@ def _configuration_update_helper(): ...@@ -613,80 +613,86 @@ def _configuration_update_helper():
reboot_required = False reboot_required = False
db_change = False db_change = False
to_save = request.form.to_dict() to_save = request.form.to_dict()
gdriveError = None
to_save['config_calibre_dir'] = re.sub('[\\/]metadata\.db$', '', to_save['config_calibre_dir'], flags=re.IGNORECASE) to_save['config_calibre_dir'] = re.sub('[\\/]metadata\.db$', '', to_save['config_calibre_dir'], flags=re.IGNORECASE)
db_change |= _config_string(to_save, "config_calibre_dir") try:
db_change |= _config_string(to_save, "config_calibre_dir")
# Google drive setup
gdriveError = _configuration_gdrive_helper(to_save)
reboot_required |= _config_int(to_save, "config_port")
reboot_required |= _config_string(to_save, "config_keyfile")
if config.config_keyfile and not os.path.isfile(config.config_keyfile):
return _configuration_result(_('Keyfile Location is not Valid, Please Enter Correct Path'), gdriveError)
reboot_required |= _config_string(to_save, "config_certfile")
if config.config_certfile and not os.path.isfile(config.config_certfile):
return _configuration_result(_('Certfile Location is not Valid, Please Enter Correct Path'), gdriveError)
_config_checkbox_int(to_save, "config_uploading")
_config_checkbox_int(to_save, "config_anonbrowse")
_config_checkbox_int(to_save, "config_public_reg")
_config_checkbox_int(to_save, "config_register_email")
reboot_required |= _config_checkbox_int(to_save, "config_kobo_sync")
_config_checkbox_int(to_save, "config_kobo_proxy")
_config_string(to_save, "config_upload_formats")
constants.EXTENSIONS_UPLOAD = [x.lstrip().rstrip() for x in config.config_upload_formats.split(',')]
_config_string(to_save, "config_calibre")
_config_string(to_save, "config_converterpath")
_config_string(to_save, "config_kepubifypath")
# Google drive setup reboot_required |= _config_int(to_save, "config_login_type")
gdriveError = _configuration_gdrive_helper(to_save)
reboot_required |= _config_int(to_save, "config_port") #LDAP configurator,
if config.config_login_type == constants.LOGIN_LDAP:
reboot, message = _configuration_ldap_helper(to_save, gdriveError)
if message:
return message
reboot_required |= reboot
reboot_required |= _config_string(to_save, "config_keyfile") # Remote login configuration
if config.config_keyfile and not os.path.isfile(config.config_keyfile):
return _configuration_result(_('Keyfile Location is not Valid, Please Enter Correct Path'), gdriveError)
reboot_required |= _config_string(to_save, "config_certfile") _config_checkbox(to_save, "config_remote_login")
if config.config_certfile and not os.path.isfile(config.config_certfile): if not config.config_remote_login:
return _configuration_result(_('Certfile Location is not Valid, Please Enter Correct Path'), gdriveError) ub.session.query(ub.RemoteAuthToken).filter(ub.RemoteAuthToken.token_type==0).delete()
_config_checkbox_int(to_save, "config_uploading") # Goodreads configuration
_config_checkbox_int(to_save, "config_anonbrowse") _config_checkbox(to_save, "config_use_goodreads")
_config_checkbox_int(to_save, "config_public_reg") _config_string(to_save, "config_goodreads_api_key")
_config_checkbox_int(to_save, "config_register_email") _config_string(to_save, "config_goodreads_api_secret")
reboot_required |= _config_checkbox_int(to_save, "config_kobo_sync") if services.goodreads_support:
_config_checkbox_int(to_save, "config_kobo_proxy") services.goodreads_support.connect(config.config_goodreads_api_key,
config.config_goodreads_api_secret,
config.config_use_goodreads)
_config_string(to_save, "config_upload_formats") _config_int(to_save, "config_updatechannel")
constants.EXTENSIONS_UPLOAD = [x.lstrip().rstrip() for x in config.config_upload_formats.split(',')]
_config_string(to_save, "config_calibre") # Reverse proxy login configuration
_config_string(to_save, "config_converterpath") _config_checkbox(to_save, "config_allow_reverse_proxy_header_login")
_config_string(to_save, "config_kepubifypath") _config_string(to_save, "config_reverse_proxy_login_header_name")
reboot_required |= _config_int(to_save, "config_login_type") # OAuth configuration
if config.config_login_type == constants.LOGIN_OAUTH:
reboot_required |= _configuration_oauth_helper(to_save)
#LDAP configurator, reboot, message = _configuration_logfile_helper(to_save, gdriveError)
if config.config_login_type == constants.LOGIN_LDAP:
reboot, message = _configuration_ldap_helper(to_save, gdriveError)
if message: if message:
return message return message
reboot_required |= reboot reboot_required |= reboot
# Rarfile Content configuration
# Remote login configuration _config_string(to_save, "config_rarfile_location")
_config_checkbox(to_save, "config_remote_login") if "config_rarfile_location" in to_save:
if not config.config_remote_login: unrar_status = helper.check_unrar(config.config_rarfile_location)
ub.session.query(ub.RemoteAuthToken).filter(ub.RemoteAuthToken.token_type==0).delete() if unrar_status:
return _configuration_result(unrar_status, gdriveError)
# Goodreads configuration except (OperationalError, InvalidRequestError):
_config_checkbox(to_save, "config_use_goodreads") ub.session.rollback()
_config_string(to_save, "config_goodreads_api_key") _configuration_result(_(u"Settings DB is not Writeable"), gdriveError)
_config_string(to_save, "config_goodreads_api_secret")
if services.goodreads_support:
services.goodreads_support.connect(config.config_goodreads_api_key,
config.config_goodreads_api_secret,
config.config_use_goodreads)
_config_int(to_save, "config_updatechannel")
# Reverse proxy login configuration
_config_checkbox(to_save, "config_allow_reverse_proxy_header_login")
_config_string(to_save, "config_reverse_proxy_login_header_name")
# OAuth configuration
if config.config_login_type == constants.LOGIN_OAUTH:
reboot_required |= _configuration_oauth_helper(to_save)
reboot, message = _configuration_logfile_helper(to_save, gdriveError)
if message:
return message
reboot_required |= reboot
# Rarfile Content configuration
_config_string(to_save, "config_rarfile_location")
if "config_rarfile_location" in to_save:
unrar_status = helper.check_unrar(config.config_rarfile_location)
if unrar_status:
return _configuration_result(unrar_status, gdriveError)
try: try:
metadata_db = os.path.join(config.config_calibre_dir, "metadata.db") metadata_db = os.path.join(config.config_calibre_dir, "metadata.db")
...@@ -719,7 +725,7 @@ def _configuration_result(error_flash=None, gdriveError=None): ...@@ -719,7 +725,7 @@ def _configuration_result(error_flash=None, gdriveError=None):
gdriveError = _(gdriveError) gdriveError = _(gdriveError)
else: else:
# if config.config_use_google_drive and\ # if config.config_use_google_drive and\
if not gdrive_authenticate: if not gdrive_authenticate and gdrive_support:
gdrivefolders = gdriveutils.listRootFolders() gdrivefolders = gdriveutils.listRootFolders()
show_back_button = current_user.is_authenticated show_back_button = current_user.is_authenticated
...@@ -783,6 +789,9 @@ def _handle_new_user(to_save, content,languages, translations, kobo_support): ...@@ -783,6 +789,9 @@ def _handle_new_user(to_save, content,languages, translations, kobo_support):
except IntegrityError: except IntegrityError:
ub.session.rollback() ub.session.rollback()
flash(_(u"Found an existing account for this e-mail address or nickname."), category="error") flash(_(u"Found an existing account for this e-mail address or nickname."), category="error")
except OperationalError:
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
def _handle_edit_user(to_save, content,languages, translations, kobo_support, downloads): def _handle_edit_user(to_save, content,languages, translations, kobo_support, downloads):
...@@ -872,6 +881,9 @@ def _handle_edit_user(to_save, content,languages, translations, kobo_support, do ...@@ -872,6 +881,9 @@ def _handle_edit_user(to_save, content,languages, translations, kobo_support, do
except IntegrityError: except IntegrityError:
ub.session.rollback() ub.session.rollback()
flash(_(u"An unknown error occured."), category="error") flash(_(u"An unknown error occured."), category="error")
except OperationalError:
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
@admi.route("/admin/user/new", methods=["GET", "POST"]) @admi.route("/admin/user/new", methods=["GET", "POST"])
...@@ -916,7 +928,12 @@ def update_mailsettings(): ...@@ -916,7 +928,12 @@ def update_mailsettings():
_config_string(to_save, "mail_password") _config_string(to_save, "mail_password")
_config_string(to_save, "mail_from") _config_string(to_save, "mail_from")
_config_int(to_save, "mail_size", lambda y: int(y)*1024*1024) _config_int(to_save, "mail_size", lambda y: int(y)*1024*1024)
config.save() try:
config.save()
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
return edit_mailsettings()
if to_save.get("test"): if to_save.get("test"):
if current_user.email: if current_user.email:
......
...@@ -354,7 +354,8 @@ def edit_book_ratings(to_save, book): ...@@ -354,7 +354,8 @@ def edit_book_ratings(to_save, book):
def edit_book_tags(tags, book): def edit_book_tags(tags, book):
input_tags = tags.split(',') input_tags = tags.split(',')
input_tags = list(map(lambda it: it.strip(), input_tags)) input_tags = list(map(lambda it: it.strip(), input_tags))
# if input_tags[0] !="": ?? # Remove duplicates
input_tags = helper.uniq(input_tags)
return modify_database_object(input_tags, book.tags, db.Tags, calibre_db.session, 'tags') return modify_database_object(input_tags, book.tags, db.Tags, calibre_db.session, 'tags')
...@@ -368,8 +369,6 @@ def edit_book_series_index(series_index, book): ...@@ -368,8 +369,6 @@ def edit_book_series_index(series_index, book):
# Add default series_index to book # Add default series_index to book
modif_date = False modif_date = False
series_index = series_index or '1' series_index = series_index or '1'
#if series_index == '':
# series_index = '1'
if book.series_index != series_index: if book.series_index != series_index:
book.series_index = series_index book.series_index = series_index
modif_date = True modif_date = True
...@@ -403,6 +402,8 @@ def edit_book_languages(languages, book, upload=False): ...@@ -403,6 +402,8 @@ def edit_book_languages(languages, book, upload=False):
if input_l[0] != current_user.filter_language() and current_user.filter_language() != "all": if input_l[0] != current_user.filter_language() and current_user.filter_language() != "all":
input_l[0] = calibre_db.session.query(db.Languages). \ input_l[0] = calibre_db.session.query(db.Languages). \
filter(db.Languages.lang_code == current_user.filter_language()).first() filter(db.Languages.lang_code == current_user.filter_language()).first()
# Remove duplicates
input_l = helper.uniq(input_l)
return modify_database_object(input_l, book.languages, db.Languages, calibre_db.session, 'languages') return modify_database_object(input_l, book.languages, db.Languages, calibre_db.session, 'languages')
...@@ -605,6 +606,8 @@ def edit_book(book_id): ...@@ -605,6 +606,8 @@ def edit_book(book_id):
# handle author(s) # handle author(s)
input_authors = to_save["author_name"].split('&') input_authors = to_save["author_name"].split('&')
input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors)) input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors))
# Remove duplicates in authors list
input_authors = helper.uniq(input_authors)
# we have all author names now # we have all author names now
if input_authors == ['']: if input_authors == ['']:
input_authors = [_(u'Unknown')] # prevent empty Author input_authors = [_(u'Unknown')] # prevent empty Author
...@@ -775,6 +778,9 @@ def upload(): ...@@ -775,6 +778,9 @@ def upload():
input_authors = authr.split('&') input_authors = authr.split('&')
# handle_authors(input_authors) # handle_authors(input_authors)
input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors)) input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors))
# Remove duplicates in authors list
input_authors = helper.uniq(input_authors)
# we have all author names now # we have all author names now
if input_authors == ['']: if input_authors == ['']:
input_authors = [_(u'Unknown')] # prevent empty Author input_authors = [_(u'Unknown')] # prevent empty Author
......
...@@ -122,9 +122,14 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension): ...@@ -122,9 +122,14 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
markupTree = etree.fromstring(markup) markupTree = etree.fromstring(markup)
# no matter xhtml or html with no namespace # no matter xhtml or html with no namespace
imgsrc = markupTree.xpath("//*[local-name() = 'img']/@src") imgsrc = markupTree.xpath("//*[local-name() = 'img']/@src")
# imgsrc maybe startwith "../"" so fullpath join then relpath to cwd # Alternative image source
filename = os.path.relpath(os.path.join(os.path.dirname(os.path.join(coverpath, coversection[0])), imgsrc[0])) if not len(imgsrc):
coverfile = extractCover(epubZip, filename, "", tmp_file_path) imgsrc = markupTree.xpath("//attribute::*[contains(local-name(), 'href')]")
if len(imgsrc):
# imgsrc maybe startwith "../"" so fullpath join then relpath to cwd
filename = os.path.relpath(os.path.join(os.path.dirname(os.path.join(coverpath, coversection[0])),
imgsrc[0]))
coverfile = extractCover(epubZip, filename, "", tmp_file_path)
else: else:
coverfile = extractCover(epubZip, coversection[0], coverpath, tmp_file_path) coverfile = extractCover(epubZip, coversection[0], coverpath, tmp_file_path)
......
...@@ -27,12 +27,14 @@ from sqlalchemy import Column, UniqueConstraint ...@@ -27,12 +27,14 @@ from sqlalchemy import Column, UniqueConstraint
from sqlalchemy import String, Integer from sqlalchemy import String, Integer
from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import OperationalError, InvalidRequestError
try: try:
from pydrive.auth import GoogleAuth from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive from pydrive.drive import GoogleDrive
from pydrive.auth import RefreshError from pydrive.auth import RefreshError
from apiclient import errors from apiclient import errors
from httplib2 import ServerNotFoundError
gdrive_support = True gdrive_support = True
except ImportError: except ImportError:
gdrive_support = False gdrive_support = False
...@@ -192,9 +194,13 @@ def getDrive(drive=None, gauth=None): ...@@ -192,9 +194,13 @@ def getDrive(drive=None, gauth=None):
return drive return drive
def listRootFolders(): def listRootFolders():
drive = getDrive(Gdrive.Instance().drive) try:
folder = "'root' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false" drive = getDrive(Gdrive.Instance().drive)
fileList = drive.ListFile({'q': folder}).GetList() folder = "'root' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false"
fileList = drive.ListFile({'q': folder}).GetList()
except ServerNotFoundError as e:
log.info("GDrive Error %s" % e)
fileList = []
return fileList return fileList
...@@ -474,8 +480,13 @@ def getChangeById (drive, change_id): ...@@ -474,8 +480,13 @@ def getChangeById (drive, change_id):
# Deletes the local hashes database to force search for new folder names # Deletes the local hashes database to force search for new folder names
def deleteDatabaseOnChange(): def deleteDatabaseOnChange():
session.query(GdriveId).delete() try:
session.commit() session.query(GdriveId).delete()
session.commit()
except (OperationalError, InvalidRequestError):
session.rollback()
log.info(u"GDrive DB is not Writeable")
def updateGdriveCalibreFromLocal(): def updateGdriveCalibreFromLocal():
copyToDrive(Gdrive.Instance().drive, config.config_calibre_dir, False, True) copyToDrive(Gdrive.Instance().drive, config.config_calibre_dir, False, True)
......
...@@ -468,6 +468,14 @@ def generate_random_password(): ...@@ -468,6 +468,14 @@ def generate_random_password():
passlen = 8 passlen = 8
return "".join(s[c % len(s)] for c in os.urandom(passlen)) return "".join(s[c % len(s)] for c in os.urandom(passlen))
def uniq(input):
output = []
for x in input:
if x not in output:
output.append(x)
return output
################################## External interface ################################## External interface
......
...@@ -64,7 +64,6 @@ def init_app(app, config): ...@@ -64,7 +64,6 @@ def init_app(app, config):
app.config['LDAP_OPENLDAP'] = bool(config.config_ldap_openldap) app.config['LDAP_OPENLDAP'] = bool(config.config_ldap_openldap)
app.config['LDAP_GROUP_OBJECT_FILTER'] = config.config_ldap_group_object_filter app.config['LDAP_GROUP_OBJECT_FILTER'] = config.config_ldap_group_object_filter
app.config['LDAP_GROUP_MEMBERS_FIELD'] = config.config_ldap_group_members_field app.config['LDAP_GROUP_MEMBERS_FIELD'] = config.config_ldap_group_members_field
# app.config['LDAP_CUSTOM_OPTIONS'] = {'OPT_NETWORK_TIMEOUT': 10}
_ldap.init_app(app) _ldap.init_app(app)
......
...@@ -27,8 +27,9 @@ from flask import Blueprint, request, flash, redirect, url_for ...@@ -27,8 +27,9 @@ from flask import Blueprint, request, flash, redirect, url_for
from flask_babel import gettext as _ from flask_babel import gettext as _
from flask_login import login_required, current_user from flask_login import login_required, current_user
from sqlalchemy.sql.expression import func from sqlalchemy.sql.expression import func
from sqlalchemy.exc import OperationalError, InvalidRequestError
from . import logger, ub, searched_ids, db, calibre_db from . import logger, ub, searched_ids, calibre_db
from .web import render_title_template from .web import render_title_template
...@@ -91,8 +92,16 @@ def add_to_shelf(shelf_id, book_id): ...@@ -91,8 +92,16 @@ def add_to_shelf(shelf_id, book_id):
shelf.books.append(ub.BookShelf(shelf=shelf.id, book_id=book_id, order=maxOrder + 1)) shelf.books.append(ub.BookShelf(shelf=shelf.id, book_id=book_id, order=maxOrder + 1))
shelf.last_modified = datetime.utcnow() shelf.last_modified = datetime.utcnow()
ub.session.merge(shelf) try:
ub.session.commit() ub.session.merge(shelf)
ub.session.commit()
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
if "HTTP_REFERER" in request.environ:
return redirect(request.environ["HTTP_REFERER"])
else:
return redirect(url_for('web.index'))
if not xhr: if not xhr:
flash(_(u"Book has been added to shelf: %(sname)s", sname=shelf.name), category="success") flash(_(u"Book has been added to shelf: %(sname)s", sname=shelf.name), category="success")
if "HTTP_REFERER" in request.environ: if "HTTP_REFERER" in request.environ:
...@@ -143,9 +152,13 @@ def search_to_shelf(shelf_id): ...@@ -143,9 +152,13 @@ def search_to_shelf(shelf_id):
maxOrder = maxOrder + 1 maxOrder = maxOrder + 1
shelf.books.append(ub.BookShelf(shelf=shelf.id, book_id=book, order=maxOrder)) shelf.books.append(ub.BookShelf(shelf=shelf.id, book_id=book, order=maxOrder))
shelf.last_modified = datetime.utcnow() shelf.last_modified = datetime.utcnow()
ub.session.merge(shelf) try:
ub.session.commit() ub.session.merge(shelf)
flash(_(u"Books have been added to shelf: %(sname)s", sname=shelf.name), category="success") ub.session.commit()
flash(_(u"Books have been added to shelf: %(sname)s", sname=shelf.name), category="success")
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
else: else:
flash(_(u"Could not add books to shelf: %(sname)s", sname=shelf.name), category="error") flash(_(u"Could not add books to shelf: %(sname)s", sname=shelf.name), category="error")
return redirect(url_for('web.index')) return redirect(url_for('web.index'))
...@@ -180,10 +193,17 @@ def remove_from_shelf(shelf_id, book_id): ...@@ -180,10 +193,17 @@ def remove_from_shelf(shelf_id, book_id):
return redirect(url_for('web.index')) return redirect(url_for('web.index'))
return "Book already removed from shelf", 410 return "Book already removed from shelf", 410
ub.session.delete(book_shelf) try:
shelf.last_modified = datetime.utcnow() ub.session.delete(book_shelf)
ub.session.commit() shelf.last_modified = datetime.utcnow()
ub.session.commit()
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
if "HTTP_REFERER" in request.environ:
return redirect(request.environ["HTTP_REFERER"])
else:
return redirect(url_for('web.index'))
if not xhr: if not xhr:
flash(_(u"Book has been removed from shelf: %(sname)s", sname=shelf.name), category="success") flash(_(u"Book has been removed from shelf: %(sname)s", sname=shelf.name), category="success")
if "HTTP_REFERER" in request.environ: if "HTTP_REFERER" in request.environ:
...@@ -235,7 +255,11 @@ def create_shelf(): ...@@ -235,7 +255,11 @@ def create_shelf():
ub.session.commit() ub.session.commit()
flash(_(u"Shelf %(title)s created", title=to_save["title"]), category="success") flash(_(u"Shelf %(title)s created", title=to_save["title"]), category="success")
return redirect(url_for('shelf.show_shelf', shelf_id=shelf.id)) return redirect(url_for('shelf.show_shelf', shelf_id=shelf.id))
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
except Exception: except Exception:
ub.session.rollback()
flash(_(u"There was an error"), category="error") flash(_(u"There was an error"), category="error")
return render_title_template('shelf_edit.html', shelf=shelf, title=_(u"Create a Shelf"), page="shelfcreate") return render_title_template('shelf_edit.html', shelf=shelf, title=_(u"Create a Shelf"), page="shelfcreate")
else: else:
...@@ -280,7 +304,11 @@ def edit_shelf(shelf_id): ...@@ -280,7 +304,11 @@ def edit_shelf(shelf_id):
try: try:
ub.session.commit() ub.session.commit()
flash(_(u"Shelf %(title)s changed", title=to_save["title"]), category="success") flash(_(u"Shelf %(title)s changed", title=to_save["title"]), category="success")
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
except Exception: except Exception:
ub.session.rollback()
flash(_(u"There was an error"), category="error") flash(_(u"There was an error"), category="error")
return render_title_template('shelf_edit.html', shelf=shelf, title=_(u"Edit a shelf"), page="shelfedit") return render_title_template('shelf_edit.html', shelf=shelf, title=_(u"Edit a shelf"), page="shelfedit")
else: else:
...@@ -298,11 +326,16 @@ def delete_shelf_helper(cur_shelf): ...@@ -298,11 +326,16 @@ def delete_shelf_helper(cur_shelf):
log.info("successfully deleted %s", cur_shelf) log.info("successfully deleted %s", cur_shelf)
@shelf.route("/shelf/delete/<int:shelf_id>") @shelf.route("/shelf/delete/<int:shelf_id>")
@login_required @login_required
def delete_shelf(shelf_id): def delete_shelf(shelf_id):
cur_shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() cur_shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
delete_shelf_helper(cur_shelf) try:
delete_shelf_helper(cur_shelf)
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
return redirect(url_for('web.index')) return redirect(url_for('web.index'))
...@@ -327,8 +360,12 @@ def show_shelf(shelf_type, shelf_id): ...@@ -327,8 +360,12 @@ def show_shelf(shelf_type, shelf_id):
cur_book = calibre_db.get_book(book.book_id) cur_book = calibre_db.get_book(book.book_id)
if not cur_book: if not cur_book:
log.info('Not existing book %s in %s deleted', book.book_id, shelf) log.info('Not existing book %s in %s deleted', book.book_id, shelf)
ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete() try:
ub.session.commit() ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete()
ub.session.commit()
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
return render_title_template(page, entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name), return render_title_template(page, entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name),
shelf=shelf, page="shelf") shelf=shelf, page="shelf")
else: else:
...@@ -348,7 +385,11 @@ def order_shelf(shelf_id): ...@@ -348,7 +385,11 @@ def order_shelf(shelf_id):
setattr(book, 'order', to_save[str(book.book_id)]) setattr(book, 'order', to_save[str(book.book_id)])
counter += 1 counter += 1
# if order diffrent from before -> shelf.last_modified = datetime.utcnow() # if order diffrent from before -> shelf.last_modified = datetime.utcnow()
ub.session.commit() try:
ub.session.commit()
except (OperationalError, InvalidRequestError):
ub.session.rollback()
flash(_(u"Settings DB is not Writeable"), category="error")
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
result = list() result = list()
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{{_('Open the .kobo/Kobo eReader.conf file in a text editor and add (or edit):')}}</a> {{_('Open the .kobo/Kobo eReader.conf file in a text editor and add (or edit):')}}</a>
</p> </p>
<p> <p>
{% if not warning %}'api_endpoint='{{kobo_auth_url}}{% else %}{{warning}}{% endif %}</a> {% if not warning %}api_endpoint={{kobo_auth_url}}{% else %}{{warning}}{% endif %}</a>
</p> </p>
<p> <p>
</div> </div>
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
from __future__ import division, print_function, unicode_literals from __future__ import division, print_function, unicode_literals
import os import os
import sys
import datetime import datetime
import itertools import itertools
import uuid import uuid
...@@ -611,9 +612,13 @@ def migrate_Database(session): ...@@ -611,9 +612,13 @@ def migrate_Database(session):
session.commit() session.commit()
# Remove login capability of user Guest # Remove login capability of user Guest
conn = engine.connect() try:
conn.execute("UPDATE user SET password='' where nickname = 'Guest' and password !=''") conn = engine.connect()
session.commit() conn.execute("UPDATE user SET password='' where nickname = 'Guest' and password !=''")
session.commit()
except exc.OperationalError:
print('Settings database is not writeable. Exiting...')
sys.exit(1)
def clean_database(session): def clean_database(session):
......
...@@ -446,7 +446,7 @@ def toggle_read(book_id): ...@@ -446,7 +446,7 @@ def toggle_read(book_id):
new_cc = cc_class(value=1, book=book_id) new_cc = cc_class(value=1, book=book_id)
calibre_db.session.add(new_cc) calibre_db.session.add(new_cc)
calibre_db.session.commit() calibre_db.session.commit()
except KeyError: except (KeyError, AttributeError):
log.error(u"Custom Column No.%d is not exisiting in calibre database", config.config_read_column) log.error(u"Custom Column No.%d is not exisiting in calibre database", config.config_read_column)
except OperationalError as e: except OperationalError as e:
calibre_db.session.rollback() calibre_db.session.rollback()
...@@ -1252,7 +1252,7 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs) ...@@ -1252,7 +1252,7 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs)
db_filter, db_filter,
order, order,
db.cc_classes[config.config_read_column]) db.cc_classes[config.config_read_column])
except KeyError: except (KeyError, AttributeError):
log.error("Custom Column No.%d is not existing in calibre database", config.config_read_column) log.error("Custom Column No.%d is not existing in calibre database", config.config_read_column)
if not as_xml: if not as_xml:
flash(_("Custom Column No.%(column)d is not existing in calibre database", flash(_("Custom Column No.%(column)d is not existing in calibre database",
...@@ -1482,7 +1482,7 @@ def login(): ...@@ -1482,7 +1482,7 @@ def login():
log.info('Login failed for user "%s" IP-adress: %s', form['username'], ipAdress) log.info('Login failed for user "%s" IP-adress: %s', form['username'], ipAdress)
flash(_(u"Wrong Username or Password"), category="error") flash(_(u"Wrong Username or Password"), category="error")
next_url = url_for('web.index') next_url = request.args.get('next', default=url_for("web.index"), type=str)
return render_title_template('login.html', return render_title_template('login.html',
title=_(u"login"), title=_(u"login"),
next_url=next_url, next_url=next_url,
...@@ -1759,7 +1759,7 @@ def show_book(book_id): ...@@ -1759,7 +1759,7 @@ def show_book(book_id):
try: try:
matching_have_read_book = getattr(entries, 'custom_column_' + str(config.config_read_column)) matching_have_read_book = getattr(entries, 'custom_column_' + str(config.config_read_column))
have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].value have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].value
except KeyError: except (KeyError, AttributeError):
log.error("Custom Column No.%d is not existing in calibre database", config.config_read_column) log.error("Custom Column No.%d is not existing in calibre database", config.config_read_column)
have_read = None have_read = None
......
This diff is collapsed.
# GDrive Integration # GDrive Integration
google-api-python-client==1.7.11,<1.8.0 google-api-python-client==1.7.11,<1.8.0
#gevent>=1.2.1,<20.6.0 gevent>=1.2.1,<20.6.0
greenlet>=0.4.12,<0.5.0 greenlet>=0.4.12,<0.5.0
httplib2>=0.9.2,<0.18.0 httplib2>=0.9.2,<0.18.0
oauth2client>=4.0.0,<4.1.4 oauth2client>=4.0.0,<4.1.4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment