diff --git a/cps/admin.py b/cps/admin.py index 3c9d6bf8..ad2db459 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -132,9 +132,9 @@ def admin(): else: commit = version['version'] - content = ub.session.query(ub.User).all() + allUser = ub.session.query(ub.User).all() settings = ub.session.query(ub.Settings).first() - return render_title_template("admin.html", content=content, email=settings, config=config, commit=commit, + return render_title_template("admin.html", allUser=allUser, email=settings, config=config, commit=commit, title=_(u"Admin page"), page="admin") @@ -190,14 +190,14 @@ def view_configuration(): if "edit_shelf_role" in to_save: content.config_default_role = content.config_default_role + ub.ROLE_EDIT_SHELFS - content.config_default_show = 0 - val = [int(k[5:]) for k, v in to_save.items() if k.startswith('show')] - sidebar = ub.get_sidebar_config() - for element in sidebar: - if element['visibility'] in val: - content.config_default_show = content.config_default_show + element['visibility'] + val = 0 + for key,v in to_save.items(): + if key.startswith('show'): + val += int(key[5:]) + content.config_default_show = val + - if "show_mature_content" in to_save: + if "Show_mature_content" in to_save: content.config_default_show = content.config_default_show + ub.MATURE_CONTENT ub.session.commit() flash(_(u"Calibre-Web configuration updated"), category="success") @@ -213,7 +213,7 @@ def view_configuration(): app.logger.info('Reboot required, restarting') readColumn = db.session.query(db.Custom_Columns)\ .filter(db.and_(db.Custom_Columns.datatype == 'bool',db.Custom_Columns.mark_for_delete == 0)).all() - return render_title_template("config_view_edit.html", content=config, readColumns=readColumn, + return render_title_template("config_view_edit.html", conf=config, readColumns=readColumn, title=_(u"UI Configuration"), page="uiconfig") @@ -514,7 +514,7 @@ def new_user(): if request.method == "POST": to_save = request.form.to_dict() content.default_language = to_save["default_language"] - content.mature_content = "show_mature_content" in to_save + content.mature_content = "Show_mature_content" in to_save if "locale" in to_save: content.locale = to_save["locale"] @@ -674,17 +674,12 @@ def edit_user(user_id): elif not element['visibility'] in val and content.check_visibility(element['visibility']): content.sidebar_view -= element['visibility'] - if "Show_read_and_unread" in to_save and not content.show_read_and_unread(): - content.sidebar_view += ub.SIDEBAR_READ_AND_UNREAD - elif "Show_read_and_unread" not in to_save and content.show_read_and_unread(): - content.sidebar_view -= ub.SIDEBAR_READ_AND_UNREAD - if "Show_detail_random" in to_save and not content.show_detail_random(): content.sidebar_view += ub.DETAIL_RANDOM elif "Show_detail_random" not in to_save and content.show_detail_random(): content.sidebar_view -= ub.DETAIL_RANDOM - content.mature_content = "show_mature_content" in to_save + content.mature_content = "Show_mature_content" in to_save if "default_language" in to_save: content.default_language = to_save["default_language"] diff --git a/cps/static/js/table.js b/cps/static/js/table.js index fbb1f0a8..1c828267 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -27,7 +27,7 @@ $(function() { async: true, timeout: 900, success:function(data){ - $("#domain-table"").bootstrapTable("load", data); + $("#domain-table").bootstrapTable("load", data); } }); }); diff --git a/cps/static/js/uploadprogress.js b/cps/static/js/uploadprogress.js index 4e84bde8..b734c9a3 100644 --- a/cps/static/js/uploadprogress.js +++ b/cps/static/js/uploadprogress.js @@ -133,7 +133,7 @@ // Replace the contents of the form, with the returned html if (xhr.status === 422) { var newHtml = $.parseHTML(xhr.responseText); - this.replaceForrm(newHtml); + this.replaceForm(newHtml); this.$modal.modal("hide"); } // Write the error response to the document. @@ -170,7 +170,7 @@ replaceForm: function(html) { var newForm; var formId = this.$form.attr("id"); - if (typeof(formId) !== "undefined") { + if (typeof formId !== "undefined") { newForm = $(html).find("#" + formId); } else { newForm = $(html).find("form"); diff --git a/cps/templates/admin.html b/cps/templates/admin.html index 4984a192..89c598a7 100644 --- a/cps/templates/admin.html +++ b/cps/templates/admin.html @@ -15,7 +15,7 @@ {{_('Upload')}} {{_('Edit')}} - {% for user in content %} + {% for user in allUser %} {% if not user.role_anonymous() or config.config_anonbrowse %} {{user.nickname}} diff --git a/cps/templates/config_view_edit.html b/cps/templates/config_view_edit.html index 590baec4..d0719d64 100644 --- a/cps/templates/config_view_edit.html +++ b/cps/templates/config_view_edit.html @@ -17,44 +17,44 @@
- +
- +
- +
- +
- +
@@ -73,31 +73,31 @@
- +
- +
- +
- +
- +
- +
- +
@@ -116,16 +116,16 @@
{% for element in sidebar %}
- +
{% endfor %}
- +
- +
diff --git a/cps/templates/user_edit.html b/cps/templates/user_edit.html index 41ba0dd5..01b2b2c3 100644 --- a/cps/templates/user_edit.html +++ b/cps/templates/user_edit.html @@ -61,7 +61,7 @@ {% endif %}
{% for element in sidebar %} - {% if element['public'] %} + {% if element['config_show'] %}
@@ -69,12 +69,6 @@ {% endif %} {% endfor %} - {% if not content.role_anonymous() %} -
- - -
- {% endif %}
@@ -89,8 +83,8 @@
{% endif %}
- - + +
diff --git a/cps/ub.py b/cps/ub.py index 28d43125..96e38674 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -68,7 +68,7 @@ SIDEBAR_BEST_RATED = 128 SIDEBAR_READ_AND_UNREAD = 256 SIDEBAR_RECENT = 512 SIDEBAR_SORTED = 1024 -# MATURE_CONTENT = 2048 +MATURE_CONTENT = 2048 SIDEBAR_PUBLISHER = 4096 UPDATE_STABLE = 0 @@ -96,44 +96,49 @@ engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False) Base = declarative_base() -def get_sidebar_config(): +def get_sidebar_config(kwargs=[]): + if 'content' in kwargs: + content = not kwargs['content'].role_anonymous() + else: + content = False sidebar = list() sidebar.append({"glyph": "glyphicon-book", "text": _('Recently Added'), "link": 'web.index', "id": "new", "visibility": SIDEBAR_RECENT, 'public': True, "page": "root", - "show_text": _('Show recent books')}) + "show_text": _('Show recent books'), "config_show":True}) sidebar.append({"glyph": "glyphicon-fire", "text": _('Hot Books'), "link": 'web.hot_books', "id": "hot", - "visibility": SIDEBAR_HOT, 'public': True, "page": "hot", "show_text": _('Show hot books')}) + "visibility": SIDEBAR_HOT, 'public': True, "page": "hot", "show_text": _('Show hot books'), + "config_show":True}) sidebar.append( {"glyph": "glyphicon-star", "text": _('Best rated Books'), "link": 'web.best_rated_books', "id": "rated", "visibility": SIDEBAR_BEST_RATED, 'public': True, "page": "rated", - "show_text": _('Show best rated books')}) + "show_text": _('Show best rated books'), "config_show":True}) sidebar.append({"glyph": "glyphicon-eye-open", "text": _('Read Books'), "link": 'web.read_books', "id": "read", "visibility": SIDEBAR_READ_AND_UNREAD, 'public': (not g.user.is_anonymous), "page": "read", - "show_text": _('Show read')}) + "show_text": _('Show read and unread'), "config_show": content}) sidebar.append( {"glyph": "glyphicon-eye-close", "text": _('Unread Books'), "link": 'web.unread_books', "id": "unread", "visibility": SIDEBAR_READ_AND_UNREAD, 'public': (not g.user.is_anonymous), "page": "read", - "show_text": _('Show unread')}) + "show_text": _('Show unread'), "config_show":False}) sidebar.append({"glyph": "glyphicon-random", "text": _('Discover'), "link": 'web.discover', "id": "rand", "visibility": SIDEBAR_RANDOM, 'public': True, "page": "discover", - "show_text": _('Show random books')}) + "show_text": _('Show random books'), "config_show":True}) sidebar.append({"glyph": "glyphicon-inbox", "text": _('Categories'), "link": 'web.category_list', "id": "cat", "visibility": SIDEBAR_CATEGORY, 'public': True, "page": "category", - "show_text": _('Show category selection')}) + "show_text": _('Show category selection'), "config_show":True}) sidebar.append({"glyph": "glyphicon-bookmark", "text": _('Series'), "link": 'web.series_list', "id": "serie", "visibility": SIDEBAR_SERIES, 'public': True, "page": "series", - "show_text": _('Show series selection')}) + "show_text": _('Show series selection'), "config_show":True}) sidebar.append({"glyph": "glyphicon-user", "text": _('Authors'), "link": 'web.author_list', "id": "author", "visibility": SIDEBAR_AUTHOR, 'public': True, "page": "author", - "show_text": _('Show author selection')}) + "show_text": _('Show author selection'), "config_show":True}) sidebar.append( {"glyph": "glyphicon-text-size", "text": _('Publishers'), "link": 'web.publisher_list', "id": "publisher", "visibility": SIDEBAR_PUBLISHER, 'public': True, "page": "publisher", - "show_text": _('Show publisher selection')}) + "show_text": _('Show publisher selection'), "config_show":True}) sidebar.append({"glyph": "glyphicon-flag", "text": _('Languages'), "link": 'web.language_overview', "id": "lang", "visibility": SIDEBAR_LANGUAGE, 'public': (g.user.filter_language() == 'all'), "page": "language", - "show_text": _('Show language selection')}) + "show_text": _('Show language selection'), "config_show":True}) return sidebar @@ -565,6 +570,9 @@ class Config: return bool((self.config_default_show is not None) and (self.config_default_show & value == value)) + def show_mature_content(self): + return bool((self.config_default_show is not None) and + (self.config_default_show & MATURE_CONTENT == MATURE_CONTENT)) def mature_content_tags(self): if sys.version_info > (3, 0): # Python3 str, Python2 unicode diff --git a/cps/web.py b/cps/web.py index a7a3026f..072069eb 100644 --- a/cps/web.py +++ b/cps/web.py @@ -324,7 +324,7 @@ def get_search_results(term): # Returns the template for rendering and includes the instance name def render_title_template(*args, **kwargs): - sidebar=ub.get_sidebar_config() + sidebar=ub.get_sidebar_config(kwargs) return render_template(instance=config.config_calibre_web_title, sidebar=sidebar, *args, **kwargs) @@ -1476,7 +1476,7 @@ def send_to_kindle(book_id, book_format, convert): @web.route("/me", methods=["GET", "POST"]) @login_required def profile(): - content = ub.session.query(ub.User).filter(ub.User.id == int(current_user.id)).first() + # content = ub.session.query(ub.User).filter(ub.User.id == int(current_user.id)).first() downloads = list() languages = speaking_language() translations = babel.list_translations() + [LC('en')] @@ -1484,7 +1484,7 @@ def profile(): oauth_status = get_oauth_status() else: oauth_status = None - for book in content.downloads: + for book in current_user.downloads: downloadBook = db.session.query(db.Books).filter(db.Books.id == book.book_id).first() if downloadBook: downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first()) @@ -1494,46 +1494,46 @@ def profile(): # ub.session.commit() if request.method == "POST": to_save = request.form.to_dict() - content.random_books = 0 + current_user.random_books = 0 if current_user.role_passwd() or current_user.role_admin(): if "password" in to_save and to_save["password"]: - content.password = generate_password_hash(to_save["password"]) - if "kindle_mail" in to_save and to_save["kindle_mail"] != content.kindle_mail: - content.kindle_mail = to_save["kindle_mail"] - if to_save["email"] and to_save["email"] != content.email: + current_user.password = generate_password_hash(to_save["password"]) + if "kindle_mail" in to_save and to_save["kindle_mail"] != current_user.kindle_mail: + current_user.kindle_mail = to_save["kindle_mail"] + if to_save["email"] and to_save["email"] != current_user.email: if config.config_public_reg and not check_valid_domain(to_save["email"]): flash(_(u"E-mail is not from valid domain"), category="error") - return render_title_template("user_edit.html", content=content, downloads=downloads, + return render_title_template("user_edit.html", content=current_user, downloads=downloads, title=_(u"%(name)s's profile", name=current_user.nickname)) - content.email = to_save["email"] + current_user.email = to_save["email"] if "show_random" in to_save and to_save["show_random"] == "on": - content.random_books = 1 + current_user.random_books = 1 if "default_language" in to_save: - content.default_language = to_save["default_language"] + current_user.default_language = to_save["default_language"] if "locale" in to_save: - content.locale = to_save["locale"] + current_user.locale = to_save["locale"] val = 0 for key,v in to_save.items(): if key.startswith('show'): val += int(key[5:]) - content.sidebar_view = val + current_user.sidebar_view = val if "Show_detail_random" in to_save: - content.sidebar_view += ub.DETAIL_RANDOM + current_user.sidebar_view += ub.DETAIL_RANDOM - content.mature_content = "show_mature_content" in to_save + current_user.mature_content = "Show_mature_content" in to_save try: ub.session.commit() except IntegrityError: ub.session.rollback() flash(_(u"Found an existing account for this e-mail address."), category="error") - return render_title_template("user_edit.html", content=content, downloads=downloads, + return render_title_template("user_edit.html", content=current_user, downloads=downloads, title=_(u"%(name)s's profile", name=current_user.nickname, registered_oauth=oauth_check, oauth_status=oauth_status)) flash(_(u"Profile updated"), category="success") return render_title_template("user_edit.html", translations=translations, profile=1, languages=languages, - content=content, downloads=downloads, title=_(u"%(name)s's profile", + content=current_user, downloads=downloads, title=_(u"%(name)s's profile", name=current_user.nickname), page="me", registered_oauth=oauth_check, oauth_status=oauth_status)