Code cosmetics

Bugfix uploadprogress
Bugfix mature content
Reenable read and unread feature
This commit is contained in:
Ozzieisaacs 2019-03-05 17:34:51 +01:00
parent 0224d45961
commit f483ca3214
8 changed files with 78 additions and 81 deletions

View File

@ -132,9 +132,9 @@ def admin():
else: else:
commit = version['version'] commit = version['version']
content = ub.session.query(ub.User).all() allUser = ub.session.query(ub.User).all()
settings = ub.session.query(ub.Settings).first() 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") title=_(u"Admin page"), page="admin")
@ -190,14 +190,14 @@ def view_configuration():
if "edit_shelf_role" in to_save: if "edit_shelf_role" in to_save:
content.config_default_role = content.config_default_role + ub.ROLE_EDIT_SHELFS content.config_default_role = content.config_default_role + ub.ROLE_EDIT_SHELFS
content.config_default_show = 0 val = 0
val = [int(k[5:]) for k, v in to_save.items() if k.startswith('show')] for key,v in to_save.items():
sidebar = ub.get_sidebar_config() if key.startswith('show'):
for element in sidebar: val += int(key[5:])
if element['visibility'] in val: content.config_default_show = val
content.config_default_show = content.config_default_show + element['visibility']
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 content.config_default_show = content.config_default_show + ub.MATURE_CONTENT
ub.session.commit() ub.session.commit()
flash(_(u"Calibre-Web configuration updated"), category="success") flash(_(u"Calibre-Web configuration updated"), category="success")
@ -213,7 +213,7 @@ def view_configuration():
app.logger.info('Reboot required, restarting') app.logger.info('Reboot required, restarting')
readColumn = db.session.query(db.Custom_Columns)\ readColumn = db.session.query(db.Custom_Columns)\
.filter(db.and_(db.Custom_Columns.datatype == 'bool',db.Custom_Columns.mark_for_delete == 0)).all() .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") title=_(u"UI Configuration"), page="uiconfig")
@ -514,7 +514,7 @@ def new_user():
if request.method == "POST": if request.method == "POST":
to_save = request.form.to_dict() to_save = request.form.to_dict()
content.default_language = to_save["default_language"] 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: if "locale" in to_save:
content.locale = to_save["locale"] 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']): elif not element['visibility'] in val and content.check_visibility(element['visibility']):
content.sidebar_view -= 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(): if "Show_detail_random" in to_save and not content.show_detail_random():
content.sidebar_view += ub.DETAIL_RANDOM content.sidebar_view += ub.DETAIL_RANDOM
elif "Show_detail_random" not in to_save and content.show_detail_random(): elif "Show_detail_random" not in to_save and content.show_detail_random():
content.sidebar_view -= ub.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: if "default_language" in to_save:
content.default_language = to_save["default_language"] content.default_language = to_save["default_language"]

View File

@ -27,7 +27,7 @@ $(function() {
async: true, async: true,
timeout: 900, timeout: 900,
success:function(data){ success:function(data){
$("#domain-table"").bootstrapTable("load", data); $("#domain-table").bootstrapTable("load", data);
} }
}); });
}); });

View File

@ -133,7 +133,7 @@
// Replace the contents of the form, with the returned html // Replace the contents of the form, with the returned html
if (xhr.status === 422) { if (xhr.status === 422) {
var newHtml = $.parseHTML(xhr.responseText); var newHtml = $.parseHTML(xhr.responseText);
this.replaceForrm(newHtml); this.replaceForm(newHtml);
this.$modal.modal("hide"); this.$modal.modal("hide");
} }
// Write the error response to the document. // Write the error response to the document.
@ -170,7 +170,7 @@
replaceForm: function(html) { replaceForm: function(html) {
var newForm; var newForm;
var formId = this.$form.attr("id"); var formId = this.$form.attr("id");
if (typeof(formId) !== "undefined") { if (typeof formId !== "undefined") {
newForm = $(html).find("#" + formId); newForm = $(html).find("#" + formId);
} else { } else {
newForm = $(html).find("form"); newForm = $(html).find("form");

View File

@ -15,7 +15,7 @@
<th class="hidden-xs">{{_('Upload')}}</th> <th class="hidden-xs">{{_('Upload')}}</th>
<th class="hidden-xs">{{_('Edit')}}</th> <th class="hidden-xs">{{_('Edit')}}</th>
</tr> </tr>
{% for user in content %} {% for user in allUser %}
{% if not user.role_anonymous() or config.config_anonbrowse %} {% if not user.role_anonymous() or config.config_anonbrowse %}
<tr> <tr>
<td><a href="{{url_for('admin.edit_user', user_id=user.id)}}">{{user.nickname}}</a></td> <td><a href="{{url_for('admin.edit_user', user_id=user.id)}}">{{user.nickname}}</a></td>

View File

@ -17,44 +17,44 @@
<div class="panel-body"> <div class="panel-body">
<div class="form-group"> <div class="form-group">
<label for="config_calibre_web_title">{{_('Title')}}</label> <label for="config_calibre_web_title">{{_('Title')}}</label>
<input type="text" class="form-control" name="config_calibre_web_title" id="config_calibre_web_title" value="{% if content.config_calibre_web_title != None %}{{ content.config_calibre_web_title }}{% endif %}" autocomplete="off" required> <input type="text" class="form-control" name="config_calibre_web_title" id="config_calibre_web_title" value="{% if conf.config_calibre_web_title != None %}{{ conf.config_calibre_web_title }}{% endif %}" autocomplete="off" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_books_per_page">{{_('Books per page')}}</label> <label for="config_books_per_page">{{_('Books per page')}}</label>
<input type="number" min="1" max="200" class="form-control" name="config_books_per_page" id="config_books_per_page" value="{% if content.config_books_per_page != None %}{{ content.config_books_per_page }}{% endif %}" autocomplete="off"> <input type="number" min="1" max="200" class="form-control" name="config_books_per_page" id="config_books_per_page" value="{% if conf.config_books_per_page != None %}{{ conf.config_books_per_page }}{% endif %}" autocomplete="off">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_random_books">{{_('No. of random books to show')}}</label> <label for="config_random_books">{{_('No. of random books to show')}}</label>
<input type="number" min="1" max="30" class="form-control" name="config_random_books" id="config_random_books" value="{% if content.config_random_books != None %}{{ content.config_random_books }}{% endif %}" autocomplete="off"> <input type="number" min="1" max="30" class="form-control" name="config_random_books" id="config_random_books" value="{% if conf.config_random_books != None %}{{ conf.config_random_books }}{% endif %}" autocomplete="off">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_theme">{{_('Theme')}}</label> <label for="config_theme">{{_('Theme')}}</label>
<select name="config_theme" id="config_theme" class="form-control"> <select name="config_theme" id="config_theme" class="form-control">
<option value="0" {% if content.config_theme == 0 %}selected{% endif %}>{{ _("Standard Theme") }}</option> <option value="0" {% if conf.config_theme == 0 %}selected{% endif %}>{{ _("Standard Theme") }}</option>
<option value="1" {% if content.config_theme == 1 %}selected{% endif %}>{{ _("caliBlur! Dark Theme") }}</option> <option value="1" {% if conf.config_theme == 1 %}selected{% endif %}>{{ _("caliBlur! Dark Theme") }}</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_columns_to_ignore">{{_('Regular expression for ignoring columns')}}</label> <label for="config_columns_to_ignore">{{_('Regular expression for ignoring columns')}}</label>
<input type="text" class="form-control" name="config_columns_to_ignore" id="config_columns_to_ignore" value="{% if content.config_columns_to_ignore != None %}{{ content.config_columns_to_ignore }}{% endif %}" autocomplete="off"> <input type="text" class="form-control" name="config_columns_to_ignore" id="config_columns_to_ignore" value="{% if conf.config_columns_to_ignore != None %}{{ conf.config_columns_to_ignore }}{% endif %}" autocomplete="off">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_read_column">{{_('Link read/unread status to Calibre column')}}</label> <label for="config_read_column">{{_('Link read/unread status to Calibre column')}}</label>
<select name="config_read_column" id="config_read_column" class="form-control"> <select name="config_read_column" id="config_read_column" class="form-control">
<option value="0" {% if content.config_read_column == 0 %}selected{% endif %}></option> <option value="0" {% if conf.config_read_column == 0 %}selected{% endif %}></option>
{% for readColumn in readColumns %} {% for readColumn in readColumns %}
<option value="{{ readColumn.id }}" {% if readColumn.id == content.config_read_column %}selected{% endif %}>{{ readColumn.name }}</option> <option value="{{ readColumn.id }}" {% if readColumn.id == conf.config_read_column %}selected{% endif %}>{{ readColumn.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_title_regex">{{_('Regular expression for title sorting')}}</label> <label for="config_title_regex">{{_('Regular expression for title sorting')}}</label>
<input type="text" class="form-control" name="config_title_regex" id="config_title_regex" value="{% if content.config_title_regex != None %}{{ content.config_title_regex }}{% endif %}" autocomplete="off"> <input type="text" class="form-control" name="config_title_regex" id="config_title_regex" value="{% if conf.config_title_regex != None %}{{ conf.config_title_regex }}{% endif %}" autocomplete="off">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="config_mature_content_tags">{{_('Tags for Mature Content')}}</label> <label for="config_mature_content_tags">{{_('Tags for Mature Content')}}</label>
<input type="text" class="form-control" name="config_mature_content_tags" id="config_mature_content_tags" <input type="text" class="form-control" name="config_mature_content_tags" id="config_mature_content_tags"
value="{% if content.config_mature_content_tags != None%}{{ content.config_mature_content_tags }}{% endif %}" value="{% if conf.config_mature_content_tags != None%}{{ conf.config_mature_content_tags }}{% endif %}"
autocomplete="off" autocomplete="off"
> >
</div> </div>
@ -73,31 +73,31 @@
<div id="collapsesix" class="panel-collapse collapse"> <div id="collapsesix" class="panel-collapse collapse">
<div class="panel-body"> <div class="panel-body">
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="admin_role" id="admin_role" {% if content.role_admin() %}checked{% endif %}> <input type="checkbox" name="admin_role" id="admin_role" {% if conf.role_admin() %}checked{% endif %}>
<label for="admin_role">{{_('Admin user')}}</label> <label for="admin_role">{{_('Admin user')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="download_role" id="download_role" {% if content.role_download() %}checked{% endif %}> <input type="checkbox" name="download_role" id="download_role" {% if conf.role_download() %}checked{% endif %}>
<label for="download_role">{{_('Allow Downloads')}}</label> <label for="download_role">{{_('Allow Downloads')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="upload_role" id="upload_role" {% if content.role_upload() %}checked{% endif %}> <input type="checkbox" name="upload_role" id="upload_role" {% if conf.role_upload() %}checked{% endif %}>
<label for="upload_role">{{_('Allow Uploads')}}</label> <label for="upload_role">{{_('Allow Uploads')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="edit_role" id="edit_role" {% if content.role_edit() %}checked{% endif %}> <input type="checkbox" name="edit_role" id="edit_role" {% if conf.role_edit() %}checked{% endif %}>
<label for="edit_role">{{_('Allow Edit')}}</label> <label for="edit_role">{{_('Allow Edit')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="delete_role" id="delete_role" {% if content.role_delete_books() %}checked{% endif %}> <input type="checkbox" name="delete_role" id="delete_role" {% if conf.role_delete_books() %}checked{% endif %}>
<label for="delete_role">{{_('Allow Delete books')}}</label> <label for="delete_role">{{_('Allow Delete books')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="passwd_role" id="passwd_role" {% if content.role_passwd() %}checked{% endif %}> <input type="checkbox" name="passwd_role" id="passwd_role" {% if conf.role_passwd() %}checked{% endif %}>
<label for="passwd_role">{{_('Allow Changing Password')}}</label> <label for="passwd_role">{{_('Allow Changing Password')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="edit_shelf_role" id="edit_shelf_role" {% if content.role_edit_shelfs() %}checked{% endif %}> <input type="checkbox" name="edit_shelf_role" id="edit_shelf_role" {% if conf.role_edit_shelfs() %}checked{% endif %}>
<label for="edit_shelf_role">{{_('Allow Editing Public Shelfs')}}</label> <label for="edit_shelf_role">{{_('Allow Editing Public Shelfs')}}</label>
</div> </div>
</div> </div>
@ -116,16 +116,16 @@
<div class="panel-body"> <div class="panel-body">
{% for element in sidebar %} {% for element in sidebar %}
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="show_{{element['visibility']}}" id="show_{{element['visibility']}}" {% if content.show_element_new_user(element['visibility']) %}checked{% endif %}> <input type="checkbox" name="show_{{element['visibility']}}" id="show_{{element['visibility']}}" {% if conf.show_element_new_user(element['visibility']) %}checked{% endif %}>
<label for="show_{{element['visibility']}}">{{element['show_text']}}</label> <label for="show_{{element['visibility']}}">{{element['show_text']}}</label>
</div> </div>
{% endfor %} {% endfor %}
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="Show_detail_random" id="Show_detail_random" {% if content.show_detail_random() %}checked{% endif %}> <input type="checkbox" name="Show_detail_random" id="Show_detail_random" {% if conf.show_detail_random() %}checked{% endif %}>
<label for="Show_detail_random">{{_('Show random books in detail view')}}</label> <label for="Show_detail_random">{{_('Show random books in detail view')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="Show_mature_content" id="Show_mature_content" {% if content.show_mature_content() %}checked{% endif %}> <input type="checkbox" name="Show_mature_content" id="Show_mature_content" {% if conf.show_mature_content() %}checked{% endif %}>
<label for="Show_mature_content">{{_('Show mature content')}}</label> <label for="Show_mature_content">{{_('Show mature content')}}</label>
</div> </div>
</div> </div>

View File

@ -61,7 +61,7 @@
{% endif %} {% endif %}
<div class="col-sm-6"> <div class="col-sm-6">
{% for element in sidebar %} {% for element in sidebar %}
{% if element['public'] %} {% if element['config_show'] %}
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="show_{{element['visibility']}}" id="show_{{element['visibility']}}" {% if content.check_visibility(element['visibility']) %}checked{% endif %}> <input type="checkbox" name="show_{{element['visibility']}}" id="show_{{element['visibility']}}" {% if content.check_visibility(element['visibility']) %}checked{% endif %}>
<label for="show_{{element['visibility']}}">{{element['show_text']}}</label> <label for="show_{{element['visibility']}}">{{element['show_text']}}</label>
@ -69,12 +69,6 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if not content.role_anonymous() %}
<div class="form-group"> <!-- ToDo: Find solution for this -->
<input type="checkbox" name="Show_read_and_unread" id="Show_read_and_unread" {% if content.check_visibility(256) %}checked{% endif %}>
<label for="Show_read_and_unread">{{_('Show read and unread')}}</label>
</div>
{% endif %}
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="Show_detail_random" id="Show_detail_random" {% if content.show_detail_random() %}checked{% endif %}> <input type="checkbox" name="Show_detail_random" id="Show_detail_random" {% if content.show_detail_random() %}checked{% endif %}>
<label for="Show_detail_random">{{_('Show random books in detail view')}}</label> <label for="Show_detail_random">{{_('Show random books in detail view')}}</label>
@ -89,8 +83,8 @@
</div> </div>
{% endif %} {% endif %}
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="show_mature_content" id="show_mature_content" {% if content.mature_content %}checked{% endif %}> <input type="checkbox" name="Show_mature_content" id="Show_mature_content" {% if content.mature_content %}checked{% endif %}>
<label for="show_mature_content">{{_('Show mature content')}}</label> <label for="Show_mature_content">{{_('Show mature content')}}</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="download_role" id="download_role" {% if content.role_download() %}checked{% endif %}> <input type="checkbox" name="download_role" id="download_role" {% if content.role_download() %}checked{% endif %}>

View File

@ -68,7 +68,7 @@ SIDEBAR_BEST_RATED = 128
SIDEBAR_READ_AND_UNREAD = 256 SIDEBAR_READ_AND_UNREAD = 256
SIDEBAR_RECENT = 512 SIDEBAR_RECENT = 512
SIDEBAR_SORTED = 1024 SIDEBAR_SORTED = 1024
# MATURE_CONTENT = 2048 MATURE_CONTENT = 2048
SIDEBAR_PUBLISHER = 4096 SIDEBAR_PUBLISHER = 4096
UPDATE_STABLE = 0 UPDATE_STABLE = 0
@ -96,44 +96,49 @@ engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False)
Base = declarative_base() 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 = list()
sidebar.append({"glyph": "glyphicon-book", "text": _('Recently Added'), "link": 'web.index', "id": "new", sidebar.append({"glyph": "glyphicon-book", "text": _('Recently Added'), "link": 'web.index', "id": "new",
"visibility": SIDEBAR_RECENT, 'public': True, "page": "root", "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", 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( sidebar.append(
{"glyph": "glyphicon-star", "text": _('Best rated Books'), "link": 'web.best_rated_books', "id": "rated", {"glyph": "glyphicon-star", "text": _('Best rated Books'), "link": 'web.best_rated_books', "id": "rated",
"visibility": SIDEBAR_BEST_RATED, 'public': True, "page": "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", 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", "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( sidebar.append(
{"glyph": "glyphicon-eye-close", "text": _('Unread Books'), "link": 'web.unread_books', "id": "unread", {"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", "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", sidebar.append({"glyph": "glyphicon-random", "text": _('Discover'), "link": 'web.discover', "id": "rand",
"visibility": SIDEBAR_RANDOM, 'public': True, "page": "discover", "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", sidebar.append({"glyph": "glyphicon-inbox", "text": _('Categories'), "link": 'web.category_list', "id": "cat",
"visibility": SIDEBAR_CATEGORY, 'public': True, "page": "category", "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", sidebar.append({"glyph": "glyphicon-bookmark", "text": _('Series'), "link": 'web.series_list', "id": "serie",
"visibility": SIDEBAR_SERIES, 'public': True, "page": "series", "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", sidebar.append({"glyph": "glyphicon-user", "text": _('Authors'), "link": 'web.author_list', "id": "author",
"visibility": SIDEBAR_AUTHOR, 'public': True, "page": "author", "visibility": SIDEBAR_AUTHOR, 'public': True, "page": "author",
"show_text": _('Show author selection')}) "show_text": _('Show author selection'), "config_show":True})
sidebar.append( sidebar.append(
{"glyph": "glyphicon-text-size", "text": _('Publishers'), "link": 'web.publisher_list', "id": "publisher", {"glyph": "glyphicon-text-size", "text": _('Publishers'), "link": 'web.publisher_list', "id": "publisher",
"visibility": SIDEBAR_PUBLISHER, 'public': True, "page": "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", sidebar.append({"glyph": "glyphicon-flag", "text": _('Languages'), "link": 'web.language_overview', "id": "lang",
"visibility": SIDEBAR_LANGUAGE, 'public': (g.user.filter_language() == 'all'), "visibility": SIDEBAR_LANGUAGE, 'public': (g.user.filter_language() == 'all'),
"page": "language", "page": "language",
"show_text": _('Show language selection')}) "show_text": _('Show language selection'), "config_show":True})
return sidebar return sidebar
@ -565,6 +570,9 @@ class Config:
return bool((self.config_default_show is not None) and return bool((self.config_default_show is not None) and
(self.config_default_show & value == value)) (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): def mature_content_tags(self):
if sys.version_info > (3, 0): # Python3 str, Python2 unicode if sys.version_info > (3, 0): # Python3 str, Python2 unicode

View File

@ -324,7 +324,7 @@ def get_search_results(term):
# Returns the template for rendering and includes the instance name # Returns the template for rendering and includes the instance name
def render_title_template(*args, **kwargs): 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) 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"]) @web.route("/me", methods=["GET", "POST"])
@login_required @login_required
def profile(): 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() downloads = list()
languages = speaking_language() languages = speaking_language()
translations = babel.list_translations() + [LC('en')] translations = babel.list_translations() + [LC('en')]
@ -1484,7 +1484,7 @@ def profile():
oauth_status = get_oauth_status() oauth_status = get_oauth_status()
else: else:
oauth_status = None 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() downloadBook = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
if downloadBook: if downloadBook:
downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first()) downloads.append(db.session.query(db.Books).filter(db.Books.id == book.book_id).first())
@ -1494,46 +1494,46 @@ def profile():
# ub.session.commit() # ub.session.commit()
if request.method == "POST": if request.method == "POST":
to_save = request.form.to_dict() 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 current_user.role_passwd() or current_user.role_admin():
if "password" in to_save and to_save["password"]: if "password" in to_save and to_save["password"]:
content.password = generate_password_hash(to_save["password"]) current_user.password = generate_password_hash(to_save["password"])
if "kindle_mail" in to_save and to_save["kindle_mail"] != content.kindle_mail: if "kindle_mail" in to_save and to_save["kindle_mail"] != current_user.kindle_mail:
content.kindle_mail = to_save["kindle_mail"] current_user.kindle_mail = to_save["kindle_mail"]
if to_save["email"] and to_save["email"] != content.email: if to_save["email"] and to_save["email"] != current_user.email:
if config.config_public_reg and not check_valid_domain(to_save["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") 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)) 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": 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: 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: if "locale" in to_save:
content.locale = to_save["locale"] current_user.locale = to_save["locale"]
val = 0 val = 0
for key,v in to_save.items(): for key,v in to_save.items():
if key.startswith('show'): if key.startswith('show'):
val += int(key[5:]) val += int(key[5:])
content.sidebar_view = val current_user.sidebar_view = val
if "Show_detail_random" in to_save: 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: try:
ub.session.commit() ub.session.commit()
except IntegrityError: except IntegrityError:
ub.session.rollback() ub.session.rollback()
flash(_(u"Found an existing account for this e-mail address."), category="error") 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, title=_(u"%(name)s's profile", name=current_user.nickname,
registered_oauth=oauth_check, oauth_status=oauth_status)) registered_oauth=oauth_check, oauth_status=oauth_status))
flash(_(u"Profile updated"), category="success") flash(_(u"Profile updated"), category="success")
return render_title_template("user_edit.html", translations=translations, profile=1, languages=languages, 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, name=current_user.nickname), page="me", registered_oauth=oauth_check,
oauth_status=oauth_status) oauth_status=oauth_status)