+ {% endif %}
+
+
+{% endblock %}
+{% block js %}
+
+{% endblock %}
diff --git a/cps/templates/layout.html b/cps/templates/layout.html
index 559eeabc..fd7c3174 100644
--- a/cps/templates/layout.html
+++ b/cps/templates/layout.html
@@ -17,6 +17,7 @@
{% endif %}
@@ -25,7 +26,7 @@
-
+
diff --git a/cps/ub.py b/cps/ub.py
index 9a405d04..69ab109c 100644
--- a/cps/ub.py
+++ b/cps/ub.py
@@ -204,6 +204,7 @@ class User(UserBase, Base):
denied_column_value = Column(String, default="")
allowed_column_value = Column(String, default="")
remote_auth_token = relationship('RemoteAuthToken', backref='user', lazy='dynamic')
+ series_view = Column(String(10), default="list")
if oauth_support:
@@ -243,6 +244,7 @@ class Anonymous(AnonymousUserMixin, UserBase):
self.allowed_tags = data.allowed_tags
self.denied_column_value = data.denied_column_value
self.allowed_column_value = data.allowed_column_value
+ self.series_view = data.series_view
def role_admin(self):
return False
@@ -349,7 +351,7 @@ class RemoteAuthToken(Base):
# Migrate database to current version, has to be updated after every database change. Currently migration from
-# everywhere to curent should work. Migration is done by checking if relevant coloums are existing, and than adding
+# everywhere to current should work. Migration is done by checking if relevant columns are existing, and than adding
# rows with SQL commands
def migrate_Database(session):
engine = session.bind
@@ -428,6 +430,12 @@ def migrate_Database(session):
conn.execute("ALTER TABLE user ADD column `allowed_tags` String DEFAULT ''")
conn.execute("ALTER TABLE user ADD column `denied_column_value` DEFAULT ''")
conn.execute("ALTER TABLE user ADD column `allowed_column_value` DEFAULT ''")
+ try:
+ session.query(exists().where(User.series_view)).scalar()
+ except exc.OperationalError:
+ conn = engine.connect()
+ conn.execute("ALTER TABLE user ADD column `series_view` VARCHAR(10) DEFAULT 'list'")
+
if session.query(User).filter(User.role.op('&')(constants.ROLE_ANONYMOUS) == constants.ROLE_ANONYMOUS).first() is None:
create_anonymous_user(session)
try:
@@ -446,10 +454,11 @@ def migrate_Database(session):
"locale VARCHAR(2),"
"sidebar_view INTEGER,"
"default_language VARCHAR(3),"
+ "series_view VARCHAR(10),"
"UNIQUE (nickname),"
"UNIQUE (email))")
conn.execute("INSERT INTO user_id(id, nickname, email, role, password, kindle_mail,locale,"
- "sidebar_view, default_language) "
+ "sidebar_view, default_language, series_view) "
"SELECT id, nickname, email, role, password, kindle_mail, locale,"
"sidebar_view, default_language FROM user")
# delete old user table and rename new user_id table to user:
@@ -486,7 +495,7 @@ def delete_download(book_id):
session.query(Downloads).filter(book_id == Downloads.book_id).delete()
session.commit()
-# Generate user Guest (translated text), as anoymous user, no rights
+# Generate user Guest (translated text), as anonymous user, no rights
def create_anonymous_user(session):
user = User()
user.nickname = "Guest"
diff --git a/cps/web.py b/cps/web.py
index bfb0ec5d..5a223387 100644
--- a/cps/web.py
+++ b/cps/web.py
@@ -37,7 +37,7 @@ from flask import Blueprint
from flask import render_template, request, redirect, send_from_directory, make_response, g, flash, abort, url_for
from flask_babel import gettext as _
from flask_login import login_user, logout_user, login_required, current_user
-from sqlalchemy.exc import IntegrityError
+from sqlalchemy.exc import IntegrityError, InvalidRequestError
from sqlalchemy.sql.expression import text, func, true, false, not_, and_, exists, or_
from werkzeug.exceptions import default_exceptions
from werkzeug.datastructures import Headers
@@ -416,6 +416,25 @@ def toggle_read(book_id):
return ""
+@web.route("/ajax/view", methods=["POST"])
+@login_required
+def update_view():
+ to_save = request.form.to_dict()
+ allowed_view = ['grid', 'list']
+ if "series_view" in to_save and to_save["series_view"] in allowed_view:
+ current_user.series_view = to_save["series_view"]
+ else:
+ log.error("Invalid request received: %r %r", request, to_save)
+ return "Invalid request", 400
+
+ try:
+ ub.session.commit()
+ except InvalidRequestError:
+ log.error("Invalid request received: %r ", request, )
+ return "Invalid request", 400
+ return "", 200
+
+
'''
@web.route("/ajax/getcomic///")
@login_required
@@ -775,14 +794,25 @@ def publisher_list():
@login_required_if_no_ano
def series_list():
if current_user.check_visibility(constants.SIDEBAR_SERIES):
- entries = db.session.query(db.Series, func.count('books_series_link.book').label('count')) \
- .join(db.books_series_link).join(db.Books).filter(common_filters()) \
- .group_by(text('books_series_link.series')).order_by(db.Series.sort).all()
- charlist = db.session.query(func.upper(func.substr(db.Series.sort, 1, 1)).label('char')) \
- .join(db.books_series_link).join(db.Books).filter(common_filters()) \
- .group_by(func.upper(func.substr(db.Series.sort, 1, 1))).all()
- return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
- title=_(u"Series"), page="serieslist", data="series")
+ if current_user.series_view == 'list':
+ entries = db.session.query(db.Series, func.count('books_series_link.book').label('count')) \
+ .join(db.books_series_link).join(db.Books).filter(common_filters()) \
+ .group_by(text('books_series_link.series')).order_by(db.Series.sort).all()
+ charlist = db.session.query(func.upper(func.substr(db.Series.sort, 1, 1)).label('char')) \
+ .join(db.books_series_link).join(db.Books).filter(common_filters()) \
+ .group_by(func.upper(func.substr(db.Series.sort, 1, 1))).all()
+ return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
+ title=_(u"Series"), page="serieslist", data="series")
+ else:
+ entries = db.session.query(db.Books, func.count('books_series_link').label('count')) \
+ .join(db.books_series_link).join(db.Series).filter(common_filters()) \
+ .group_by(text('books_series_link.series')).order_by(db.Series.sort).all()
+ charlist = db.session.query(func.upper(func.substr(db.Series.sort, 1, 1)).label('char')) \
+ .join(db.books_series_link).join(db.Books).filter(common_filters()) \
+ .group_by(func.upper(func.substr(db.Series.sort, 1, 1))).all()
+
+ return render_title_template('grid.html', entries=entries, folder='web.books_list', charlist=charlist,
+ title=_(u"Series list"), page="serieslist", data="series", bodyClass="grid-view")
else:
abort(404)