From aee5ca0e06b71412ea8e982f020cf0ae19e24970 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Thu, 30 Nov 2017 20:12:13 +0100 Subject: [PATCH] #396 implemented --- cps/templates/config_edit.html | 54 ++++++++++++++++++++- cps/translations/de/LC_MESSAGES/messages.po | 2 +- cps/ub.py | 54 ++++++++++++++++++++- cps/web.py | 27 +++++++++++ 4 files changed, 134 insertions(+), 3 deletions(-) diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index cd8c321c..4d59190f 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -88,6 +88,7 @@ +
@@ -121,7 +122,6 @@
{% endif %} -

{{_('Default Settings for new users')}}

@@ -151,6 +151,57 @@
+ +
+

{{_('Default visiblities for new users')}}

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
{% if not origin %} {{_('Back')}} @@ -158,6 +209,7 @@ {% if success %} {{_('Login')}} {% endif %} +
{% endblock %} diff --git a/cps/translations/de/LC_MESSAGES/messages.po b/cps/translations/de/LC_MESSAGES/messages.po index 1aaf8250..760f63df 100644 --- a/cps/translations/de/LC_MESSAGES/messages.po +++ b/cps/translations/de/LC_MESSAGES/messages.po @@ -1284,7 +1284,7 @@ msgstr "Zeige Zufällige Bücher" #: cps/templates/user_edit.html:50 msgid "Show recent books" -msgstr " kürzlich hinzugefügte Bücher" +msgstr "Zeige kürzlich hinzugefügte Bücher" #: cps/templates/user_edit.html:54 msgid "Show sorted books" diff --git a/cps/ub.py b/cps/ub.py index 5f4d5df0..b76ace02 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -281,6 +281,7 @@ class Settings(Base): config_anonbrowse = Column(SmallInteger, default=0) config_public_reg = Column(SmallInteger, default=0) config_default_role = Column(SmallInteger, default=0) + config_default_show = Column(SmallInteger, default=2047) config_columns_to_ignore = Column(String) config_use_google_drive = Column(Boolean) config_google_drive_client_id = Column(String) @@ -288,7 +289,6 @@ class Settings(Base): config_google_drive_folder = Column(String) config_google_drive_calibre_url_base = Column(String) config_google_drive_watch_changes_response = Column(String) - #config_columns_to_ignore = Column(String) config_remote_login = Column(Boolean) config_use_goodreads = Column(Boolean) config_goodreads_api_key = Column(String) @@ -337,6 +337,7 @@ class Config: self.config_anonbrowse = data.config_anonbrowse self.config_public_reg = data.config_public_reg self.config_default_role = data.config_default_role + self.config_default_show = data.config_default_show self.config_columns_to_ignore = data.config_columns_to_ignore self.config_use_google_drive = data.config_use_google_drive self.config_google_drive_client_id = data.config_google_drive_client_id @@ -400,6 +401,50 @@ class Config: return bool((self.config_default_role is not None) and (self.config_default_role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS)) + def show_detail_random(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & DETAIL_RANDOM == DETAIL_RANDOM)) + + def show_language(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_LANGUAGE == SIDEBAR_LANGUAGE)) + + def show_series(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_SERIES == SIDEBAR_SERIES)) + + def show_category(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_CATEGORY == SIDEBAR_CATEGORY)) + + def show_hot_books(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_HOT == SIDEBAR_HOT)) + + def show_random_books(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_RANDOM == SIDEBAR_RANDOM)) + + def show_author(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_AUTHOR == SIDEBAR_AUTHOR)) + + def show_best_rated_books(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_BEST_RATED == SIDEBAR_BEST_RATED)) + + def show_read_and_unread(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_READ_AND_UNREAD == SIDEBAR_READ_AND_UNREAD)) + + def show_recent(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_RECENT == SIDEBAR_RECENT)) + + def show_sorted(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & SIDEBAR_SORTED == SIDEBAR_SORTED)) + def mature_content_tags(self): if sys.version_info > (3, 0): # Python3 str, Python2 unicode lstrip = str.lstrip @@ -532,6 +577,13 @@ def migrate_Database(): except exc.OperationalError: conn = engine.connect() conn.execute("ALTER TABLE Settings ADD column `config_mature_content_tags` String DEFAULT ''") + try: + session.query(exists().where(Settings.config_default_show)).scalar() + session.commit() + except exc.OperationalError: # Database is not compatible, some rows are missing + conn = engine.connect() + conn.execute("ALTER TABLE Settings ADD column `config_default_show` SmallInteger DEFAULT 2047") + session.commit() def clean_database(): diff --git a/cps/web.py b/cps/web.py index 06c4a18a..80875356 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1933,6 +1933,7 @@ def register(): content.nickname = to_save["nickname"] content.email = to_save["email"] content.role = config.config_default_role + content.sidebar_view = config.config_default_show try: ub.session.add(content) ub.session.commit() @@ -2484,6 +2485,7 @@ def configuration_helper(origin): if "config_mature_content_tags" in to_save: content.config_mature_content_tags = to_save["config_mature_content_tags"].strip() + # Default user configuration content.config_default_role = 0 if "admin_role" in to_save: content.config_default_role = content.config_default_role + ub.ROLE_ADMIN @@ -2499,6 +2501,30 @@ def configuration_helper(origin): content.config_default_role = content.config_default_role + ub.ROLE_PASSWD if "passwd_role" in to_save: content.config_default_role = content.config_default_role + ub.ROLE_EDIT_SHELFS + content.config_default_show = 0 + if "show_detail_random" in to_save: + content.config_default_show = content.config_default_show + ub.DETAIL_RANDOM + if "show_language" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_LANGUAGE + if "show_series" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_SERIES + if "show_category" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_CATEGORY + if "show_hot" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_HOT + if "show_random" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_RANDOM + if "show_author" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_AUTHOR + if "show_best_rated" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_BEST_RATED + if "show_read_and_unread" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_READ_AND_UNREAD + if "show_recent" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_RECENT + if "show_sorted" in to_save: + content.config_default_show = content.config_default_show + ub.SIDEBAR_SORTED + try: if content.config_use_google_drive and is_gdrive_ready() and not os.path.exists(config.config_calibre_dir + "/metadata.db"): gdriveutils.downloadFile(Gdrive.Instance().drive, None, "metadata.db", config.config_calibre_dir + "/metadata.db") @@ -2607,6 +2633,7 @@ def new_user(): flash(_(u"Found an existing account for this email address or nickname."), category="error") else: content.role = config.config_default_role + content.sidebar_view = config.config_default_show return render_title_template("user_edit.html", new_user=1, content=content, translations=translations, languages=languages, title=_(u"Add new user"))