From 9144a7ceb9549bae9c48e10eca0b61a51e4d1fd8 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Fri, 8 Mar 2019 16:29:12 +0100 Subject: [PATCH] Fix for sqlalchemy 1.3 --- cps/admin.py | 18 ++++---- cps/opds.py | 11 +++-- cps/templates/config_edit.html | 84 +++++++++++++++++----------------- cps/templates/index.html | 13 +++++- cps/templates/list.html | 3 +- cps/ub.py | 6 ++- cps/web.py | 67 +++++++++++++++++---------- 7 files changed, 120 insertions(+), 82 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index ad2db459..41273642 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -325,7 +325,7 @@ def configuration_helper(origin): 'credential': os.path.join(config.get_main_dir, 'gdrive_credentials')}) else: flash(_(u'client_secrets.json is not configured for web application'), category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, gdriveError=gdriveError, gfeature_support=feature_support, title=_(u"Basic Configuration"), page="config") @@ -351,7 +351,7 @@ def configuration_helper(origin): else: ub.session.commit() flash(_(u'Keyfile location is not valid, please enter correct path'), category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, gdriveError=gdriveError, feature_support=feature_support, title=_(u"Basic Configuration"), page="config") @@ -363,7 +363,7 @@ def configuration_helper(origin): else: ub.session.commit() flash(_(u'Certfile location is not valid, please enter correct path'), category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, gdriveError=gdriveError, feature_support=feature_support, title=_(u"Basic Configuration"), page="config") content.config_uploading = 0 @@ -388,7 +388,7 @@ def configuration_helper(origin): if "config_ldap_provider_url" not in to_save or "config_ldap_dn" not in to_save: ub.session.commit() flash(_(u'Please enter a LDAP provider and a DN'), category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, gdriveError=gdriveError, feature_support=feature_support, title=_(u"Basic Configuration"), page="config") else: @@ -446,7 +446,7 @@ def configuration_helper(origin): else: ub.session.commit() flash(_(u'Logfile location is not valid, please enter correct path'), category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, gdriveError=gdriveError, feature_support=feature_support, title=_(u"Basic Configuration"), page="config") else: @@ -460,7 +460,7 @@ def configuration_helper(origin): content.config_rarfile_location = to_save["config_rarfile_location"].strip() else: flash(check[1], category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, feature_support=feature_support, title=_(u"Basic Configuration")) try: if content.config_use_google_drive and is_gdrive_ready() and not \ @@ -477,14 +477,14 @@ def configuration_helper(origin): # logging.getLogger("uploader").setLevel(config.config_log_level) except Exception as e: flash(e, category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, gdriveError=gdriveError, feature_support=feature_support, title=_(u"Basic Configuration"), page="config") if db_change: reload(db) if not db.setup_db(): flash(_(u'DB location is not valid, please enter correct path'), category="error") - return render_title_template("config_edit.html", content=config, origin=origin, + return render_title_template("config_edit.html", config=config, origin=origin, gdriveError=gdriveError, feature_support=feature_support, title=_(u"Basic Configuration"), page="config") if reboot_required: @@ -498,7 +498,7 @@ def configuration_helper(origin): gdrivefolders = listRootFolders() else: gdrivefolders = list() - return render_title_template("config_edit.html", origin=origin, success=success, content=config, + return render_title_template("config_edit.html", origin=origin, success=success, config=config, show_authenticate_google_drive=not is_gdrive_ready(), gdriveError=gdriveError, gdrivefolders=gdrivefolders, feature_support=feature_support, title=_(u"Basic Configuration"), page="config") diff --git a/cps/opds.py b/cps/opds.py index 8f718a0d..73cd790d 100644 --- a/cps/opds.py +++ b/cps/opds.py @@ -31,12 +31,13 @@ import ub from flask_login import current_user from functools import wraps from web import login_required_if_no_ano, fill_indexpage, common_filters, get_search_results, render_read_books -from sqlalchemy.sql.expression import func +from sqlalchemy.sql.expression import func, text import helper from werkzeug.security import check_password_hash from werkzeug.datastructures import Headers from web import download_required import sys + try: from urllib.parse import quote except ImportError: @@ -138,7 +139,7 @@ def feed_hot(): def feed_authorindex(): off = request.args.get("offset") or 0 entries = db.session.query(db.Authors).join(db.books_authors_link).join(db.Books).filter(common_filters())\ - .group_by('books_authors_link.author').order_by(db.Authors.sort).limit(config.config_books_per_page).offset(off) + .group_by(text('books_authors_link.author')).order_by(db.Authors.sort).limit(config.config_books_per_page).offset(off) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Authors).all())) return render_xml_template('feed.xml', listelements=entries, folder='opds.feed_author', pagination=pagination) @@ -158,7 +159,7 @@ def feed_author(book_id): def feed_publisherindex(): off = request.args.get("offset") or 0 entries = db.session.query(db.Publishers).join(db.books_publishers_link).join(db.Books).filter(common_filters())\ - .group_by('books_publishers_link.publisher').order_by(db.Publishers.sort).limit(config.config_books_per_page).offset(off) + .group_by(text('books_publishers_link.publisher')).order_by(db.Publishers.sort).limit(config.config_books_per_page).offset(off) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Publishers).all())) return render_xml_template('feed.xml', listelements=entries, folder='opds.feed_publisher', pagination=pagination) @@ -179,7 +180,7 @@ def feed_publisher(book_id): def feed_categoryindex(): off = request.args.get("offset") or 0 entries = db.session.query(db.Tags).join(db.books_tags_link).join(db.Books).filter(common_filters())\ - .group_by('books_tags_link.tag').order_by(db.Tags.name).offset(off).limit(config.config_books_per_page) + .group_by(text('books_tags_link.tag')).order_by(db.Tags.name).offset(off).limit(config.config_books_per_page) pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Tags).all())) return render_xml_template('feed.xml', listelements=entries, folder='opds.feed_category', pagination=pagination) @@ -199,7 +200,7 @@ def feed_category(book_id): def feed_seriesindex(): off = request.args.get("offset") or 0 entries = db.session.query(db.Series).join(db.books_series_link).join(db.Books).filter(common_filters())\ - .group_by('books_series_link.series').order_by(db.Series.sort).offset(off).all() + .group_by(text('books_series_link.series')).order_by(db.Series.sort).offset(off).all() pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, len(db.session.query(db.Series).all())) return render_xml_template('feed.xml', listelements=entries, folder='opds.feed_series', pagination=pagination) diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 19303cbe..8414032f 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -17,10 +17,10 @@
- +
- +
@@ -31,12 +31,12 @@
{% else %} - {% if show_authenticate_google_drive and g.user.is_authenticated and content.config_use_google_drive %} + {% if show_authenticate_google_drive and g.user.is_authenticated and config.config_use_google_drive %} {% else %} - {% if show_authenticate_google_drive and g.user.is_authenticated and not content.config_use_google_drive %} + {% if show_authenticate_google_drive and g.user.is_authenticated and not config.config_use_google_drive %}
{{_('Please hit submit to continue with setup')}}
{% endif %} {% if not g.user.is_authenticated %} @@ -48,14 +48,14 @@
- {% if content.config_google_drive_watch_changes_response %} + {% if config.config_google_drive_watch_changes_response %}
- + {{_('Revoke')}}
{% else %} @@ -83,23 +83,23 @@
- +
- +
- +
@@ -119,15 +119,15 @@
- +
@@ -144,35 +144,35 @@
- +
- +
- +
- +
{% if feature_support['goodreads'] %}
- + {{_('Obtain an API Key')}}
- +
- +
{% endif %} @@ -180,13 +180,13 @@
@@ -194,11 +194,11 @@
- +
- +
{% endif %} @@ -209,11 +209,11 @@
- +
- +
@@ -222,11 +222,11 @@
- +
- +
{% endif %} @@ -246,27 +246,27 @@
-
+
-
+
-
+
- +
- +
{% if rarfile_support %}
- +
{% endif %}
diff --git a/cps/templates/index.html b/cps/templates/index.html index bdfc2fc6..fc2f3e95 100755 --- a/cps/templates/index.html +++ b/cps/templates/index.html @@ -4,7 +4,6 @@

