Książka ma {0} stron(y).
" + TRANSLATOR_TEMPLATE = "Tłumacz: {0}
" PUBLISH_DATE_TEMPLATE = "Data pierwszego wydania: {0}
" PUBLISH_DATE_PL_TEMPLATE = ( "Data pierwszego wydania w Polsce: {0}
" @@ -282,11 +285,13 @@ class LubimyCzytacParser: def _parse_tags(self) -> List[str]: tags = self._parse_xpath_node(xpath=LubimyCzytac.TAGS, take_first=False) - return [ - strip_accents(w.replace(", itd.", " itd.")) - for w in tags - if isinstance(w, str) - ] + if tags: + return [ + strip_accents(w.replace(", itd.", " itd.")) + for w in tags + if isinstance(w, str) + ] + return None def _parse_from_summary(self, attribute_name: str) -> Optional[str]: value = None @@ -346,5 +351,9 @@ class LubimyCzytacParser: description += LubimyCzytacParser.PUBLISH_DATE_PL_TEMPLATE.format( first_publish_date_pl.strftime("%d.%m.%Y") ) + translator = self._parse_xpath_node(xpath=LubimyCzytac.TRANSLATOR) + if translator: + description += LubimyCzytacParser.TRANSLATOR_TEMPLATE.format(translator) + return description diff --git a/cps/oauth_bb.py b/cps/oauth_bb.py index ec400f71..76b8d2ba 100644 --- a/cps/oauth_bb.py +++ b/cps/oauth_bb.py @@ -135,7 +135,7 @@ def bind_oauth_or_register(provider_id, provider_user_id, redirect_url, provider if oauth_entry.user: login_user(oauth_entry.user) log.debug("You are now logged in as: '%s'", oauth_entry.user.name) - flash(_("Success! You are now logged in as: %(nickname)s", nickname= oauth_entry.user.name), + flash(_("Success! You are now logged in as: %(nickname)s", nickname=oauth_entry.user.name), category="success") return redirect(url_for('web.index')) else: @@ -205,6 +205,7 @@ def unlink_oauth(provider): flash(_("Not Linked to %(oauth)s", oauth=provider), category="error") return redirect(url_for('web.profile')) + def generate_oauth_blueprints(): if not ub.session.query(ub.OAuthProvider).count(): for provider in ("github", "google"): @@ -291,6 +292,7 @@ if ub.oauth_support: return oauth_update_token(str(oauthblueprints[1]['id']), token, google_user_id) + # notify on OAuth provider error @oauth_error.connect_via(oauthblueprints[0]['blueprint']) def github_error(blueprint, error, error_description=None, error_uri=None): diff --git a/cps/opds.py b/cps/opds.py index b13b0570..b61de5a9 100644 --- a/cps/opds.py +++ b/cps/opds.py @@ -24,14 +24,14 @@ import datetime import json from urllib.parse import unquote_plus -from flask import Blueprint, request, render_template, make_response, abort, Response +from flask import Blueprint, request, render_template, make_response, abort, Response, g from flask_login import current_user from flask_babel import get_locale from flask_babel import gettext as _ from sqlalchemy.sql.expression import func, text, or_, and_, true from sqlalchemy.exc import InvalidRequestError, OperationalError -from . import logger, config, db, calibre_db, ub, isoLanguages +from . import logger, config, db, calibre_db, ub, isoLanguages, constants from .usermanagement import requires_basic_auth_if_no_ano from .helper import get_download_link, get_book_cover from .pagination import Pagination @@ -94,6 +94,8 @@ def feed_letter_books(book_id): @opds.route("/opds/new") @requires_basic_auth_if_no_ano def feed_new(): + if not current_user.check_visibility(constants.SIDEBAR_RECENT): + abort(404) off = request.args.get("offset") or 0 entries, __, pagination = calibre_db.fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1), 0, db.Books, True, [db.Books.timestamp.desc()], @@ -104,6 +106,8 @@ def feed_new(): @opds.route("/opds/discover") @requires_basic_auth_if_no_ano def feed_discover(): + if not current_user.check_visibility(constants.SIDEBAR_RANDOM): + abort(404) query = calibre_db.generate_linked_query(config.config_read_column, db.Books) entries = query.filter(calibre_db.common_filters()).order_by(func.random()).limit(config.config_books_per_page) pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page)) @@ -113,6 +117,8 @@ def feed_discover(): @opds.route("/opds/rated") @requires_basic_auth_if_no_ano def feed_best_rated(): + if not current_user.check_visibility(constants.SIDEBAR_BEST_RATED): + abort(404) off = request.args.get("offset") or 0 entries, __, pagination = calibre_db.fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1), 0, db.Books, db.Books.ratings.any(db.Ratings.rating > 9), @@ -124,6 +130,8 @@ def feed_best_rated(): @opds.route("/opds/hot") @requires_basic_auth_if_no_ano def feed_hot(): + if not current_user.check_visibility(constants.SIDEBAR_HOT): + abort(404) off = request.args.get("offset") or 0 all_books = ub.session.query(ub.Downloads, func.count(ub.Downloads.book_id)).order_by( func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id) @@ -146,12 +154,16 @@ def feed_hot(): @opds.route("/opds/author") @requires_basic_auth_if_no_ano def feed_authorindex(): + if not current_user.check_visibility(constants.SIDEBAR_AUTHOR): + abort(404) return render_element_index(db.Authors.sort, db.books_authors_link, 'opds.feed_letter_author') @opds.route("/opds/author/letter/