diff --git a/cps/templates/list.html b/cps/templates/list.html index 9cdc154d..709b7e32 100644 --- a/cps/templates/list.html +++ b/cps/templates/list.html @@ -19,7 +19,7 @@ {% for entry in entries %}
{{entry.count}}
-
+ + {% else %} + {% if entry.format %} + {{entry.format}} + {% else %} + {{entry[0].name}}{% endif %}{% endif %}
{% endfor %} diff --git a/cps/ub.py b/cps/ub.py index e298ccd4..2e5f33d5 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -71,6 +71,7 @@ SIDEBAR_SORTED = 1024 MATURE_CONTENT = 2048 SIDEBAR_PUBLISHER = 4096 SIDEBAR_RATING = 8192 +SIDEBAR_FORMAT = 16384 UPDATE_STABLE = 0 AUTO_UPDATE_STABLE = 1 @@ -143,9 +144,13 @@ def get_sidebar_config(kwargs=[]): sidebar.append({"glyph": "glyphicon-star-empty", "text": _('Ratings'), "link": 'web.ratings_list', "id": "rate", "visibility": SIDEBAR_RATING, 'public': True, "page": "rating", "show_text": _('Show ratings selection'), "config_show":True}) + sidebar.append({"glyph": "glyphicon-file", "text": _('File formats'), "link": 'web.formats_list', "id": "format", + "visibility": SIDEBAR_FORMAT, 'public': True, + "page": "format", "show_text": _('Show file formats selection'), "config_show":True}) return sidebar + class UserBase: @property @@ -847,7 +852,7 @@ def create_admin_user(): user.role = ROLE_USER + ROLE_ADMIN + ROLE_DOWNLOAD + ROLE_UPLOAD + ROLE_EDIT + ROLE_DELETE_BOOKS + ROLE_PASSWD user.sidebar_view = DETAIL_RANDOM + SIDEBAR_LANGUAGE + SIDEBAR_SERIES + SIDEBAR_CATEGORY + SIDEBAR_HOT + \ SIDEBAR_RANDOM + SIDEBAR_AUTHOR + SIDEBAR_BEST_RATED + SIDEBAR_READ_AND_UNREAD + SIDEBAR_RECENT + \ - SIDEBAR_SORTED + + MATURE_CONTENT + SIDEBAR_PUBLISHER + SIDEBAR_RATING + SIDEBAR_SORTED + MATURE_CONTENT + SIDEBAR_PUBLISHER + SIDEBAR_RATING + SIDEBAR_FORMAT user.password = generate_password_hash(DEFAULT_PASS) diff --git a/cps/web.py b/cps/web.py index 30794451..07495bd5 100644 --- a/cps/web.py +++ b/cps/web.py @@ -722,7 +722,6 @@ def series(book_id, page): abort(404) -# (cast(db.Ratings.rating/2, SQLString)).label('name'))\ @web.route("/ratings") @login_required_if_no_ano def ratings_list(): @@ -746,7 +745,34 @@ def ratings(book_id, page): entries, random, pagination = fill_indexpage(page, db.Books, db.Books.ratings.any(db.Ratings.id == book_id), [db.Books.timestamp.desc()]) return render_title_template('index.html', random=random, pagination=pagination, entries=entries, - title=_(u"Ratings: %(rating)s stars", rating=(name.rating/2)), page="ratings") + title=_(u"Rating: %(rating)s stars", rating=int(name.rating/2)), page="ratings") + else: + abort(404) + + +@web.route("/formats") +@login_required_if_no_ano +def formats_list(): + if current_user.check_visibility(ub.SIDEBAR_FORMAT): + entries = db.session.query(db.Data, func.count('data.book').label('count'),db.Data.format.label('format'))\ + .join(db.Books).filter(common_filters())\ + .group_by(db.Data.format).order_by(db.Data.format).all() + return render_title_template('list.html', entries=entries, folder='web.formats', charlist=list(), + title=_(u"File formats list"), page="formatslist") + else: + abort(404) + + +@web.route("/formats//", defaults={'page': 1}) +@web.route("/formats//") +@login_required_if_no_ano +def formats(book_id, page): + name = db.session.query(db.Data).filter(db.Data.format == book_id.upper()).first() + if name: + entries, random, pagination = fill_indexpage(page, db.Books, db.Books.data.any(db.Data.format == book_id.upper()), + [db.Books.timestamp.desc()]) + return render_title_template('index.html', random=random, pagination=pagination, entries=entries, + title=_(u"File format: %(format)s", format=name.format), page="formats") else: abort(404)