2020-12-12 10:23:17 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
|
|
|
# Copyright (C) 2018-2020 OzzieIsaacs
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-04-26 09:28:20 +00:00
|
|
|
from flask import render_template, g, abort, request
|
2020-12-12 10:23:17 +00:00
|
|
|
from flask_babel import gettext as _
|
|
|
|
from werkzeug.local import LocalProxy
|
2024-07-14 14:24:07 +00:00
|
|
|
from .cw_login import current_user
|
2023-02-04 13:51:41 +00:00
|
|
|
from sqlalchemy.sql.expression import or_
|
2020-12-12 10:23:17 +00:00
|
|
|
|
2023-02-04 13:51:41 +00:00
|
|
|
from . import config, constants, logger, ub
|
2020-12-12 10:23:17 +00:00
|
|
|
from .ub import User
|
|
|
|
|
|
|
|
|
2020-12-27 12:34:59 +00:00
|
|
|
log = logger.create()
|
|
|
|
|
2020-12-12 11:03:11 +00:00
|
|
|
def get_sidebar_config(kwargs=None):
|
2020-12-12 10:23:17 +00:00
|
|
|
kwargs = kwargs or []
|
2022-04-02 09:37:02 +00:00
|
|
|
simple = bool([e for e in ['kindle', 'tolino', "kobo", "bookeen"]
|
|
|
|
if (e in request.headers.get('User-Agent', "").lower())])
|
2020-12-12 10:23:17 +00:00
|
|
|
if 'content' in kwargs:
|
|
|
|
content = kwargs['content']
|
|
|
|
content = isinstance(content, (User, LocalProxy)) and not content.role_anonymous()
|
|
|
|
else:
|
|
|
|
content = 'conf' in kwargs
|
|
|
|
sidebar = list()
|
2021-01-31 18:20:43 +00:00
|
|
|
sidebar.append({"glyph": "glyphicon-book", "text": _('Books'), "link": 'web.index', "id": "new",
|
2020-12-12 10:23:17 +00:00
|
|
|
"visibility": constants.SIDEBAR_RECENT, 'public': True, "page": "root",
|
|
|
|
"show_text": _('Show recent books'), "config_show":False})
|
|
|
|
sidebar.append({"glyph": "glyphicon-fire", "text": _('Hot Books'), "link": 'web.books_list', "id": "hot",
|
|
|
|
"visibility": constants.SIDEBAR_HOT, 'public': True, "page": "hot",
|
|
|
|
"show_text": _('Show Hot Books'), "config_show": True})
|
2021-03-21 18:31:32 +00:00
|
|
|
if current_user.role_admin():
|
|
|
|
sidebar.append({"glyph": "glyphicon-download", "text": _('Downloaded Books'), "link": 'web.download_list',
|
2023-02-04 10:18:43 +00:00
|
|
|
"id": "download", "visibility": constants.SIDEBAR_DOWNLOAD, 'public': (not current_user.is_anonymous),
|
2021-03-21 18:31:32 +00:00
|
|
|
"page": "download", "show_text": _('Show Downloaded Books'),
|
|
|
|
"config_show": content})
|
|
|
|
else:
|
|
|
|
sidebar.append({"glyph": "glyphicon-download", "text": _('Downloaded Books'), "link": 'web.books_list',
|
2023-02-04 10:18:43 +00:00
|
|
|
"id": "download", "visibility": constants.SIDEBAR_DOWNLOAD, 'public': (not current_user.is_anonymous),
|
2021-03-21 18:31:32 +00:00
|
|
|
"page": "download", "show_text": _('Show Downloaded Books'),
|
|
|
|
"config_show": content})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append(
|
|
|
|
{"glyph": "glyphicon-star", "text": _('Top Rated Books'), "link": 'web.books_list', "id": "rated",
|
|
|
|
"visibility": constants.SIDEBAR_BEST_RATED, 'public': True, "page": "rated",
|
|
|
|
"show_text": _('Show Top Rated Books'), "config_show": True})
|
|
|
|
sidebar.append({"glyph": "glyphicon-eye-open", "text": _('Read Books'), "link": 'web.books_list', "id": "read",
|
2023-02-04 10:18:43 +00:00
|
|
|
"visibility": constants.SIDEBAR_READ_AND_UNREAD, 'public': (not current_user.is_anonymous),
|
2023-01-04 02:30:13 +00:00
|
|
|
"page": "read", "show_text": _('Show Read and Unread'), "config_show": content})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append(
|
|
|
|
{"glyph": "glyphicon-eye-close", "text": _('Unread Books'), "link": 'web.books_list', "id": "unread",
|
2023-02-04 10:18:43 +00:00
|
|
|
"visibility": constants.SIDEBAR_READ_AND_UNREAD, 'public': (not current_user.is_anonymous), "page": "unread",
|
2020-12-12 10:23:17 +00:00
|
|
|
"show_text": _('Show unread'), "config_show": False})
|
|
|
|
sidebar.append({"glyph": "glyphicon-random", "text": _('Discover'), "link": 'web.books_list', "id": "rand",
|
|
|
|
"visibility": constants.SIDEBAR_RANDOM, 'public': True, "page": "discover",
|
2021-05-16 07:37:45 +00:00
|
|
|
"show_text": _('Show Random Books'), "config_show": True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append({"glyph": "glyphicon-inbox", "text": _('Categories'), "link": 'web.category_list', "id": "cat",
|
|
|
|
"visibility": constants.SIDEBAR_CATEGORY, 'public': True, "page": "category",
|
2023-01-04 02:30:13 +00:00
|
|
|
"show_text": _('Show Category Section'), "config_show": True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append({"glyph": "glyphicon-bookmark", "text": _('Series'), "link": 'web.series_list', "id": "serie",
|
|
|
|
"visibility": constants.SIDEBAR_SERIES, 'public': True, "page": "series",
|
2023-01-04 02:30:13 +00:00
|
|
|
"show_text": _('Show Series Section'), "config_show": True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append({"glyph": "glyphicon-user", "text": _('Authors'), "link": 'web.author_list', "id": "author",
|
|
|
|
"visibility": constants.SIDEBAR_AUTHOR, 'public': True, "page": "author",
|
2023-01-04 02:30:13 +00:00
|
|
|
"show_text": _('Show Author Section'), "config_show": True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append(
|
|
|
|
{"glyph": "glyphicon-text-size", "text": _('Publishers'), "link": 'web.publisher_list', "id": "publisher",
|
|
|
|
"visibility": constants.SIDEBAR_PUBLISHER, 'public': True, "page": "publisher",
|
2023-01-04 02:30:13 +00:00
|
|
|
"show_text": _('Show Publisher Section'), "config_show":True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append({"glyph": "glyphicon-flag", "text": _('Languages'), "link": 'web.language_overview', "id": "lang",
|
2023-02-04 10:18:43 +00:00
|
|
|
"visibility": constants.SIDEBAR_LANGUAGE, 'public': (current_user.filter_language() == 'all'),
|
2020-12-12 10:23:17 +00:00
|
|
|
"page": "language",
|
2023-01-04 02:30:13 +00:00
|
|
|
"show_text": _('Show Language Section'), "config_show": True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append({"glyph": "glyphicon-star-empty", "text": _('Ratings'), "link": 'web.ratings_list', "id": "rate",
|
|
|
|
"visibility": constants.SIDEBAR_RATING, 'public': True,
|
2023-01-04 02:30:13 +00:00
|
|
|
"page": "rating", "show_text": _('Show Ratings Section'), "config_show": True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append({"glyph": "glyphicon-file", "text": _('File formats'), "link": 'web.formats_list', "id": "format",
|
|
|
|
"visibility": constants.SIDEBAR_FORMAT, 'public': True,
|
2023-01-04 02:30:13 +00:00
|
|
|
"page": "format", "show_text": _('Show File Formats Section'), "config_show": True})
|
2020-12-12 10:23:17 +00:00
|
|
|
sidebar.append(
|
|
|
|
{"glyph": "glyphicon-trash", "text": _('Archived Books'), "link": 'web.books_list', "id": "archived",
|
2023-02-04 10:18:43 +00:00
|
|
|
"visibility": constants.SIDEBAR_ARCHIVED, 'public': (not current_user.is_anonymous), "page": "archived",
|
2023-01-04 02:30:13 +00:00
|
|
|
"show_text": _('Show Archived Books'), "config_show": content})
|
2022-03-25 17:30:12 +00:00
|
|
|
if not simple:
|
|
|
|
sidebar.append(
|
|
|
|
{"glyph": "glyphicon-th-list", "text": _('Books List'), "link": 'web.books_table', "id": "list",
|
2023-02-04 10:18:43 +00:00
|
|
|
"visibility": constants.SIDEBAR_LIST, 'public': (not current_user.is_anonymous), "page": "list",
|
2022-03-25 17:30:12 +00:00
|
|
|
"show_text": _('Show Books List'), "config_show": content})
|
2023-02-04 13:51:41 +00:00
|
|
|
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()
|
|
|
|
|
2022-03-25 17:30:12 +00:00
|
|
|
return sidebar, simple
|
2020-12-12 10:23:17 +00:00
|
|
|
|
2020-12-27 12:34:59 +00:00
|
|
|
|
2020-12-12 10:23:17 +00:00
|
|
|
# Returns the template for rendering and includes the instance name
|
|
|
|
def render_title_template(*args, **kwargs):
|
2022-03-25 17:30:12 +00:00
|
|
|
sidebar, simple = get_sidebar_config(kwargs)
|
2022-04-03 18:26:43 +00:00
|
|
|
try:
|
|
|
|
return render_template(instance=config.config_calibre_web_title, sidebar=sidebar, simple=simple,
|
2024-06-23 10:00:12 +00:00
|
|
|
accept=config.config_upload_formats.split(','),
|
2022-04-03 18:26:43 +00:00
|
|
|
*args, **kwargs)
|
|
|
|
except PermissionError:
|
|
|
|
log.error("No permission to access {} file.".format(args[0]))
|
|
|
|
abort(403)
|