From cbb236ba7b3fc4063ed5f5410b9a2cc92121949c Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Fri, 1 Dec 2017 07:53:52 +0100 Subject: [PATCH] Added visiblilty of shelfs to opds catalog (#267) --- cps/static/js/libs/screenfull.min.js | 6 +-- cps/templates/index.xml | 14 ++++++ cps/translations/de/LC_MESSAGES/messages.po | 2 +- cps/web.py | 49 +++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/cps/static/js/libs/screenfull.min.js b/cps/static/js/libs/screenfull.min.js index 6f5eaf33..e7a33a42 100644 --- a/cps/static/js/libs/screenfull.min.js +++ b/cps/static/js/libs/screenfull.min.js @@ -1,7 +1,7 @@ /*! * screenfull -* v1.1.0 - 2013-09-06 -* https://github.com/sindresorhus/screenfull.js +* v3.3.0 - 2017-07-06 * (c) Sindre Sorhus; MIT License */ -!function(a,b){"use strict";var c="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,d=function(){for(var a,c,d=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenchange","MSFullscreenerror"]],e=0,f=d.length,g={};f>e;e++)if(a=d[e],a&&a[1]in b){for(e=0,c=a.length;c>e;e++)g[d[0][e]]=a[e];return g}return!1}(),e={request:function(a){var e=d.requestFullscreen;a=a||b.documentElement,/5\.1[\.\d]* Safari/.test(navigator.userAgent)?a[e]():a[e](c&&Element.ALLOW_KEYBOARD_INPUT)},exit:function(){b[d.exitFullscreen]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){},onerror:function(){},raw:d};return d?(Object.defineProperties(e,{isFullscreen:{get:function(){return!!b[d.fullscreenElement]}},element:{enumerable:!0,get:function(){return b[d.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return!!b[d.fullscreenEnabled]}}}),b.addEventListener(d.fullscreenchange,function(a){e.onchange.call(e,a)}),b.addEventListener(d.fullscreenerror,function(a){e.onerror.call(e,a)}),a.screenfull=e,void 0):(a.screenfull=!1,void 0)}(window,document); \ No newline at end of file + +!function(){"use strict";var a="undefined"!=typeof window&&void 0!==window.document?window.document:{},b="undefined"!=typeof module&&module.exports,c="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,d=function(){for(var b,c=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],d=0,e=c.length,f={};d{{url_for('feed_seriesindex')}} {{_('Books ordered by series')}} + + {{_('Public Shelves')}} + + {{url_for('feed_shelfindex', public="public")}} + {{_('Books organized in public shelfs, visible to everyone')}} + + {% if not current_user.is_anonymous %} + + {{_('Your Shelves')}} + + {{url_for('feed_shelfindex')}} + {{_("User's own shelfs, only visible to the current user himself")}} + + {% endif %} diff --git a/cps/translations/de/LC_MESSAGES/messages.po b/cps/translations/de/LC_MESSAGES/messages.po index 760f63df..b60d375a 100644 --- a/cps/translations/de/LC_MESSAGES/messages.po +++ b/cps/translations/de/LC_MESSAGES/messages.po @@ -1090,7 +1090,7 @@ msgstr "Sprachen" #: cps/templates/layout.html:152 msgid "Public Shelves" -msgstr "Öffentiche Bücherregale" +msgstr "Öffentliche Bücherregale" #: cps/templates/layout.html:156 msgid "Your Shelves" diff --git a/cps/web.py b/cps/web.py index 80875356..b1632431 100755 --- a/cps/web.py +++ b/cps/web.py @@ -840,6 +840,55 @@ def feed_series(book_id): return response +@app.route("/opds/shelfindex/", defaults={'public': 0}) +@app.route("/opds/shelfindex/") +@requires_basic_auth_if_no_ano +def feed_shelfindex(public): + off = request.args.get("offset") + if not off: + off = 0 + if public is not 0: + shelf = g.public_shelfes + number = len(shelf) + else: + shelf = g.user.shelf + number = shelf.count() + pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, + number) + xml = render_title_template('feed.xml', listelements=shelf, folder='feed_shelf', pagination=pagination) + response = make_response(xml) + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" + return response + + +@app.route("/opds/shelf/") +@requires_basic_auth_if_no_ano +def feed_shelf(book_id): + off = request.args.get("offset") + if not off: + off = 0 + if current_user.is_anonymous: + shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == book_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 == book_id), + ub.and_(ub.Shelf.is_public == 1, + ub.Shelf.id == book_id))).first() + result = list() + # user is allowed to access shelf + if shelf: + books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == book_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() + result.append(cur_book) + pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, + len(result)) + xml = render_title_template('feed.xml', entries=result, pagination=pagination) + response = make_response(xml) + response.headers["Content-Type"] = "application/atom+xml; charset=utf-8" + return response + def partial(total_byte_len, part_size_limit): s = [] for p in range(0, total_byte_len, part_size_limit):