diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html index a317c14b..bdc5e94b 100644 --- a/cps/templates/shelf.html +++ b/cps/templates/shelf.html @@ -2,6 +2,9 @@ {% 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') }}
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 3dabaa2e..c5de39a0 100644 --- a/cps/web.py +++ b/cps/web.py @@ -2675,6 +2675,34 @@ def show_shelf(shelf_id): return redirect(url_for("index")) +@app.route("/shelfdown/") +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):