From e0229c917cf627a1f3bacb35e7f8bc4d89c49833 Mon Sep 17 00:00:00 2001 From: otapi <31888571+otapi@users.noreply.github.com> Date: Wed, 10 Oct 2018 23:01:05 +0200 Subject: [PATCH 1/3] Download only shelf Show only titles and download button for specific shelf. Currently only direct link works, e.g: calibre-web/shelfdown/6 --- cps/templates/shelfdown.html | 82 ++++++++++++++++++++++++++++++++++++ cps/web.py | 29 +++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 cps/templates/shelfdown.html diff --git a/cps/templates/shelfdown.html b/cps/templates/shelfdown.html new file mode 100644 index 00000000..32fa78b2 --- /dev/null +++ b/cps/templates/shelfdown.html @@ -0,0 +1,82 @@ + + + + {{instance}} | {{title}} + + + + + + + + + + + {% if g.user.get_theme == 1 %} + + {% endif %} + + + + + {% block header %}{% endblock %} + + +{% block body %} +
+

{{title}}

+
+ + {% for entry in entries %} +
+ +
+

{{entry.title|shortentitle}}

+

+ {% for author in entry.authors %} + {{author.name.replace('|',',')}} + {% if not loop.last %} + & + {% endif %} + {% endfor %} +

+ +
+ +
+ {% if g.user.role_download() %} + {% if entry.data|length %} +
+ {% if entry.data|length < 2 %} + + {% for format in entry.data %} + + {{format.format}} ({{ format.uncompressed_size|filesizeformat }}) + + {% endfor %} + {% else %} + + + {% endif %} +
+ {% endif %} + {% endif %} +
+
+ {% endfor %} +
+
+ +{% endblock %} + + \ No newline at end of file diff --git a/cps/web.py b/cps/web.py index 5d6e766c..b18a2ecc 100644 --- a/cps/web.py +++ b/cps/web.py @@ -2676,6 +2676,35 @@ def show_shelf(shelf_id): return redirect(url_for("index")) +@app.route("/shelfdown/") +@login_required_if_no_ano +def show_shelf_down(shelf_id): + if current_user.is_anonymous: + shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first() + else: + shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id), + ub.Shelf.id == shelf_id), + ub.and_(ub.Shelf.is_public == 1, + ub.Shelf.id == shelf_id))).first() + result = list() + # user is allowed to access shelf + if shelf: + books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by( + ub.BookShelf.order.asc()).all() + for book in books_in_shelf: + cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).first() + if cur_book: + result.append(cur_book) + else: + app.logger.info('Not existing book %s in shelf %s deleted' % (book.book_id, shelf.id)) + ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete() + ub.session.commit() + return render_title_template('shelfdown.html', entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name), + shelf=shelf, page="shelf") + else: + flash(_(u"Error opening shelf. Shelf does not exist or is not accessible"), category="error") + return redirect(url_for("index")) + @app.route("/shelf/order/", methods=["GET", "POST"]) @login_required def order_shelf(shelf_id): From c6d3613e576aa8d0cfa943df5ad51f53c749219d Mon Sep 17 00:00:00 2001 From: otapi <31888571+otapi@users.noreply.github.com> Date: Thu, 11 Oct 2018 18:20:38 +0200 Subject: [PATCH 2/3] Add UI link button to shelves --- cps/templates/shelf.html | 6 +++++- cps/web.py | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html index 28cd20bb..645dad74 100644 --- a/cps/templates/shelf.html +++ b/cps/templates/shelf.html @@ -2,9 +2,13 @@ {% block body %}

{{title}}

+ {% if g.user.role_download() %} + {{ _('Download') }} + {% endif %} {% if g.user.is_authenticated %} {% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %} -
{{ _('Delete this Shelf') }}
+ +
{{ _('Delete this Shelf') }}
{{ _('Edit Shelf') }} {{ _('Change order') }} {% endif %} diff --git a/cps/web.py b/cps/web.py index b18a2ecc..d8d4bab1 100644 --- a/cps/web.py +++ b/cps/web.py @@ -2677,7 +2677,6 @@ def show_shelf(shelf_id): @app.route("/shelfdown/") -@login_required_if_no_ano def show_shelf_down(shelf_id): if current_user.is_anonymous: shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first() From 9b4ca22254d0ce0b3f6c0d8c7e36a68d55997e44 Mon Sep 17 00:00:00 2001 From: otapi <31888571+otapi@users.noreply.github.com> Date: Thu, 11 Oct 2018 18:39:31 +0200 Subject: [PATCH 3/3] Update shelf.html --- cps/templates/shelf.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html index 645dad74..e7d528b3 100644 --- a/cps/templates/shelf.html +++ b/cps/templates/shelf.html @@ -7,8 +7,7 @@ {% endif %} {% if g.user.is_authenticated %} {% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %} - -
{{ _('Delete this Shelf') }}
+
{{ _('Delete this Shelf') }}
{{ _('Edit Shelf') }} {{ _('Change order') }} {% endif %}