From 5129bc36018f85a26f68302aec01e8372251114f Mon Sep 17 00:00:00 2001 From: Virgil Grigoras Date: Sun, 30 Sep 2018 18:30:24 +0200 Subject: [PATCH] Add entry for publishers to the left menu (+ setting for showing / hiding) + separate publisher page --- cps/templates/config_view_edit.html | 4 ++++ cps/templates/detail.html | 15 +++++++++++---- cps/templates/layout.html | 3 +++ cps/templates/user_edit.html | 4 ++++ cps/ub.py | 8 ++++++++ cps/web.py | 29 +++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 4 deletions(-) diff --git a/cps/templates/config_view_edit.html b/cps/templates/config_view_edit.html index 5cbf8e65..88c4a4bc 100644 --- a/cps/templates/config_view_edit.html +++ b/cps/templates/config_view_edit.html @@ -143,6 +143,10 @@ +
+ + +
diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 420b98a6..57475736 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -120,13 +120,20 @@
{% endif %} + {% if entry.publishers|length > 0 %}
-

- {{_('Publisher')}}:{% for publisher in entry.publishers %} {{publisher.name}}{% if not loop.last %},{% endif %}{% endfor %} -

+

+ {{_('Publisher')}}: + {% for publisher in entry.publishers %} + {{publisher.name}} + {% if not loop.last %},{% endif %} + {% endfor %} + +

- {% endif %} + {% endif %} + {% if entry.pubdate[:10] != '0101-01-01' %}

{{_('Publishing date')}}: {{entry.pubdate|formatdate}}

{% endif %} diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 8ccce35c..d0f6469f 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -159,6 +159,9 @@ {% if g.user.show_author() %} {%endif%} + {% if g.user.show_publisher() %} + + {%endif%} {% if g.user.filter_language() == 'all' and g.user.show_language() %} {%endif%} diff --git a/cps/templates/user_edit.html b/cps/templates/user_edit.html index ecf8042e..48630cea 100644 --- a/cps/templates/user_edit.html +++ b/cps/templates/user_edit.html @@ -89,6 +89,10 @@ +
+ + +
diff --git a/cps/ub.py b/cps/ub.py index f1b19d02..2a41663e 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -41,6 +41,7 @@ SIDEBAR_READ_AND_UNREAD = 256 SIDEBAR_RECENT = 512 SIDEBAR_SORTED = 1024 MATURE_CONTENT = 2048 +SIDEBAR_PUBLISHER = 4096 DEFAULT_PASS = "admin123" DEFAULT_PORT = int(os.environ.get("CALIBRE_PORT", 8083)) @@ -136,6 +137,9 @@ class UserBase: def show_author(self): return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_AUTHOR == SIDEBAR_AUTHOR)) + def show_publisher(self): + return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_PUBLISHER == SIDEBAR_PUBLISHER)) + def show_best_rated_books(self): return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_BEST_RATED == SIDEBAR_BEST_RATED)) @@ -485,6 +489,10 @@ class Config: return bool((self.config_default_show is not None) and (self.config_default_show & SIDEBAR_AUTHOR == SIDEBAR_AUTHOR)) + def show_publisher(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_PUBLISHER == SIDEBAR_PUBLISHER)) + def show_best_rated_books(self): return bool((self.config_default_show is not None) and (self.config_default_show & SIDEBAR_BEST_RATED == SIDEBAR_BEST_RATED)) diff --git a/cps/web.py b/cps/web.py index b4132111..0f359fd6 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1415,6 +1415,31 @@ def author(book_id, page): title=name, author=author_info, other_books=other_books, page="author") +@app.route("/publisher") +@login_required_if_no_ano +def publisher_list(): + if current_user.show_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() + return render_title_template('list.html', entries=entries, folder='publisher', + title=_(u"Publisher list"), page="publisherlist") + else: + abort(404) + + +@app.route("/publisher/", defaults={'page': 1}) +@app.route('/publisher//') +@login_required_if_no_ano +def publisher(book_id, page): + entries, random, pagination = fill_indexpage(page, db.Books, db.Books.publishers.any(db.Publishers.id == book_id), + (db.Series.name, db.Books.series_index), db.books_series_link, db.Series) + + name = db.session.query(db.Publishers).filter(db.Publishers.id == book_id).first().name + return render_title_template('index.html', random=random, entries=entries, pagination=pagination, + title=_(u"Publisher: %(name)s", name=name), page="publisher") + + def get_unique_other_books(library_books, author_books): # Get all identifiers (ISBN, Goodreads, etc) and filter author's books by that list so we show fewer duplicates # Note: Not all images will be shown, even though they're available on Goodreads.com. @@ -2774,6 +2799,8 @@ def profile(): content.sidebar_view += ub.SIDEBAR_BEST_RATED if "show_author" in to_save: content.sidebar_view += ub.SIDEBAR_AUTHOR + if "show_publisher" in to_save: + content.sidebar_view += ub.SIDEBAR_PUBLISHER if "show_read_and_unread" in to_save: content.sidebar_view += ub.SIDEBAR_READ_AND_UNREAD if "show_detail_random" in to_save: @@ -2884,6 +2911,8 @@ def view_configuration(): content.config_default_show = content.config_default_show + ub.SIDEBAR_RANDOM if "show_author" in to_save: content.config_default_show = content.config_default_show + ub.SIDEBAR_AUTHOR + if "show_publisher" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_PUBLISHER if "show_best_rated" in to_save: content.config_default_show = content.config_default_show + ub.SIDEBAR_BEST_RATED if "show_read_and_unread" in to_save: