|
|
@ -57,10 +57,11 @@ feature_support = {
|
|
|
|
'ldap': bool(services.ldap),
|
|
|
|
'ldap': bool(services.ldap),
|
|
|
|
'goodreads': bool(services.goodreads_support),
|
|
|
|
'goodreads': bool(services.goodreads_support),
|
|
|
|
'kobo': bool(services.kobo)
|
|
|
|
'kobo': bool(services.kobo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from .oauth_bb import oauth_check, register_user_with_oauth, logout_oauth_user, get_oauth_status
|
|
|
|
from .oauth_bb import oauth_check, register_user_with_oauth, logout_oauth_user, get_oauth_status
|
|
|
|
|
|
|
|
|
|
|
|
feature_support['oauth'] = True
|
|
|
|
feature_support['oauth'] = True
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
feature_support['oauth'] = False
|
|
|
|
feature_support['oauth'] = False
|
|
|
@ -110,14 +111,15 @@ for ex in default_exceptions:
|
|
|
|
elif ex == 500:
|
|
|
|
elif ex == 500:
|
|
|
|
app.register_error_handler(ex, internal_error)
|
|
|
|
app.register_error_handler(ex, internal_error)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web = Blueprint('web', __name__)
|
|
|
|
web = Blueprint('web', __name__)
|
|
|
|
log = logger.create()
|
|
|
|
log = logger.create()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ################################### Login logic and rights management ###############################################
|
|
|
|
# ################################### Login logic and rights management ###############################################
|
|
|
|
def _fetch_user_by_name(username):
|
|
|
|
def _fetch_user_by_name(username):
|
|
|
|
return ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == username.lower()).first()
|
|
|
|
return ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == username.lower()).first()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@lm.user_loader
|
|
|
|
@lm.user_loader
|
|
|
|
def load_user(user_id):
|
|
|
|
def load_user(user_id):
|
|
|
|
return ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first()
|
|
|
|
return ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first()
|
|
|
@ -165,6 +167,7 @@ def login_required_if_no_ano(func):
|
|
|
|
if config.config_anonbrowse == 1:
|
|
|
|
if config.config_anonbrowse == 1:
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
return login_required(func)(*args, **kwargs)
|
|
|
|
return login_required(func)(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
return decorated_view
|
|
|
|
return decorated_view
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -256,8 +259,9 @@ def edit_required(f):
|
|
|
|
|
|
|
|
|
|
|
|
# Returns the template for rendering and includes the instance name
|
|
|
|
# Returns the template for rendering and includes the instance name
|
|
|
|
def render_title_template(*args, **kwargs):
|
|
|
|
def render_title_template(*args, **kwargs):
|
|
|
|
sidebar=ub.get_sidebar_config(kwargs)
|
|
|
|
sidebar = ub.get_sidebar_config(kwargs)
|
|
|
|
return render_template(instance=config.config_calibre_web_title, sidebar=sidebar, accept=constants.EXTENSIONS_UPLOAD,
|
|
|
|
return render_template(instance=config.config_calibre_web_title, sidebar=sidebar,
|
|
|
|
|
|
|
|
accept=constants.EXTENSIONS_UPLOAD,
|
|
|
|
*args, **kwargs)
|
|
|
|
*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -269,8 +273,10 @@ def before_request():
|
|
|
|
g.allow_upload = config.config_uploading
|
|
|
|
g.allow_upload = config.config_uploading
|
|
|
|
g.current_theme = config.config_theme
|
|
|
|
g.current_theme = config.config_theme
|
|
|
|
g.config_authors_max = config.config_authors_max
|
|
|
|
g.config_authors_max = config.config_authors_max
|
|
|
|
g.shelves_access = ub.session.query(ub.Shelf).filter(or_(ub.Shelf.is_public == 1, ub.Shelf.user_id == current_user.id)).order_by(ub.Shelf.name).all()
|
|
|
|
g.shelves_access = ub.session.query(ub.Shelf).filter(
|
|
|
|
if not config.db_configured and request.endpoint not in ('admin.basic_configuration', 'login') and '/static/' not in request.path:
|
|
|
|
or_(ub.Shelf.is_public == 1, ub.Shelf.user_id == current_user.id)).order_by(ub.Shelf.name).all()
|
|
|
|
|
|
|
|
if not config.db_configured and request.endpoint not in (
|
|
|
|
|
|
|
|
'admin.basic_configuration', 'login') and '/static/' not in request.path:
|
|
|
|
return redirect(url_for('admin.basic_configuration'))
|
|
|
|
return redirect(url_for('admin.basic_configuration'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -477,11 +483,10 @@ def get_publishers_json():
|
|
|
|
return get_typeahead(db.Publishers, request.args.get('q'), ('|', ','))
|
|
|
|
return get_typeahead(db.Publishers, request.args.get('q'), ('|', ','))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@web.route("/get_tags_json", methods=['GET'])
|
|
|
|
@web.route("/get_tags_json", methods=['GET'])
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
|
def get_tags_json():
|
|
|
|
def get_tags_json():
|
|
|
|
return get_typeahead(db.Tags, request.args.get('q'),tag_filter=tags_filters())
|
|
|
|
return get_typeahead(db.Tags, request.args.get('q'), tag_filter=tags_filters())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@web.route("/get_series_json", methods=['GET'])
|
|
|
|
@web.route("/get_series_json", methods=['GET'])
|
|
|
@ -497,9 +502,8 @@ def get_languages_json():
|
|
|
|
language_names = isoLanguages.get_language_names(get_locale())
|
|
|
|
language_names = isoLanguages.get_language_names(get_locale())
|
|
|
|
entries_start = [s for key, s in language_names.items() if s.lower().startswith(query.lower())]
|
|
|
|
entries_start = [s for key, s in language_names.items() if s.lower().startswith(query.lower())]
|
|
|
|
if len(entries_start) < 5:
|
|
|
|
if len(entries_start) < 5:
|
|
|
|
|
|
|
|
|
|
|
|
entries = [s for key, s in language_names.items() if query in s.lower()]
|
|
|
|
entries = [s for key, s in language_names.items() if query in s.lower()]
|
|
|
|
entries_start.extend(entries[0:(5-len(entries_start))])
|
|
|
|
entries_start.extend(entries[0:(5 - len(entries_start))])
|
|
|
|
entries_start = list(set(entries_start))
|
|
|
|
entries_start = list(set(entries_start))
|
|
|
|
json_dumps = json.dumps([dict(name=r) for r in entries_start[0:5]])
|
|
|
|
json_dumps = json.dumps([dict(name=r) for r in entries_start[0:5]])
|
|
|
|
return json_dumps
|
|
|
|
return json_dumps
|
|
|
@ -636,13 +640,13 @@ def render_hot_books(page):
|
|
|
|
abort(404)
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_author_books(page, author_id, order):
|
|
|
|
def render_author_books(page, author_id, order):
|
|
|
|
entries, __, pagination = fill_indexpage(page, db.Books, db.Books.authors.any(db.Authors.id == author_id),
|
|
|
|
entries, __, pagination = fill_indexpage(page, db.Books, db.Books.authors.any(db.Authors.id == author_id),
|
|
|
|
[order[0], db.Series.name, db.Books.series_index],
|
|
|
|
[order[0], db.Series.name, db.Books.series_index],
|
|
|
|
db.books_series_link, db.Series)
|
|
|
|
db.books_series_link, db.Series)
|
|
|
|
if entries is None or not len(entries):
|
|
|
|
if entries is None or not len(entries):
|
|
|
|
flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"), category="error")
|
|
|
|
flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"),
|
|
|
|
|
|
|
|
category="error")
|
|
|
|
return redirect(url_for("web.index"))
|
|
|
|
return redirect(url_for("web.index"))
|
|
|
|
|
|
|
|
|
|
|
|
author = db.session.query(db.Authors).get(author_id)
|
|
|
|
author = db.session.query(db.Authors).get(author_id)
|
|
|
@ -689,7 +693,7 @@ def render_ratings_books(page, book_id, order):
|
|
|
|
[db.Books.timestamp.desc(), order[0]])
|
|
|
|
[db.Books.timestamp.desc(), order[0]])
|
|
|
|
if name and name.rating <= 10:
|
|
|
|
if name and name.rating <= 10:
|
|
|
|
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
|
|
|
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
|
|
|
title=_(u"Rating: %(rating)s stars", rating=int(name.rating/2)), page="ratings")
|
|
|
|
title=_(u"Rating: %(rating)s stars", rating=int(name.rating / 2)), page="ratings")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
abort(404)
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
|
|
|
@ -697,7 +701,8 @@ def render_ratings_books(page, book_id, order):
|
|
|
|
def render_formats_books(page, book_id, order):
|
|
|
|
def render_formats_books(page, book_id, order):
|
|
|
|
name = db.session.query(db.Data).filter(db.Data.format == book_id.upper()).first()
|
|
|
|
name = db.session.query(db.Data).filter(db.Data.format == book_id.upper()).first()
|
|
|
|
if name:
|
|
|
|
if name:
|
|
|
|
entries, random, pagination = fill_indexpage(page, db.Books, db.Books.data.any(db.Data.format == book_id.upper()),
|
|
|
|
entries, random, pagination = fill_indexpage(page, db.Books,
|
|
|
|
|
|
|
|
db.Books.data.any(db.Data.format == book_id.upper()),
|
|
|
|
[db.Books.timestamp.desc(), order[0]])
|
|
|
|
[db.Books.timestamp.desc(), order[0]])
|
|
|
|
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
|
|
|
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
|
|
|
|
title=_(u"File format: %(format)s", format=name.format), page="formats")
|
|
|
|
title=_(u"File format: %(format)s", format=name.format), page="formats")
|
|
|
@ -736,12 +741,12 @@ def render_language_books(page, name, order):
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
|
def author_list():
|
|
|
|
def author_list():
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_AUTHOR):
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_AUTHOR):
|
|
|
|
entries = db.session.query(db.Authors, func.count('books_authors_link.book').label('count'))\
|
|
|
|
entries = db.session.query(db.Authors, func.count('books_authors_link.book').label('count')) \
|
|
|
|
.join(db.books_authors_link).join(db.Books).filter(common_filters())\
|
|
|
|
.join(db.books_authors_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(text('books_authors_link.author')).order_by(db.Authors.sort).all()
|
|
|
|
.group_by(text('books_authors_link.author')).order_by(db.Authors.sort).all()
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Authors.sort,1,1)).label('char')) \
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Authors.sort, 1, 1)).label('char')) \
|
|
|
|
.join(db.books_authors_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.join(db.books_authors_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(func.upper(func.substr(db.Authors.sort,1,1))).all()
|
|
|
|
.group_by(func.upper(func.substr(db.Authors.sort, 1, 1))).all()
|
|
|
|
for entry in entries:
|
|
|
|
for entry in entries:
|
|
|
|
entry.Authors.name = entry.Authors.name.replace('|', ',')
|
|
|
|
entry.Authors.name = entry.Authors.name.replace('|', ',')
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
@ -754,12 +759,12 @@ def author_list():
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
|
def publisher_list():
|
|
|
|
def publisher_list():
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_PUBLISHER):
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_PUBLISHER):
|
|
|
|
entries = db.session.query(db.Publishers, func.count('books_publishers_link.book').label('count'))\
|
|
|
|
entries = db.session.query(db.Publishers, func.count('books_publishers_link.book').label('count')) \
|
|
|
|
.join(db.books_publishers_link).join(db.Books).filter(common_filters())\
|
|
|
|
.join(db.books_publishers_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(text('books_publishers_link.publisher')).order_by(db.Publishers.sort).all()
|
|
|
|
.group_by(text('books_publishers_link.publisher')).order_by(db.Publishers.sort).all()
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Publishers.name,1,1)).label('char')) \
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Publishers.name, 1, 1)).label('char')) \
|
|
|
|
.join(db.books_publishers_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.join(db.books_publishers_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(func.upper(func.substr(db.Publishers.name,1,1))).all()
|
|
|
|
.group_by(func.upper(func.substr(db.Publishers.name, 1, 1))).all()
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
|
title=_(u"Publishers"), page="publisherlist", data="publisher")
|
|
|
|
title=_(u"Publishers"), page="publisherlist", data="publisher")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -770,12 +775,12 @@ def publisher_list():
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
|
def series_list():
|
|
|
|
def series_list():
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_SERIES):
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_SERIES):
|
|
|
|
entries = db.session.query(db.Series, func.count('books_series_link.book').label('count'))\
|
|
|
|
entries = db.session.query(db.Series, func.count('books_series_link.book').label('count')) \
|
|
|
|
.join(db.books_series_link).join(db.Books).filter(common_filters())\
|
|
|
|
.join(db.books_series_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(text('books_series_link.series')).order_by(db.Series.sort).all()
|
|
|
|
.group_by(text('books_series_link.series')).order_by(db.Series.sort).all()
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Series.sort,1,1)).label('char')) \
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Series.sort, 1, 1)).label('char')) \
|
|
|
|
.join(db.books_series_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.join(db.books_series_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(func.upper(func.substr(db.Series.sort,1,1))).all()
|
|
|
|
.group_by(func.upper(func.substr(db.Series.sort, 1, 1))).all()
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
|
title=_(u"Series"), page="serieslist", data="series")
|
|
|
|
title=_(u"Series"), page="serieslist", data="series")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -787,8 +792,8 @@ def series_list():
|
|
|
|
def ratings_list():
|
|
|
|
def ratings_list():
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_RATING):
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_RATING):
|
|
|
|
entries = db.session.query(db.Ratings, func.count('books_ratings_link.book').label('count'),
|
|
|
|
entries = db.session.query(db.Ratings, func.count('books_ratings_link.book').label('count'),
|
|
|
|
(db.Ratings.rating/2).label('name'))\
|
|
|
|
(db.Ratings.rating / 2).label('name')) \
|
|
|
|
.join(db.books_ratings_link).join(db.Books).filter(common_filters())\
|
|
|
|
.join(db.books_ratings_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(text('books_ratings_link.rating')).order_by(db.Ratings.rating).all()
|
|
|
|
.group_by(text('books_ratings_link.rating')).order_by(db.Ratings.rating).all()
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
|
|
|
title=_(u"Ratings list"), page="ratingslist", data="ratings")
|
|
|
|
title=_(u"Ratings list"), page="ratingslist", data="ratings")
|
|
|
@ -800,8 +805,8 @@ def ratings_list():
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
|
def formats_list():
|
|
|
|
def formats_list():
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_FORMAT):
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_FORMAT):
|
|
|
|
entries = db.session.query(db.Data, func.count('data.book').label('count'),db.Data.format.label('format'))\
|
|
|
|
entries = db.session.query(db.Data, func.count('data.book').label('count'), db.Data.format.label('format')) \
|
|
|
|
.join(db.Books).filter(common_filters())\
|
|
|
|
.join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(db.Data.format).order_by(db.Data.format).all()
|
|
|
|
.group_by(db.Data.format).order_by(db.Data.format).all()
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
|
|
|
|
title=_(u"File formats list"), page="formatslist", data="formats")
|
|
|
|
title=_(u"File formats list"), page="formatslist", data="formats")
|
|
|
@ -842,12 +847,12 @@ def language_overview():
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
|
def category_list():
|
|
|
|
def category_list():
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_CATEGORY):
|
|
|
|
if current_user.check_visibility(constants.SIDEBAR_CATEGORY):
|
|
|
|
entries = db.session.query(db.Tags, func.count('books_tags_link.book').label('count'))\
|
|
|
|
entries = db.session.query(db.Tags, func.count('books_tags_link.book').label('count')) \
|
|
|
|
.join(db.books_tags_link).join(db.Books).order_by(db.Tags.name).filter(common_filters())\
|
|
|
|
.join(db.books_tags_link).join(db.Books).order_by(db.Tags.name).filter(common_filters()) \
|
|
|
|
.group_by(text('books_tags_link.tag')).all()
|
|
|
|
.group_by(text('books_tags_link.tag')).all()
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Tags.name,1,1)).label('char')) \
|
|
|
|
charlist = db.session.query(func.upper(func.substr(db.Tags.name, 1, 1)).label('char')) \
|
|
|
|
.join(db.books_tags_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.join(db.books_tags_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(func.upper(func.substr(db.Tags.name,1,1))).all()
|
|
|
|
.group_by(func.upper(func.substr(db.Tags.name, 1, 1))).all()
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
|
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
|
|
|
|
title=_(u"Categories"), page="catlist", data="category")
|
|
|
|
title=_(u"Categories"), page="catlist", data="category")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -873,6 +878,7 @@ def reconnect():
|
|
|
|
db.reconnect_db(config)
|
|
|
|
db.reconnect_db(config)
|
|
|
|
return json.dumps({})
|
|
|
|
return json.dumps({})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@web.route("/search", methods=["GET"])
|
|
|
|
@web.route("/search", methods=["GET"])
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
|
def search():
|
|
|
|
def search():
|
|
|
@ -915,7 +921,7 @@ def advanced_search():
|
|
|
|
rating_high = request.args.get("ratinglow")
|
|
|
|
rating_high = request.args.get("ratinglow")
|
|
|
|
description = request.args.get("comment")
|
|
|
|
description = request.args.get("comment")
|
|
|
|
if author_name:
|
|
|
|
if author_name:
|
|
|
|
author_name = author_name.strip().lower().replace(',','|')
|
|
|
|
author_name = author_name.strip().lower().replace(',', '|')
|
|
|
|
if book_title:
|
|
|
|
if book_title:
|
|
|
|
book_title = book_title.strip().lower()
|
|
|
|
book_title = book_title.strip().lower()
|
|
|
|
if publisher:
|
|
|
|
if publisher:
|
|
|
@ -937,14 +943,14 @@ def advanced_search():
|
|
|
|
if pub_start:
|
|
|
|
if pub_start:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
searchterm.extend([_(u"Published after ") +
|
|
|
|
searchterm.extend([_(u"Published after ") +
|
|
|
|
format_date(datetime.datetime.strptime(pub_start,"%Y-%m-%d"),
|
|
|
|
format_date(datetime.datetime.strptime(pub_start, "%Y-%m-%d"),
|
|
|
|
format='medium', locale=get_locale())])
|
|
|
|
format='medium', locale=get_locale())])
|
|
|
|
except ValueError:
|
|
|
|
except ValueError:
|
|
|
|
pub_start = u""
|
|
|
|
pub_start = u""
|
|
|
|
if pub_end:
|
|
|
|
if pub_end:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
searchterm.extend([_(u"Published before ") +
|
|
|
|
searchterm.extend([_(u"Published before ") +
|
|
|
|
format_date(datetime.datetime.strptime(pub_end,"%Y-%m-%d"),
|
|
|
|
format_date(datetime.datetime.strptime(pub_end, "%Y-%m-%d"),
|
|
|
|
format='medium', locale=get_locale())])
|
|
|
|
format='medium', locale=get_locale())])
|
|
|
|
except ValueError:
|
|
|
|
except ValueError:
|
|
|
|
pub_start = u""
|
|
|
|
pub_start = u""
|
|
|
@ -1011,13 +1017,13 @@ def advanced_search():
|
|
|
|
custom_query = request.args.get('custom_column_' + str(c.id))
|
|
|
|
custom_query = request.args.get('custom_column_' + str(c.id))
|
|
|
|
if custom_query:
|
|
|
|
if custom_query:
|
|
|
|
if c.datatype == 'bool':
|
|
|
|
if c.datatype == 'bool':
|
|
|
|
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
|
|
|
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
|
|
|
db.cc_classes[c.id].value == (custom_query == "True")))
|
|
|
|
db.cc_classes[c.id].value == (custom_query == "True")))
|
|
|
|
elif c.datatype == 'int':
|
|
|
|
elif c.datatype == 'int':
|
|
|
|
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
|
|
|
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
|
|
|
db.cc_classes[c.id].value == custom_query))
|
|
|
|
db.cc_classes[c.id].value == custom_query))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
|
|
|
|
q = q.filter(getattr(db.Books, 'custom_column_' + str(c.id)).any(
|
|
|
|
func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
|
|
|
|
func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
|
|
|
|
q = q.all()
|
|
|
|
q = q.all()
|
|
|
|
ids = list()
|
|
|
|
ids = list()
|
|
|
@ -1027,11 +1033,11 @@ def advanced_search():
|
|
|
|
return render_title_template('search.html', searchterm=searchterm,
|
|
|
|
return render_title_template('search.html', searchterm=searchterm,
|
|
|
|
entries=q, title=_(u"search"), page="search")
|
|
|
|
entries=q, title=_(u"search"), page="search")
|
|
|
|
# prepare data for search-form
|
|
|
|
# prepare data for search-form
|
|
|
|
tags = db.session.query(db.Tags).join(db.books_tags_link).join(db.Books).filter(common_filters())\
|
|
|
|
tags = db.session.query(db.Tags).join(db.books_tags_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(text('books_tags_link.tag')).order_by(db.Tags.name).all()
|
|
|
|
.group_by(text('books_tags_link.tag')).order_by(db.Tags.name).all()
|
|
|
|
series = db.session.query(db.Series).join(db.books_series_link).join(db.Books).filter(common_filters())\
|
|
|
|
series = db.session.query(db.Series).join(db.books_series_link).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(text('books_series_link.series')).order_by(db.Series.name).filter(common_filters()).all()
|
|
|
|
.group_by(text('books_series_link.series')).order_by(db.Series.name).filter(common_filters()).all()
|
|
|
|
extensions = db.session.query(db.Data).join(db.Books).filter(common_filters())\
|
|
|
|
extensions = db.session.query(db.Data).join(db.Books).filter(common_filters()) \
|
|
|
|
.group_by(db.Data.format).order_by(db.Data.format).all()
|
|
|
|
.group_by(db.Data.format).order_by(db.Data.format).all()
|
|
|
|
|
|
|
|
|
|
|
|
if current_user.filter_language() == u"all":
|
|
|
|
if current_user.filter_language() == u"all":
|
|
|
@ -1045,12 +1051,12 @@ def advanced_search():
|
|
|
|
def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs):
|
|
|
|
def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs):
|
|
|
|
order = order or []
|
|
|
|
order = order or []
|
|
|
|
if not config.config_read_column:
|
|
|
|
if not config.config_read_column:
|
|
|
|
readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id))\
|
|
|
|
readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)) \
|
|
|
|
.filter(ub.ReadBook.is_read == True).all()
|
|
|
|
.filter(ub.ReadBook.is_read == True).all()
|
|
|
|
readBookIds = [x.book_id for x in readBooks]
|
|
|
|
readBookIds = [x.book_id for x in readBooks]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
readBooks = db.session.query(db.cc_classes[config.config_read_column])\
|
|
|
|
readBooks = db.session.query(db.cc_classes[config.config_read_column]) \
|
|
|
|
.filter(db.cc_classes[config.config_read_column].value == True).all()
|
|
|
|
.filter(db.cc_classes[config.config_read_column].value == True).all()
|
|
|
|
readBookIds = [x.book for x in readBooks]
|
|
|
|
readBookIds = [x.book for x in readBooks]
|
|
|
|
except KeyError:
|
|
|
|
except KeyError:
|
|
|
@ -1094,7 +1100,7 @@ def get_cover(book_id):
|
|
|
|
def serve_book(book_id, book_format, anyname):
|
|
|
|
def serve_book(book_id, book_format, anyname):
|
|
|
|
book_format = book_format.split(".")[0]
|
|
|
|
book_format = book_format.split(".")[0]
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
|
|
|
data = db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == book_format.upper())\
|
|
|
|
data = db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == book_format.upper()) \
|
|
|
|
.first()
|
|
|
|
.first()
|
|
|
|
log.info('Serving book: %s', data.name)
|
|
|
|
log.info('Serving book: %s', data.name)
|
|
|
|
if config.config_use_google_drive:
|
|
|
|
if config.config_use_google_drive:
|
|
|
@ -1105,6 +1111,7 @@ def serve_book(book_id, book_format, anyname):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format)
|
|
|
|
return send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@web.route("/download/<int:book_id>/<book_format>", defaults={'anyname': 'None'})
|
|
|
|
@web.route("/download/<int:book_id>/<book_format>", defaults={'anyname': 'None'})
|
|
|
|
@web.route("/download/<int:book_id>/<book_format>/<anyname>")
|
|
|
|
@web.route("/download/<int:book_id>/<book_format>/<anyname>")
|
|
|
|
@login_required_if_no_ano
|
|
|
|
@login_required_if_no_ano
|
|
|
@ -1168,7 +1175,7 @@ def register():
|
|
|
|
content.password = generate_password_hash(password)
|
|
|
|
content.password = generate_password_hash(password)
|
|
|
|
content.role = config.config_default_role
|
|
|
|
content.role = config.config_default_role
|
|
|
|
content.sidebar_view = config.config_default_show
|
|
|
|
content.sidebar_view = config.config_default_show
|
|
|
|
#content.mature_content = bool(config.config_default_show & constants.MATURE_CONTENT)
|
|
|
|
# content.mature_content = bool(config.config_default_show & constants.MATURE_CONTENT)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ub.session.add(content)
|
|
|
|
ub.session.add(content)
|
|
|
|
ub.session.commit()
|
|
|
|
ub.session.commit()
|
|
|
@ -1206,20 +1213,18 @@ def login():
|
|
|
|
flash(_(u"Cannot activate LDAP authentication"), category="error")
|
|
|
|
flash(_(u"Cannot activate LDAP authentication"), category="error")
|
|
|
|
if request.method == "POST":
|
|
|
|
if request.method == "POST":
|
|
|
|
form = request.form.to_dict()
|
|
|
|
form = request.form.to_dict()
|
|
|
|
user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower())\
|
|
|
|
user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()) \
|
|
|
|
.first()
|
|
|
|
.first()
|
|
|
|
if config.config_login_type == constants.LOGIN_LDAP and services.ldap and user and form['password'] != "":
|
|
|
|
if config.config_login_type == constants.LOGIN_LDAP and services.ldap and user and form['password'] != "":
|
|
|
|
login_result, error = services.ldap.bind_user(form['username'], form['password'])
|
|
|
|
login_result, error = services.ldap.bind_user(form['username'], form['password'])
|
|
|
|
# None if credentials are not matching
|
|
|
|
|
|
|
|
# -1 if LDAP Server error
|
|
|
|
|
|
|
|
# 0 if wrong passwort
|
|
|
|
|
|
|
|
if login_result:
|
|
|
|
if login_result:
|
|
|
|
login_user(user, remember=True)
|
|
|
|
login_user(user, remember=True)
|
|
|
|
log.debug(u"You are now logged in as: '%s'", user.nickname)
|
|
|
|
log.debug(u"You are now logged in as: '%s'", user.nickname)
|
|
|
|
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname),
|
|
|
|
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname),
|
|
|
|
category="success")
|
|
|
|
category="success")
|
|
|
|
return redirect_back(url_for("web.index"))
|
|
|
|
return redirect_back(url_for("web.index"))
|
|
|
|
elif login_result is None and user and check_password_hash(str(user.password), form['password']) and user.nickname != "Guest":
|
|
|
|
elif login_result is None and user and check_password_hash(str(user.password), form['password']) \
|
|
|
|
|
|
|
|
and user.nickname != "Guest":
|
|
|
|
login_user(user, remember=True)
|
|
|
|
login_user(user, remember=True)
|
|
|
|
log.info("Local Fallback Login as: '%s'", user.nickname)
|
|
|
|
log.info("Local Fallback Login as: '%s'", user.nickname)
|
|
|
|
flash(_(u"Fallback Login as: '%(nickname)s', LDAP Server not reachable, or user not known",
|
|
|
|
flash(_(u"Fallback Login as: '%(nickname)s', LDAP Server not reachable, or user not known",
|
|
|
@ -1258,9 +1263,18 @@ 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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if feature_support['oauth']:
|
|
|
|
|
|
|
|
oauth_status = get_oauth_status()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
oauth_status = None
|
|
|
|
next_url = url_for('web.index')
|
|
|
|
next_url = url_for('web.index')
|
|
|
|
return render_title_template('login.html', title=_(u"login"), next_url=next_url, config=config,
|
|
|
|
return render_title_template('login.html',
|
|
|
|
mail = config.get_mail_server_configured(), page="login")
|
|
|
|
title=_(u"login"),
|
|
|
|
|
|
|
|
next_url=next_url,
|
|
|
|
|
|
|
|
config=config,
|
|
|
|
|
|
|
|
# oauth_status=oauth_status,
|
|
|
|
|
|
|
|
oauth_check=oauth_check,
|
|
|
|
|
|
|
|
mail=config.get_mail_server_configured(), page="login")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@web.route('/logout')
|
|
|
|
@web.route('/logout')
|
|
|
@ -1429,7 +1443,7 @@ def profile():
|
|
|
|
if "Show_detail_random" in to_save:
|
|
|
|
if "Show_detail_random" in to_save:
|
|
|
|
current_user.sidebar_view += constants.DETAIL_RANDOM
|
|
|
|
current_user.sidebar_view += constants.DETAIL_RANDOM
|
|
|
|
|
|
|
|
|
|
|
|
#current_user.mature_content = "Show_mature_content" in to_save
|
|
|
|
# current_user.mature_content = "Show_mature_content" in to_save
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ub.session.commit()
|
|
|
|
ub.session.commit()
|
|
|
@ -1445,7 +1459,7 @@ def profile():
|
|
|
|
log.debug(u"Profile updated")
|
|
|
|
log.debug(u"Profile updated")
|
|
|
|
return render_title_template("user_edit.html", translations=translations, profile=1, languages=languages,
|
|
|
|
return render_title_template("user_edit.html", translations=translations, profile=1, languages=languages,
|
|
|
|
content=current_user, downloads=downloads, kobo_support=kobo_support,
|
|
|
|
content=current_user, downloads=downloads, kobo_support=kobo_support,
|
|
|
|
title= _(u"%(name)s's profile", name=current_user.nickname),
|
|
|
|
title=_(u"%(name)s's profile", name=current_user.nickname),
|
|
|
|
page="me", registered_oauth=oauth_check, oauth_status=oauth_status)
|
|
|
|
page="me", registered_oauth=oauth_check, oauth_status=oauth_status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1523,12 +1537,12 @@ def show_book(book_id):
|
|
|
|
|
|
|
|
|
|
|
|
if not current_user.is_anonymous:
|
|
|
|
if not current_user.is_anonymous:
|
|
|
|
if not config.config_read_column:
|
|
|
|
if not config.config_read_column:
|
|
|
|
matching_have_read_book = ub.session.query(ub.ReadBook).\
|
|
|
|
matching_have_read_book = ub.session.query(ub.ReadBook). \
|
|
|
|
filter(and_(ub.ReadBook.user_id == int(current_user.id), ub.ReadBook.book_id == book_id)).all()
|
|
|
|
filter(and_(ub.ReadBook.user_id == int(current_user.id), ub.ReadBook.book_id == book_id)).all()
|
|
|
|
have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read
|
|
|
|
have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
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:
|
|
|
|
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)
|
|
|
@ -1550,7 +1564,8 @@ def show_book(book_id):
|
|
|
|
audioentries.append(media_format.format.lower())
|
|
|
|
audioentries.append(media_format.format.lower())
|
|
|
|
|
|
|
|
|
|
|
|
return render_title_template('detail.html', entry=entries, audioentries=audioentries, cc=cc,
|
|
|
|
return render_title_template('detail.html', entry=entries, audioentries=audioentries, cc=cc,
|
|
|
|
is_xhr=request.headers.get('X-Requested-With')=='XMLHttpRequest', title=entries.title, books_shelfs=book_in_shelfs,
|
|
|
|
is_xhr=request.headers.get('X-Requested-With') == 'XMLHttpRequest',
|
|
|
|
|
|
|
|
title=entries.title, books_shelfs=book_in_shelfs,
|
|
|
|
have_read=have_read, kindle_list=kindle_list, reader_list=reader_list, page="book")
|
|
|
|
have_read=have_read, kindle_list=kindle_list, reader_list=reader_list, page="book")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
log.debug(u"Error opening eBook. File does not exist or file is not accessible:")
|
|
|
|
log.debug(u"Error opening eBook. File does not exist or file is not accessible:")
|
|
|
|