Merge branch 'master' into Develop
# Conflicts: # cps/admin.py # cps/config_sql.py # cps/search.py # cps/templates/admin.html # cps/web.py # setup.cfg # test/Calibre-Web TestSummary_Linux.html
This commit is contained in:
166
cps/web.py
Executable file → Normal file
166
cps/web.py
Executable file → Normal file
@@ -32,7 +32,7 @@ from flask_babel import lazy_gettext as N_
|
||||
from flask_babel import get_locale
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
from sqlalchemy.exc import IntegrityError, InvalidRequestError, OperationalError
|
||||
from sqlalchemy.sql.expression import text, func, false, not_, and_
|
||||
from sqlalchemy.sql.expression import text, func, false, not_, and_, or_
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
from sqlalchemy.sql.functions import coalesce
|
||||
|
||||
@@ -86,15 +86,18 @@ except ImportError:
|
||||
def add_security_headers(resp):
|
||||
csp = "default-src 'self'"
|
||||
csp += ''.join([' ' + host for host in config.config_trustedhosts.strip().split(',')])
|
||||
csp += " 'unsafe-inline' 'unsafe-eval'; font-src 'self' data:; img-src 'self' "
|
||||
csp += " 'unsafe-inline' 'unsafe-eval'; font-src 'self' data:; img-src 'self'"
|
||||
if request.path.startswith("/author/") and config.config_use_goodreads:
|
||||
csp += "images.gr-assets.com i.gr-assets.com s.gr-assets.com"
|
||||
csp += " images.gr-assets.com i.gr-assets.com s.gr-assets.com"
|
||||
csp += " data:"
|
||||
resp.headers['Content-Security-Policy'] = csp
|
||||
if request.endpoint == "edit-book.show_edit_book" or config.config_use_google_drive:
|
||||
resp.headers['Content-Security-Policy'] += " *"
|
||||
csp += " *;"
|
||||
elif request.endpoint == "web.read_book":
|
||||
resp.headers['Content-Security-Policy'] += " blob:;style-src-elem 'self' blob: 'unsafe-inline';"
|
||||
csp += " style-src-elem 'self' blob: 'unsafe-inline';"
|
||||
else:
|
||||
csp += ";"
|
||||
csp += "object-src: 'none';"
|
||||
resp.headers['Content-Security-Policy'] = csp
|
||||
resp.headers['X-Content-Type-Options'] = 'nosniff'
|
||||
resp.headers['X-Frame-Options'] = 'SAMEORIGIN'
|
||||
resp.headers['X-XSS-Protection'] = '1; mode=block'
|
||||
@@ -406,7 +409,7 @@ def render_books_list(data, sort_param, book_id, page):
|
||||
db.Books.id == db.books_series_link.c.book,
|
||||
db.Series)
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
||||
title=_(u"Books"), page=website, order=order[1])
|
||||
title=_("Books"), page=website, order=order[1])
|
||||
|
||||
|
||||
def render_rated_books(page, book_id, order):
|
||||
@@ -421,7 +424,7 @@ def render_rated_books(page, book_id, order):
|
||||
db.Series)
|
||||
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
||||
id=book_id, title=_(u"Top Rated Books"), page="rated", order=order[1])
|
||||
id=book_id, title=_("Top Rated Books"), page="rated", order=order[1])
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -433,7 +436,7 @@ def render_discover_books(book_id):
|
||||
config_read_column=config.config_read_column)
|
||||
pagination = Pagination(1, config.config_books_per_page, config.config_books_per_page)
|
||||
return render_title_template('index.html', random=false(), entries=entries, pagination=pagination, id=book_id,
|
||||
title=_(u"Discover (Random Books)"), page="discover")
|
||||
title=_("Discover (Random Books)"), page="discover")
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -441,7 +444,7 @@ def render_discover_books(book_id):
|
||||
def render_hot_books(page, order):
|
||||
if current_user.check_visibility(constants.SIDEBAR_HOT):
|
||||
if order[1] not in ['hotasc', 'hotdesc']:
|
||||
# Unary expression comparsion only working (for this expression) in sqlalchemy 1.4+
|
||||
# Unary expression comparison only working (for this expression) in sqlalchemy 1.4+
|
||||
# if not (order[0][0].compare(func.count(ub.Downloads.book_id).desc()) or
|
||||
# order[0][0].compare(func.count(ub.Downloads.book_id).asc())):
|
||||
order = [func.count(ub.Downloads.book_id).desc()], 'hotdesc'
|
||||
@@ -469,7 +472,7 @@ def render_hot_books(page, order):
|
||||
num_books = entries.__len__()
|
||||
pagination = Pagination(page, config.config_books_per_page, num_books)
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
||||
title=_(u"Hot Books (Most Downloaded)"), page="hot", order=order[1])
|
||||
title=_("Hot Books (Most Downloaded)"), page="hot", order=order[1])
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -500,7 +503,7 @@ def render_downloaded_books(page, order, user_id):
|
||||
entries=entries,
|
||||
pagination=pagination,
|
||||
id=user_id,
|
||||
title=_(u"Downloaded books by %(user)s", user=user.name),
|
||||
title=_("Downloaded books by %(user)s", user=user.name),
|
||||
page="download",
|
||||
order=order[1])
|
||||
else:
|
||||
@@ -517,7 +520,7 @@ def render_author_books(page, author_id, order):
|
||||
db.books_series_link.c.book == db.Books.id,
|
||||
db.Series)
|
||||
if entries is None or not len(entries):
|
||||
flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"),
|
||||
flash(_("Oops! Selected book is unavailable. File does not exist or is not accessible"),
|
||||
category="error")
|
||||
return redirect(url_for("web.index"))
|
||||
if constants.sqlalchemy_version2:
|
||||
@@ -533,7 +536,7 @@ def render_author_books(page, author_id, order):
|
||||
book_entries = [entry.Books for entry in entries]
|
||||
other_books = services.goodreads_support.get_other_books(author_info, book_entries)
|
||||
return render_title_template('author.html', entries=entries, pagination=pagination, id=author_id,
|
||||
title=_(u"Author: %(name)s", name=author_name), author=author_info,
|
||||
title=_("Author: %(name)s", name=author_name), author=author_info,
|
||||
other_books=other_books, page="author", order=order[1])
|
||||
|
||||
|
||||
@@ -569,7 +572,7 @@ def render_publisher_books(page, book_id, order):
|
||||
abort(404)
|
||||
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id,
|
||||
title=_(u"Publisher: %(name)s", name=publisher),
|
||||
title=_("Publisher: %(name)s", name=publisher),
|
||||
page="publisher",
|
||||
order=order[1])
|
||||
|
||||
@@ -597,20 +600,22 @@ def render_series_books(page, book_id, order):
|
||||
else:
|
||||
abort(404)
|
||||
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
||||
title=_(u"Series: %(serie)s", serie=series_name), page="series", order=order[1])
|
||||
title=_("Series: %(serie)s", serie=series_name), page="series", order=order[1])
|
||||
|
||||
|
||||
def render_ratings_books(page, book_id, order):
|
||||
if book_id == '-1':
|
||||
db_filter = coalesce(db.Ratings.rating, 0) < 1
|
||||
entries, random, pagination = calibre_db.fill_indexpage(page, 0,
|
||||
db.Books,
|
||||
db.Books.ratings == None,
|
||||
db_filter,
|
||||
[order[0][0]],
|
||||
True, config.config_read_column,
|
||||
db.books_series_link,
|
||||
db.Books.id == db.books_series_link.c.book,
|
||||
db.Series)
|
||||
title = _(u"Rating: None")
|
||||
db.Series,
|
||||
db.books_ratings_link, db.Ratings)
|
||||
title = _("Rating: None")
|
||||
rating = -1
|
||||
else:
|
||||
name = calibre_db.session.query(db.Ratings).filter(db.Ratings.id == book_id).first()
|
||||
@@ -619,7 +624,7 @@ def render_ratings_books(page, book_id, order):
|
||||
db.Books.ratings.any(db.Ratings.id == book_id),
|
||||
[order[0][0]],
|
||||
True, config.config_read_column)
|
||||
title = _(u"Rating: %(rating)s stars", rating=int(name.rating / 2))
|
||||
title = _("Rating: %(rating)s stars", rating=int(name.rating / 2))
|
||||
rating = name.rating
|
||||
if title and rating <= 10:
|
||||
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
||||
@@ -637,7 +642,7 @@ def render_formats_books(page, book_id, order):
|
||||
[order[0][0]],
|
||||
True, config.config_read_column)
|
||||
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
||||
title=_(u"File format: %(format)s", format=name.format),
|
||||
title=_("File format: %(format)s", format=name.format),
|
||||
page="formats",
|
||||
order=order[1])
|
||||
else:
|
||||
@@ -674,7 +679,7 @@ def render_category_books(page, book_id, order):
|
||||
else:
|
||||
abort(404)
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id,
|
||||
title=_(u"Category: %(name)s", name=tagsname), page="category", order=order[1])
|
||||
title=_("Category: %(name)s", name=tagsname), page="category", order=order[1])
|
||||
|
||||
|
||||
def render_language_books(page, name, order):
|
||||
@@ -701,7 +706,7 @@ def render_language_books(page, name, order):
|
||||
[order[0][0]],
|
||||
True, config.config_read_column)
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=name,
|
||||
title=_(u"Language: %(name)s", name=lang_name), page="language", order=order[1])
|
||||
title=_("Language: %(name)s", name=lang_name), page="language", order=order[1])
|
||||
|
||||
|
||||
def render_read_books(page, are_read, as_xml=False, order=None):
|
||||
@@ -740,10 +745,10 @@ def render_read_books(page, are_read, as_xml=False, order=None):
|
||||
return entries, pagination
|
||||
else:
|
||||
if are_read:
|
||||
name = _(u'Read Books') + ' (' + str(pagination.total_count) + ')'
|
||||
name = _('Read Books') + ' (' + str(pagination.total_count) + ')'
|
||||
page_name = "read"
|
||||
else:
|
||||
name = _(u'Unread Books') + ' (' + str(pagination.total_count) + ')'
|
||||
name = _('Unread Books') + ' (' + str(pagination.total_count) + ')'
|
||||
page_name = "unread"
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
||||
title=name, page=page_name, order=order[1])
|
||||
@@ -766,7 +771,7 @@ def render_archived_books(page, sort_param):
|
||||
True,
|
||||
True, config.config_read_column)
|
||||
|
||||
name = _(u'Archived Books') + ' (' + str(len(archived_book_ids)) + ')'
|
||||
name = _('Archived Books') + ' (' + str(len(archived_book_ids)) + ')'
|
||||
page_name = "archived"
|
||||
return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
|
||||
title=name, page=page_name, order=sort_param[1])
|
||||
@@ -797,7 +802,7 @@ def books_list(data, sort_param, book_id, page):
|
||||
def books_table():
|
||||
visibility = current_user.view_settings.get('table', {})
|
||||
cc = calibre_db.get_cc_columns(config, filter_config_custom_read=True)
|
||||
return render_title_template('book_table.html', title=_(u"Books List"), cc=cc, page="book_table",
|
||||
return render_title_template('book_table.html', title=_("Books List"), cc=cc, page="book_table",
|
||||
visiblility=visibility)
|
||||
|
||||
|
||||
@@ -918,7 +923,7 @@ def author_list():
|
||||
for entry in author_copy:
|
||||
entry.Authors.name = entry.Authors.name.replace('|', ',')
|
||||
return render_title_template('list.html', entries=author_copy, folder='web.books_list', charlist=char_list,
|
||||
title=u"Authors", page="authorlist", data='author', order=order_no)
|
||||
title="Authors", page="authorlist", data='author', order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -939,7 +944,7 @@ def download_list():
|
||||
.filter(ub.User.role.op('&')(constants.ROLE_ANONYMOUS) != constants.ROLE_ANONYMOUS) \
|
||||
.group_by(func.upper(func.substr(ub.User.name, 1, 1))).all()
|
||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||
title=_(u"Downloads"), page="downloadlist", data="download", order=order_no)
|
||||
title=_("Downloads"), page="downloadlist", data="download", order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -967,7 +972,7 @@ def publisher_list():
|
||||
entries = sorted(entries, key=lambda x: x[0].name.lower(), reverse=not order_no)
|
||||
char_list = generate_char_list(entries)
|
||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||
title=_(u"Publishers"), page="publisherlist", data="publisher", order=order_no)
|
||||
title=_("Publishers"), page="publisherlist", data="publisher", order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -996,14 +1001,14 @@ def series_list():
|
||||
entries.append([db.Category(_("None"), "-1"), no_series_count])
|
||||
entries = sorted(entries, key=lambda x: x[0].name.lower(), reverse=not order_no)
|
||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||
title=_(u"Series"), page="serieslist", data="series", order=order_no)
|
||||
title=_("Series"), page="serieslist", data="series", order=order_no)
|
||||
else:
|
||||
entries = calibre_db.session.query(db.Books, func.count('books_series_link').label('count'),
|
||||
func.max(db.Books.series_index), db.Books.id) \
|
||||
.join(db.books_series_link).join(db.Series).filter(calibre_db.common_filters()) \
|
||||
.group_by(text('books_series_link.series')).order_by(order).all()
|
||||
return render_title_template('grid.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||
title=_(u"Series"), page="serieslist", data="series", bodyClass="grid-view",
|
||||
title=_("Series"), page="serieslist", data="series", bodyClass="grid-view",
|
||||
order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
@@ -1022,16 +1027,17 @@ def ratings_list():
|
||||
entries = calibre_db.session.query(db.Ratings, func.count('books_ratings_link.book').label('count'),
|
||||
(db.Ratings.rating / 2).label('name')) \
|
||||
.join(db.books_ratings_link).join(db.Books).filter(calibre_db.common_filters()) \
|
||||
.filter(db.Ratings.rating > 0) \
|
||||
.group_by(text('books_ratings_link.rating')).order_by(order).all()
|
||||
no_rating_count = (calibre_db.session.query(db.Books)
|
||||
.outerjoin(db.books_ratings_link).outerjoin(db.Ratings)
|
||||
.filter(db.Ratings.rating == None)
|
||||
.filter(or_(db.Ratings.rating == None, db.Ratings.rating == 0))
|
||||
.filter(calibre_db.common_filters())
|
||||
.count())
|
||||
entries.append([db.Category(_("None"), "-1", -1), no_rating_count])
|
||||
entries = sorted(entries, key=lambda x: x[0].rating, reverse=not order_no)
|
||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
||||
title=_(u"Ratings list"), page="ratingslist", data="ratings", order=order_no)
|
||||
title=_("Ratings list"), page="ratingslist", data="ratings", order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -1058,7 +1064,7 @@ def formats_list():
|
||||
if no_format_count:
|
||||
entries.append([db.Category(_("None"), "-1"), no_format_count])
|
||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
||||
title=_(u"File formats list"), page="formatslist", data="formats", order=order_no)
|
||||
title=_("File formats list"), page="formatslist", data="formats", order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -1066,12 +1072,12 @@ def formats_list():
|
||||
@web.route("/language")
|
||||
@login_required_if_no_ano
|
||||
def language_overview():
|
||||
if current_user.check_visibility(constants.SIDEBAR_LANGUAGE) and current_user.filter_language() == u"all":
|
||||
if current_user.check_visibility(constants.SIDEBAR_LANGUAGE) and current_user.filter_language() == "all":
|
||||
order_no = 0 if current_user.get_view_property('language', 'dir') == 'desc' else 1
|
||||
languages = calibre_db.speaking_language(reverse_order=not order_no, with_count=True)
|
||||
char_list = generate_char_list(languages)
|
||||
return render_title_template('list.html', entries=languages, folder='web.books_list', charlist=char_list,
|
||||
title=_(u"Languages"), page="langlist", data="language", order=order_no)
|
||||
title=_("Languages"), page="langlist", data="language", order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -1088,7 +1094,7 @@ def category_list():
|
||||
order_no = 1
|
||||
entries = calibre_db.session.query(db.Tags, func.count('books_tags_link.book').label('count')) \
|
||||
.join(db.books_tags_link).join(db.Books).order_by(order).filter(calibre_db.common_filters()) \
|
||||
.group_by(text('books_tags_link.tag')).all()
|
||||
.group_by(db.Tags.id).all()
|
||||
no_tag_count = (calibre_db.session.query(db.Books)
|
||||
.outerjoin(db.books_tags_link).outerjoin(db.Tags)
|
||||
.filter(db.Tags.name == None)
|
||||
@@ -1099,7 +1105,7 @@ def category_list():
|
||||
entries = sorted(entries, key=lambda x: x[0].name.lower(), reverse=not order_no)
|
||||
char_list = generate_char_list(entries)
|
||||
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=char_list,
|
||||
title=_(u"Categories"), page="catlist", data="category", order=order_no)
|
||||
title=_("Categories"), page="catlist", data="category", order=order_no)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
@@ -1191,22 +1197,22 @@ def download_link(book_id, book_format, anyname):
|
||||
|
||||
|
||||
@web.route('/send/<int:book_id>/<book_format>/<int:convert>', methods=["POST"])
|
||||
@login_required
|
||||
@login_required_if_no_ano
|
||||
@download_required
|
||||
def send_to_ereader(book_id, book_format, convert):
|
||||
if not config.get_mail_server_configured():
|
||||
flash(_(u"Please configure the SMTP mail settings first..."), category="error")
|
||||
flash(_("Please configure the SMTP mail settings first."), category="error")
|
||||
elif current_user.kindle_mail:
|
||||
result = send_mail(book_id, book_format, convert, current_user.kindle_mail, config.config_calibre_dir,
|
||||
current_user.name)
|
||||
if result is None:
|
||||
flash(_(u"Book successfully queued for sending to %(kindlemail)s", kindlemail=current_user.kindle_mail),
|
||||
flash(_("Success! Book queued for sending to %(eReadermail)s", eReadermail=current_user.kindle_mail),
|
||||
category="success")
|
||||
ub.update_download(book_id, int(current_user.id))
|
||||
else:
|
||||
flash(_(u"Oops! There was an error sending this book: %(res)s", res=result), category="error")
|
||||
flash(_("Oops! There was an error sending book: %(res)s", res=result), category="error")
|
||||
else:
|
||||
flash(_(u"Please update your profile with a valid Send to Kindle E-mail Address."), category="error")
|
||||
flash(_("Oops! Please update your profile with a valid eReader Email."), category="error")
|
||||
if "HTTP_REFERER" in request.environ:
|
||||
return redirect(request.environ["HTTP_REFERER"])
|
||||
else:
|
||||
@@ -1223,14 +1229,14 @@ def register():
|
||||
if current_user is not None and current_user.is_authenticated:
|
||||
return redirect(url_for('web.index'))
|
||||
if not config.get_mail_server_configured():
|
||||
flash(_(u"E-Mail server is not configured, please contact your administrator!"), category="error")
|
||||
flash(_("Oops! Email server is not configured, please contact your administrator."), category="error")
|
||||
return render_title_template('register.html', title=_("Register"), page="register")
|
||||
|
||||
if request.method == "POST":
|
||||
to_save = request.form.to_dict()
|
||||
nickname = to_save.get("email", "").strip() if config.config_register_email else to_save.get('name')
|
||||
if not nickname or not to_save.get("email"):
|
||||
flash(_(u"Please fill out all fields!"), category="error")
|
||||
flash(_("Oops! Please complete all fields."), category="error")
|
||||
return render_title_template('register.html', title=_("Register"), page="register")
|
||||
try:
|
||||
nickname = check_username(nickname)
|
||||
@@ -1246,6 +1252,7 @@ def register():
|
||||
password = generate_random_password()
|
||||
content.password = generate_password_hash(password)
|
||||
content.role = config.config_default_role
|
||||
content.locale = config.config_default_locale
|
||||
content.sidebar_view = config.config_default_show
|
||||
try:
|
||||
ub.session.add(content)
|
||||
@@ -1255,14 +1262,14 @@ def register():
|
||||
send_registration_mail(to_save.get("email", "").strip(), nickname, password)
|
||||
except Exception:
|
||||
ub.session.rollback()
|
||||
flash(_(u"An unknown error occurred. Please try again later."), category="error")
|
||||
flash(_("Oops! An unknown error occurred. Please try again later."), category="error")
|
||||
return render_title_template('register.html', title=_("Register"), page="register")
|
||||
else:
|
||||
flash(_(u"Your e-mail is not allowed to register"), category="error")
|
||||
log.warning('Registering failed for user "{}" e-mail address: {}'.format(nickname,
|
||||
flash(_("Oops! Your Email is not allowed."), category="error")
|
||||
log.warning('Registering failed for user "{}" Email: {}'.format(nickname,
|
||||
to_save.get("email","")))
|
||||
return render_title_template('register.html', title=_("Register"), page="register")
|
||||
flash(_(u"Confirmation e-mail was send to your e-mail account."), category="success")
|
||||
flash(_("Success! Confirmation Email has been sent."), category="success")
|
||||
return redirect(url_for('web.login'))
|
||||
|
||||
if feature_support['oauth']:
|
||||
@@ -1283,7 +1290,7 @@ def render_login():
|
||||
if url_for("web.logout") == next_url:
|
||||
next_url = url_for("web.index")
|
||||
return render_title_template('login.html',
|
||||
title=_(u"Login"),
|
||||
title=_("Login"),
|
||||
next_url=next_url,
|
||||
config=config,
|
||||
oauth_check=oauth_check,
|
||||
@@ -1377,7 +1384,7 @@ def logout():
|
||||
logout_user()
|
||||
if feature_support['oauth'] and (config.config_login_type == 2 or config.config_login_type == 3):
|
||||
logout_oauth_user()
|
||||
log.debug(u"User logged out")
|
||||
log.debug("User logged out")
|
||||
return redirect(url_for('web.login'))
|
||||
|
||||
|
||||
@@ -1386,13 +1393,16 @@ def change_profile(kobo_support, local_oauth_check, oauth_status, translations,
|
||||
to_save = request.form.to_dict()
|
||||
current_user.random_books = 0
|
||||
try:
|
||||
if current_user.role_passwd() or current_user.role_admin():
|
||||
if to_save.get('password', "") != "":
|
||||
current_user.password = generate_password_hash(valid_password(to_save['password']))
|
||||
if to_save.get("kindle_mail", current_user.kindle_mail) != current_user.kindle_mail:
|
||||
current_user.kindle_mail = valid_email(to_save.get("kindle_mail"))
|
||||
if to_save.get("email", current_user.email) != current_user.email:
|
||||
current_user.email = check_email(to_save.get("email"))
|
||||
if current_user.role_passwd() or current_user.role_admin():
|
||||
if to_save.get('password', "") != "":
|
||||
current_user.password = generate_password_hash(to_save.get("password"))
|
||||
if to_save.get("eReader_mail", current_user.kindle_mail) != current_user.kindle_mail:
|
||||
current_user.kindle_mail = valid_email(to_save.get("eReader_mail"))
|
||||
new_email = valid_email(to_save.get("email", current_user.email))
|
||||
if not new_email:
|
||||
raise Exception(_("Email can't be empty and has to be a valid Email"))
|
||||
if new_email != current_user.email:
|
||||
current_user.email = check_email(new_email)
|
||||
if current_user.role_admin():
|
||||
if to_save.get("name", current_user.name) != current_user.name:
|
||||
# Query username, if not existing, change
|
||||
@@ -1416,7 +1426,7 @@ def change_profile(kobo_support, local_oauth_check, oauth_status, translations,
|
||||
translations=translations,
|
||||
profile=1,
|
||||
languages=languages,
|
||||
title=_(u"%(name)s's profile", name=current_user.name),
|
||||
title=_("%(name)s's Profile", name=current_user.name),
|
||||
page="me",
|
||||
kobo_support=kobo_support,
|
||||
registered_oauth=local_oauth_check,
|
||||
@@ -1432,16 +1442,16 @@ def change_profile(kobo_support, local_oauth_check, oauth_status, translations,
|
||||
|
||||
try:
|
||||
ub.session.commit()
|
||||
flash(_(u"Profile updated"), category="success")
|
||||
log.debug(u"Profile updated")
|
||||
flash(_("Success! Profile Updated"), category="success")
|
||||
log.debug("Profile updated")
|
||||
except IntegrityError:
|
||||
ub.session.rollback()
|
||||
flash(_(u"Found an existing account for this e-mail address"), category="error")
|
||||
log.debug(u"Found an existing account for this e-mail address")
|
||||
flash(_("Oops! An account already exists for this Email."), category="error")
|
||||
log.debug("Found an existing account for this Email")
|
||||
except OperationalError as e:
|
||||
ub.session.rollback()
|
||||
log.error("Database error: %s", e)
|
||||
flash(_(u"Database error: %(error)s.", error=e), category="error")
|
||||
flash(_("Oops! Database Error: %(error)s.", error=e), category="error")
|
||||
|
||||
|
||||
@web.route("/me", methods=["GET", "POST"])
|
||||
@@ -1466,7 +1476,7 @@ def profile():
|
||||
content=current_user,
|
||||
config=config,
|
||||
kobo_support=kobo_support,
|
||||
title=_(u"%(name)s's profile", name=current_user.name),
|
||||
title=_("%(name)s's Profile", name=current_user.name),
|
||||
page="me",
|
||||
registered_oauth=local_oauth_check,
|
||||
oauth_status=oauth_status)
|
||||
@@ -1483,9 +1493,9 @@ def read_book(book_id, book_format):
|
||||
book.ordered_authors = calibre_db.order_authors([book], False)
|
||||
|
||||
if not book:
|
||||
flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"),
|
||||
flash(_("Oops! Selected book is unavailable. File does not exist or is not accessible"),
|
||||
category="error")
|
||||
log.debug(u"Oops! Selected book title is unavailable. File does not exist or is not accessible")
|
||||
log.debug("Selected book is unavailable. File does not exist or is not accessible")
|
||||
return redirect(url_for("web.index"))
|
||||
|
||||
# check if book has a bookmark
|
||||
@@ -1495,22 +1505,22 @@ def read_book(book_id, book_format):
|
||||
ub.Bookmark.book_id == book_id,
|
||||
ub.Bookmark.format == book_format.upper())).first()
|
||||
if book_format.lower() == "epub":
|
||||
log.debug(u"Start epub reader for %d", book_id)
|
||||
log.debug("Start epub reader for %d", book_id)
|
||||
return render_title_template('read.html', bookid=book_id, title=book.title, bookmark=bookmark)
|
||||
elif book_format.lower() == "pdf":
|
||||
log.debug(u"Start pdf reader for %d", book_id)
|
||||
log.debug("Start pdf reader for %d", book_id)
|
||||
return render_title_template('readpdf.html', pdffile=book_id, title=book.title)
|
||||
elif book_format.lower() == "txt":
|
||||
log.debug(u"Start txt reader for %d", book_id)
|
||||
log.debug("Start txt reader for %d", book_id)
|
||||
return render_title_template('readtxt.html', txtfile=book_id, title=book.title)
|
||||
elif book_format.lower() == "djvu":
|
||||
log.debug(u"Start djvu reader for %d", book_id)
|
||||
log.debug("Start djvu reader for %d", book_id)
|
||||
return render_title_template('readdjvu.html', djvufile=book_id, title=book.title)
|
||||
else:
|
||||
for fileExt in constants.EXTENSIONS_AUDIO:
|
||||
if book_format.lower() == fileExt:
|
||||
entries = calibre_db.get_filtered_book(book_id)
|
||||
log.debug(u"Start mp3 listening for %d", book_id)
|
||||
log.debug("Start mp3 listening for %d", book_id)
|
||||
return render_title_template('listenmp3.html', mp3file=book_id, audioformat=book_format.lower(),
|
||||
entry=entries, bookmark=bookmark)
|
||||
for fileExt in ["cbr", "cbt", "cbz"]:
|
||||
@@ -1521,11 +1531,11 @@ def read_book(book_id, book_format):
|
||||
title = title + " - " + book.series[0].name
|
||||
if book.series_index:
|
||||
title = title + " #" + '{0:.2f}'.format(book.series_index).rstrip('0').rstrip('.')
|
||||
log.debug(u"Start comic reader for %d", book_id)
|
||||
log.debug("Start comic reader for %d", book_id)
|
||||
return render_title_template('readcbr.html', comicfile=all_name, title=title,
|
||||
extension=fileExt)
|
||||
log.debug(u"Oops! Selected book title is unavailable. File does not exist or is not accessible")
|
||||
flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"),
|
||||
log.debug("Selected book is unavailable. File does not exist or is not accessible")
|
||||
flash(_("Oops! Selected book is unavailable. File does not exist or is not accessible"),
|
||||
category="error")
|
||||
return redirect(url_for("web.index"))
|
||||
|
||||
@@ -1569,7 +1579,7 @@ def show_book(book_id):
|
||||
books_shelfs=book_in_shelves,
|
||||
page="book")
|
||||
else:
|
||||
log.debug(u"Oops! Selected book title is unavailable. File does not exist or is not accessible")
|
||||
flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"),
|
||||
log.debug("Selected book is unavailable. File does not exist or is not accessible")
|
||||
flash(_("Oops! Selected book is unavailable. File does not exist or is not accessible"),
|
||||
category="error")
|
||||
return redirect(url_for("web.index"))
|
||||
|
||||
Reference in New Issue
Block a user