1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-28 20:39:59 +00:00

#396 implemented

This commit is contained in:
OzzieIsaacs 2017-11-30 20:12:13 +01:00
parent f1fac28203
commit aee5ca0e06
4 changed files with 134 additions and 3 deletions

View File

@ -88,6 +88,7 @@
<option value="40" {% if content.config_log_level == 40 %}selected{% endif %}>ERROR</option>
</select>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="checkbox" id="config_uploading" name="config_uploading" {% if content.config_uploading %}checked{% endif %}>
<label for="config_uploading">{{_('Enable uploading')}}</label>
@ -121,7 +122,6 @@
</div>
</div>
{% endif %}
<h2>{{_('Default Settings for new users')}}</h2>
<div class="form-group">
<input type="checkbox" name="admin_role" id="admin_role" {% if content.role_admin() %}checked{% endif %}>
@ -151,6 +151,57 @@
<input type="checkbox" name="edit_shelf_role" id="edit_shelf_role" {% if content.role_edit_shelfs() %}checked{% endif %}>
<label for="edit_shelf_role">{{_('Allow Editing Public Shelfs')}}</label>
</div>
</div>
<div class="col-sm-6">
<h3>{{_('Default visiblities for new users')}}</h3>
<div class="col-sm-6">
<div class="form-group">
<input type="checkbox" name="show_random" id="show_random" {% if content.show_random_books() %}checked{% endif %}>
<label for="show_random">{{_('Show random books')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_recent" id="show_recent" {% if content.show_recent() %}checked{% endif %}>
<label for="show_recent">{{_('Show recent books')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_sorted" id="show_sorted" {% if content.show_sorted() %}checked{% endif %}>
<label for="show_sorted">{{_('Show sorted books')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_hot" id="show_hot" {% if content.show_hot_books() %}checked{% endif %}>
<label for="show_hot">{{_('Show hot books')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_best_rated" id="show_best_rated" {% if content.show_best_rated_books() %}checked{% endif %}>
<label for="show_best_rated">{{_('Show best rated books')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_language" id="show_language" {% if content.show_language() %}checked{% endif %}>
<label for="show_language">{{_('Show language selection')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_series" id="show_series" {% if content.show_series() %}checked{% endif %}>
<label for="show_series">{{_('Show series selection')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_category" id="show_category" {% if content.show_category() %}checked{% endif %}>
<label for="show_category">{{_('Show category selection')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_author" id="show_author" {% if content.show_author() %}checked{% endif %}>
<label for="show_author">{{_('Show author selection')}}</label>
</div>
<div class="form-group">
<input type="checkbox" name="show_read_and_unread" id="show_read_and_unread" {% if content.show_read_and_unread() %}checked{% endif %}>
<label for="show_read_and_unread">{{_('Show read and unread')}}</label>
</div>
<div class="form-group">
<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>
</div>
</div>
</div>
<div class="col-sm-12">
<button type="submit" class="btn btn-default">{{_('Submit')}}</button>
{% if not origin %}
<a href="{{ url_for('admin') }}" class="btn btn-default">{{_('Back')}}</a>
@ -158,6 +209,7 @@
{% if success %}
<a href="{{ url_for('login') }}" class="btn btn-default">{{_('Login')}}</a>
{% endif %}
</div>
</form>
</div>
{% endblock %}

View File

@ -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"

View File

@ -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():

View File

@ -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"))