{{_('Discover (Random Books)')}}

- {% for entry in random %}
@@ -48,6 +47,18 @@ {% endif %}

{{_(title)}}

+
{% if entries[0] %} {% for entry in entries %} diff --git a/cps/templates/list.html b/cps/templates/list.html index 9002ee20..32b463fa 100644 --- a/cps/templates/list.html +++ b/cps/templates/list.html @@ -1,7 +1,7 @@ {% extends "layout.html" %} {% block body %}

{{_(title)}}

-
+
+
{% for entry in entries %}
diff --git a/cps/ub.py b/cps/ub.py index 96e38674..099c05c6 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -70,6 +70,7 @@ SIDEBAR_RECENT = 512 SIDEBAR_SORTED = 1024 MATURE_CONTENT = 2048 SIDEBAR_PUBLISHER = 4096 +SIDEBAR_RATING = 8192 UPDATE_STABLE = 0 AUTO_UPDATE_STABLE = 1 @@ -139,6 +140,9 @@ def get_sidebar_config(kwargs=[]): "visibility": SIDEBAR_LANGUAGE, 'public': (g.user.filter_language() == 'all'), "page": "language", "show_text": _('Show language selection'), "config_show":True}) + sidebar.append({"glyph": "glyphicon-star-empty", "text": _('Ratings'), "link": 'web.ratings_list', "id": "rate", + "visibility": SIDEBAR_RATING, 'public': True, + "page": "rating", "show_text": _('Show ratings selection'), "config_show":True}) return sidebar @@ -835,7 +839,7 @@ def create_admin_user(): user.role = ROLE_USER + ROLE_ADMIN + ROLE_DOWNLOAD + ROLE_UPLOAD + ROLE_EDIT + ROLE_DELETE_BOOKS + ROLE_PASSWD user.sidebar_view = DETAIL_RANDOM + SIDEBAR_LANGUAGE + SIDEBAR_SERIES + SIDEBAR_CATEGORY + SIDEBAR_HOT + \ SIDEBAR_RANDOM + SIDEBAR_AUTHOR + SIDEBAR_BEST_RATED + SIDEBAR_READ_AND_UNREAD + SIDEBAR_RECENT + \ - SIDEBAR_SORTED + SIDEBAR_PUBLISHER + SIDEBAR_SORTED + + MATURE_CONTENT + SIDEBAR_PUBLISHER + SIDEBAR_RATING user.password = generate_password_hash(DEFAULT_PASS) diff --git a/cps/web.py b/cps/web.py index c5bd7600..2f56d4e7 100644 --- a/cps/web.py +++ b/cps/web.py @@ -501,36 +501,27 @@ def index(page): @web.route('/books/newest/page/') @login_required_if_no_ano def newest_books(page): - if current_user.show_sorted(): - entries, random, pagination = fill_indexpage(page, db.Books, True, [db.Books.pubdate.desc()]) - return render_title_template('index.html', random=random, entries=entries, pagination=pagination, - title=_(u"Newest Books"), page="newest") - else: - abort(404) + entries, random, pagination = fill_indexpage(page, db.Books, True, [db.Books.pubdate.desc()]) + return render_title_template('index.html', random=random, entries=entries, pagination=pagination, + title=_(u"Newest Books"), page="newest") @web.route('/books/oldest', defaults={'page': 1}) @web.route('/books/oldest/page/') @login_required_if_no_ano def oldest_books(page): - if current_user.show_sorted(): - entries, random, pagination = fill_indexpage(page, db.Books, True, [db.Books.pubdate]) - return render_title_template('index.html', random=random, entries=entries, pagination=pagination, - title=_(u"Oldest Books"), page="oldest") - else: - abort(404) + entries, random, pagination = fill_indexpage(page, db.Books, True, [db.Books.pubdate]) + return render_title_template('index.html', random=random, entries=entries, pagination=pagination, + title=_(u"Oldest Books"), page="oldest") @web.route('/books/a-z', defaults={'page': 1}) @web.route('/books/a-z/page/') @login_required_if_no_ano def titles_ascending(page): - if current_user.show_sorted(): - entries, random, pagination = fill_indexpage(page, db.Books, True, [db.Books.sort]) - return render_title_template('index.html', random=random, entries=entries, pagination=pagination, - title=_(u"Books (A-Z)"), page="a-z") - else: - abort(404) + entries, random, pagination = fill_indexpage(page, db.Books, True, [db.Books.sort]) + return render_title_template('index.html', random=random, entries=entries, pagination=pagination, + title=_(u"Books (A-Z)"), page="a-z") @web.route('/books/z-a', defaults={'page': 1}) @@ -605,7 +596,7 @@ def author_list(): if current_user.check_visibility(ub.SIDEBAR_AUTHOR): 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())\ - .group_by('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')) \ .join(db.books_authors_link).join(db.Books).filter(common_filters()) \ .group_by(func.upper(func.substr(db.Authors.sort,1,1))).all() @@ -650,7 +641,7 @@ def publisher_list(): if current_user.check_visibility(ub.SIDEBAR_PUBLISHER): 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())\ - .group_by('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')) \ .join(db.books_publishers_link).join(db.Books).filter(common_filters()) \ .group_by(func.upper(func.substr(db.Publishers.name,1,1))).all() @@ -704,7 +695,7 @@ def series_list(): if current_user.check_visibility(ub.SIDEBAR_SERIES): 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())\ - .group_by('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')) \ .join(db.books_series_link).join(db.Books).filter(common_filters()) \ .group_by(func.upper(func.substr(db.Series.sort,1,1))).all() @@ -728,6 +719,36 @@ def series(book_id, page): abort(404) +@web.route("/ratings") +@login_required_if_no_ano +def ratings_list(): + if current_user.check_visibility(ub.SIDEBAR_RATING): + 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())\ + .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')) \ + .join(db.books_series_link).join(db.Books).filter(common_filters()) \ + .group_by(func.upper(func.substr(db.Series.sort,1,1))).all() + return render_title_template('list.html', entries=entries, folder='web.series', charlist=charlist, + title=_(u"Ratings list"), page="ratingslist") + else: + abort(404) + + +@web.route("/ratings//", defaults={'page': 1}) +@web.route("/ratings//") +@login_required_if_no_ano +def ratings(book_id, page): + name = db.session.query(db.Series).filter(db.Series.id == book_id).first() + if name: + entries, random, pagination = fill_indexpage(page, db.Books, db.Books.series.any(db.Series.id == book_id), + [db.Books.series_index]) + return render_title_template('index.html', random=random, pagination=pagination, entries=entries, + title=_(u"Ratings: %(serie)s", serie=name.name), page="ratings") + else: + abort(404) + + @web.route("/language") @login_required_if_no_ano def language_overview(): @@ -749,7 +770,7 @@ def language_overview(): languages[0].name = _(isoLanguages.get(part3=languages[0].lang_code).name) lang_counter = db.session.query(db.books_languages_link, func.count('books_languages_link.book').label('bookcount')).group_by( - 'books_languages_link.lang_code').all() + text('books_languages_link.lang_code')).all() return render_title_template('languages.html', languages=languages, lang_counter=lang_counter, charlist=charlist, title=_(u"Available languages"), page="langlist") else: @@ -780,7 +801,7 @@ def category_list(): if current_user.check_visibility(ub.SIDEBAR_CATEGORY): 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())\ - .group_by('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')) \ .join(db.books_tags_link).join(db.Books).filter(common_filters()) \ .group_by(func.upper(func.substr(db.Tags.name,1,1))).all()