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] 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):