Refactored sidebar (some parts are missing)

pull/932/head
Ozzieisaacs 6 years ago
parent f0de822ce7
commit 0be17ed157

@ -21,7 +21,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import os import os
from flask import Blueprint, flash, redirect, url_for from flask import Blueprint, flash, redirect, url_for
from flask import abort, request, make_response from flask import abort, request, make_response
@ -193,30 +192,12 @@ def view_configuration():
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 content.config_default_show = 0
if "show_detail_random" in to_save: val = [int(k[5:]) for k, v in to_save.items() if k.startswith('show')]
content.config_default_show = content.config_default_show + ub.DETAIL_RANDOM sidebar = ub.get_sidebar_config()
if "show_language" in to_save: for element in sidebar:
content.config_default_show = content.config_default_show + ub.SIDEBAR_LANGUAGE if element['visibility'] in val:
if "show_series" in to_save: content.config_default_show = content.config_default_show + element['visibility']
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_publisher" in to_save:
content.config_default_show = content.config_default_show + ub.SIDEBAR_PUBLISHER
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
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()
@ -537,31 +518,15 @@ def new_user():
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"]
content.sidebar_view = 0
if "show_random" in to_save: val = 0
content.sidebar_view += ub.SIDEBAR_RANDOM for key,v in to_save.items():
if "show_language" in to_save: if key.startswith('show'):
content.sidebar_view += ub.SIDEBAR_LANGUAGE val += int(key[5:])
if "show_series" in to_save: content.sidebar_view = val
content.sidebar_view += ub.SIDEBAR_SERIES
if "show_category" in to_save:
content.sidebar_view += ub.SIDEBAR_CATEGORY
if "show_hot" in to_save:
content.sidebar_view += ub.SIDEBAR_HOT
if "show_read_and_unread" in to_save:
content.sidebar_view += ub.SIDEBAR_READ_AND_UNREAD
if "show_best_rated" in to_save:
content.sidebar_view += ub.SIDEBAR_BEST_RATED
if "show_author" in to_save:
content.sidebar_view += ub.SIDEBAR_AUTHOR
if "show_publisher" in to_save:
content.sidebar_view += ub.SIDEBAR_PUBLISHER
if "show_detail_random" in to_save: if "show_detail_random" in to_save:
content.sidebar_view += ub.DETAIL_RANDOM content.sidebar_view += ub.DETAIL_RANDOM
if "show_sorted" in to_save:
content.sidebar_view += ub.SIDEBAR_SORTED
if "show_recent" in to_save:
content.sidebar_view += ub.SIDEBAR_RECENT
content.role = 0 content.role = 0
if "admin_role" in to_save: if "admin_role" in to_save:
@ -702,67 +667,22 @@ def edit_user(user_id):
elif "edit_shelf_role" not in to_save and content.role_edit_shelfs(): elif "edit_shelf_role" not in to_save and content.role_edit_shelfs():
content.role = content.role - ub.ROLE_EDIT_SHELFS content.role = content.role - ub.ROLE_EDIT_SHELFS
# next(v for k, v in my_dict.items() if k.startswith('show')) val = [int(k[5:]) for k, v in to_save.items() if k.startswith('show')]
val=[{k[5:]:v} for k, v in to_save.items() if k.startswith('show')] sidebar = ub.get_sidebar_config()
# ['15th july'] for element in sidebar:
if "show_random" in to_save and not content.show_random_books(): if element['visibility'] in val and not content.check_visibility(element['visibility']):
content.sidebar_view += ub.SIDEBAR_RANDOM content.sidebar_view += element['visibility']
elif "show_random" not in to_save and content.show_random_books(): elif not element['visibility'] in val and content.check_visibility(element['visibility']):
content.sidebar_view -= ub.SIDEBAR_RANDOM content.sidebar_view -= element['visibility']
if "show_language" in to_save and not content.show_language(): if "Show_read_and_unread" in to_save and not content.show_read_and_unread():
content.sidebar_view += ub.SIDEBAR_LANGUAGE
elif "show_language" not in to_save and content.show_language():
content.sidebar_view -= ub.SIDEBAR_LANGUAGE
if "show_series" in to_save and not content.show_series():
content.sidebar_view += ub.SIDEBAR_SERIES
elif "show_series" not in to_save and content.show_series():
content.sidebar_view -= ub.SIDEBAR_SERIES
if "show_category" in to_save and not content.show_category():
content.sidebar_view += ub.SIDEBAR_CATEGORY
elif "show_category" not in to_save and content.show_category():
content.sidebar_view -= ub.SIDEBAR_CATEGORY
if "show_recent" in to_save and not content.show_recent():
content.sidebar_view += ub.SIDEBAR_RECENT
elif "show_recent" not in to_save and content.show_recent():
content.sidebar_view -= ub.SIDEBAR_RECENT
if "show_sorted" in to_save and not content.show_sorted():
content.sidebar_view += ub.SIDEBAR_SORTED
elif "show_sorted" not in to_save and content.show_sorted():
content.sidebar_view -= ub.SIDEBAR_SORTED
if "show_publisher" in to_save and not content.show_publisher():
content.sidebar_view += ub.SIDEBAR_PUBLISHER
elif "show_publisher" not in to_save and content.show_publisher():
content.sidebar_view -= ub.SIDEBAR_PUBLISHER
if "show_hot" in to_save and not content.show_hot_books():
content.sidebar_view += ub.SIDEBAR_HOT
elif "show_hot" not in to_save and content.show_hot_books():
content.sidebar_view -= ub.SIDEBAR_HOT
if "show_best_rated" in to_save and not content.show_best_rated_books():
content.sidebar_view += ub.SIDEBAR_BEST_RATED
elif "show_best_rated" not in to_save and content.show_best_rated_books():
content.sidebar_view -= ub.SIDEBAR_BEST_RATED
if "show_read_and_unread" in to_save and not content.show_read_and_unread():
content.sidebar_view += ub.SIDEBAR_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(): elif "Show_read_and_unread" not in to_save and content.show_read_and_unread():
content.sidebar_view -= ub.SIDEBAR_READ_AND_UNREAD content.sidebar_view -= ub.SIDEBAR_READ_AND_UNREAD
if "show_author" in to_save and not content.show_author(): if "Show_detail_random" in to_save and not content.show_detail_random():
content.sidebar_view += ub.SIDEBAR_AUTHOR
elif "show_author" not in to_save and content.show_author():
content.sidebar_view -= ub.SIDEBAR_AUTHOR
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

@ -114,65 +114,19 @@
</div> </div>
<div id="collapseseven" class="panel-collapse collapse"> <div id="collapseseven" class="panel-collapse collapse">
<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(element['visibility']) %}checked{% endif %}> <input type="checkbox" name="show_{{element['visibility']}}" id="show_{{element['visibility']}}" {% if content.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">
<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_publisher" id="show_publisher" {% if content.show_publisher() %}checked{% endif %}>
<label for="show_publisher">{{_('Show publisher 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"> <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>
</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 content.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>
</div> </div>

@ -119,7 +119,7 @@
<nav class="navigation"> <nav class="navigation">
<ul class="list-unstyled" id="scnd-nav" intent in-standard-append="nav.navigation" in-mobile-after="#main-nav" in-mobile-class="nav navbar-nav"> <ul class="list-unstyled" id="scnd-nav" intent in-standard-append="nav.navigation" in-mobile-after="#main-nav" in-mobile-class="nav navbar-nav">
<li class="nav-head hidden-xs">{{_('Browse')}}</li> <li class="nav-head hidden-xs">{{_('Browse')}}</li>
{% if g.user.show_sorted() %} {% if g.user.check_visibility(1024) %} <!-- ToDo: eliminate -->
<!--li id="nav_sort" class="dropdown"> <!--li id="nav_sort" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-sort-by-attributes"></span>{{_('Sorted Books')}} <span class="glyphicon glyphicon-sort-by-attributes"></span>{{_('Sorted Books')}}
@ -135,7 +135,7 @@
{%endif%} {%endif%}
{% for element in sidebar %} {% for element in sidebar %}
{% if g.user.check_visibility(element['visibility']) and element['public'] %} {% if g.user.check_visibility(element['visibility']) and element['public'] %}
<li id="nav_{{element['id']}}" {% if page == element['page'] %}class="active"{% endif %}><a href="{{element['link']}}"><span class="glyphicon {{element['glyph']}}"></span>{{_(element['text'])}}</a></li> <li id="nav_{{element['id']}}" {% if page == element['page'] %}class="active"{% endif %}><a href="{{url_for(element['link'])}}"><span class="glyphicon {{element['glyph']}}"></span>{{_(element['text'])}}</a></li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}

@ -69,55 +69,15 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<!--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_publisher" id="show_publisher" {% if content.show_publisher() %}checked{% endif %}>
<label for="show_publisher">{{_('Show publisher selection')}}</label>
</div-->
{% if not content.role_anonymous() %} {% if not content.role_anonymous() %}
<div class="form-group"> <div class="form-group"> <!-- ToDo: Find solution for this -->
<input type="checkbox" name="show_read_and_unread" id="show_read_and_unread" {% if content.show_read_and_unread() %}checked{% endif %}> <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> <label for="Show_read_and_unread">{{_('Show read and unread')}}</label>
</div> </div>
{% endif %} {% 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>
</div> </div>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">

@ -31,6 +31,8 @@ import json
import datetime import datetime
from binascii import hexlify from binascii import hexlify
import cli import cli
from flask import g
from flask_babel import gettext as _
try: try:
from flask_dance.consumer.backend.sqla import OAuthConsumerMixin from flask_dance.consumer.backend.sqla import OAuthConsumerMixin
@ -66,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
@ -94,6 +96,47 @@ engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False)
Base = declarative_base() Base = declarative_base()
def get_sidebar_config():
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')})
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')})
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')})
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')})
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')})
sidebar.append({"glyph": "glyphicon-random", "text": _('Discover'), "link": 'web.discover', "id": "rand",
"visibility": SIDEBAR_RANDOM, 'public': True, "page": "discover",
"show_text": _('Show random books')})
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')})
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')})
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')})
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')})
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')})
return sidebar
class UserBase: class UserBase:
@property @property
@ -159,39 +202,6 @@ class UserBase:
def check_visibility(self, value): def check_visibility(self, value):
return bool((self.sidebar_view is not None) and (self.sidebar_view & value == value)) return bool((self.sidebar_view is not None) and (self.sidebar_view & value == value))
def show_random_books(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_RANDOM == SIDEBAR_RANDOM))
def show_language(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_LANGUAGE == SIDEBAR_LANGUAGE))
def show_hot_books(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_HOT == SIDEBAR_HOT))
def show_recent(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_RECENT == SIDEBAR_RECENT))
def show_sorted(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_SORTED == SIDEBAR_SORTED))
def show_series(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_SERIES == SIDEBAR_SERIES))
def show_category(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_CATEGORY == SIDEBAR_CATEGORY))
def show_author(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_AUTHOR == SIDEBAR_AUTHOR))
def show_publisher(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_PUBLISHER == SIDEBAR_PUBLISHER))
def show_best_rated_books(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_BEST_RATED == SIDEBAR_BEST_RATED))
def show_read_and_unread(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & SIDEBAR_READ_AND_UNREAD == SIDEBAR_READ_AND_UNREAD))
def show_detail_random(self): def show_detail_random(self):
return bool((self.sidebar_view is not None)and(self.sidebar_view & DETAIL_RANDOM == DETAIL_RANDOM)) return bool((self.sidebar_view is not None)and(self.sidebar_view & DETAIL_RANDOM == DETAIL_RANDOM))
@ -551,57 +561,10 @@ 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 & DETAIL_RANDOM == DETAIL_RANDOM)) (self.config_default_show & DETAIL_RANDOM == DETAIL_RANDOM))
def show_element(self, value): def show_element_new_user(self, value):
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_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_publisher(self):
return bool((self.config_default_show is not None) and
(self.config_default_show & SIDEBAR_PUBLISHER == SIDEBAR_PUBLISHER))
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 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
@ -864,7 +827,7 @@ def create_admin_user():
user.role = ROLE_USER + ROLE_ADMIN + ROLE_DOWNLOAD + ROLE_UPLOAD + ROLE_EDIT + ROLE_DELETE_BOOKS + ROLE_PASSWD user.role = ROLE_USER + ROLE_ADMIN + ROLE_DOWNLOAD + ROLE_UPLOAD + ROLE_EDIT + ROLE_DELETE_BOOKS + ROLE_PASSWD
user.sidebar_view = DETAIL_RANDOM + SIDEBAR_LANGUAGE + SIDEBAR_SERIES + SIDEBAR_CATEGORY + SIDEBAR_HOT + \ user.sidebar_view = DETAIL_RANDOM + SIDEBAR_LANGUAGE + SIDEBAR_SERIES + SIDEBAR_CATEGORY + SIDEBAR_HOT + \
SIDEBAR_RANDOM + SIDEBAR_AUTHOR + SIDEBAR_BEST_RATED + SIDEBAR_READ_AND_UNREAD + SIDEBAR_RECENT + \ SIDEBAR_RANDOM + SIDEBAR_AUTHOR + SIDEBAR_BEST_RATED + SIDEBAR_READ_AND_UNREAD + SIDEBAR_RECENT + \
SIDEBAR_SORTED + MATURE_CONTENT + SIDEBAR_PUBLISHER SIDEBAR_SORTED + SIDEBAR_PUBLISHER
user.password = generate_password_hash(DEFAULT_PASS) user.password = generate_password_hash(DEFAULT_PASS)

@ -324,18 +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=list() sidebar=ub.get_sidebar_config()
sidebar.append({"glyph":"glyphicon-book","text":_('Recently Added'),"link":url_for('web.index'),"id":"new", "visibility":ub.SIDEBAR_RECENT, 'public':True, "page": "root", "show_text":_('Show recent books')})
sidebar.append({"glyph":"glyphicon-fire","text":_('Hot Books'),"link":url_for('web.hot_books'),"id":"hot", "visibility":ub.SIDEBAR_HOT, 'public':True, "page": "hot", "show_text":_('Show hot books')})
sidebar.append({"glyph":"glyphicon-star","text":_('Best rated Books'),"link":url_for('web.best_rated_books'),"id":"rated","visibility":ub.SIDEBAR_BEST_RATED, 'public':True, "page": "rated", "show_text":_('Show best rated books')})
sidebar.append({"glyph":"glyphicon-eye-open","text":_('Read Books'),"link":url_for('web.read_books'),"id":"read","visibility":ub.SIDEBAR_READ_AND_UNREAD, 'public':(not g.user.is_anonymous), "page": "read", "show_text":_('Show read')})
sidebar.append({"glyph":"glyphicon-eye-close","text":_('Unread Books'),"link":url_for('web.unread_books'),"id":"unread","visibility":ub.SIDEBAR_READ_AND_UNREAD, 'public':(not g.user.is_anonymous), "page": "read", "show_text":_('Show unread')})
sidebar.append({"glyph":"glyphicon-random","text":_('Discover'),"link":url_for('web.discover'),"id":"rand","visibility":ub.SIDEBAR_RANDOM, 'public':True, "page": "discover", "show_text":_('Show random books')})
sidebar.append({"glyph":"glyphicon-inbox","text":_('Categories'),"link":url_for('web.category_list'),"id":"cat","visibility":ub.SIDEBAR_CATEGORY, 'public':True, "page": "category", "show_text":_('Show category selection')})
sidebar.append({"glyph":"glyphicon-bookmark","text":_('Series'),"link":url_for('web.series_list'),"id":"serie","visibility":ub.SIDEBAR_SERIES, 'public':True, "page": "series", "show_text":_('Show series selection')})
sidebar.append({"glyph":"glyphicon-user","text":_('Authors'),"link":url_for('web.author_list'),"id":"author","visibility":ub.SIDEBAR_AUTHOR, 'public':True, "page": "author", "show_text":_('Show author selection')})
sidebar.append({"glyph":"glyphicon-text-size","text":_('Publishers'),"link":url_for('web.publisher_list'),"id":"publisher","visibility":ub.SIDEBAR_PUBLISHER, 'public':True, "page": "publisher", "show_text":_('Show publisher selection')})
sidebar.append({"glyph":"glyphicon-flag","text":_('Languages'),"link":url_for('web.language_overview'),"id":"lang","visibility":ub.SIDEBAR_LANGUAGE, 'public':(g.user.filter_language() == 'all'), "page": "language", "show_text":_('Show language selection')})
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)
@ -556,7 +545,7 @@ def titles_descending(page):
@web.route('/hot/page/<int:page>') @web.route('/hot/page/<int:page>')
@login_required_if_no_ano @login_required_if_no_ano
def hot_books(page): def hot_books(page):
if current_user.show_hot_books(): if current_user.check_visibility(ub.SIDEBAR_HOT):
if current_user.show_detail_random(): if current_user.show_detail_random():
random = db.session.query(db.Books).filter(common_filters())\ random = db.session.query(db.Books).filter(common_filters())\
.order_by(func.random()).limit(config.config_random_books) .order_by(func.random()).limit(config.config_random_books)
@ -587,7 +576,7 @@ def hot_books(page):
@web.route('/rated/page/<int:page>') @web.route('/rated/page/<int:page>')
@login_required_if_no_ano @login_required_if_no_ano
def best_rated_books(page): def best_rated_books(page):
if current_user.show_best_rated_books(): if current_user.check_visibility(ub.SIDEBAR_BEST_RATED):
entries, random, pagination = fill_indexpage(page, db.Books, db.Books.ratings.any(db.Ratings.rating > 9), entries, random, pagination = fill_indexpage(page, db.Books, db.Books.ratings.any(db.Ratings.rating > 9),
[db.Books.timestamp.desc()]) [db.Books.timestamp.desc()])
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
@ -600,7 +589,7 @@ def best_rated_books(page):
@web.route('/discover/page/<int:page>') @web.route('/discover/page/<int:page>')
@login_required_if_no_ano @login_required_if_no_ano
def discover(page): def discover(page):
if current_user.show_random_books(): if current_user.check_visibility(ub.SIDEBAR_RANDOM):
entries, __, pagination = fill_indexpage(page, db.Books, True, [func.randomblob(2)]) entries, __, pagination = fill_indexpage(page, db.Books, True, [func.randomblob(2)])
pagination = Pagination(1, config.config_books_per_page, config.config_books_per_page) pagination = Pagination(1, config.config_books_per_page, config.config_books_per_page)
return render_title_template('discover.html', entries=entries, pagination=pagination, return render_title_template('discover.html', entries=entries, pagination=pagination,
@ -612,7 +601,7 @@ def discover(page):
@web.route("/author") @web.route("/author")
@login_required_if_no_ano @login_required_if_no_ano
def author_list(): def author_list():
if current_user.show_author(): if current_user.check_visibility(ub.SIDEBAR_AUTHOR):
entries = db.session.query(db.Authors, func.count('books_authors_link.book').label('count'))\ entries = db.session.query(db.Authors, func.count('books_authors_link.book').label('count'))\
.join(db.books_authors_link).join(db.Books).filter(common_filters())\ .join(db.books_authors_link).join(db.Books).filter(common_filters())\
.group_by('books_authors_link.author').order_by(db.Authors.sort).all() .group_by('books_authors_link.author').order_by(db.Authors.sort).all()
@ -657,7 +646,7 @@ def author(book_id, page):
@web.route("/publisher") @web.route("/publisher")
@login_required_if_no_ano @login_required_if_no_ano
def publisher_list(): def publisher_list():
if current_user.show_publisher(): if current_user.check_visibility(ub.SIDEBAR_PUBLISHER):
entries = db.session.query(db.Publishers, func.count('books_publishers_link.book').label('count'))\ entries = db.session.query(db.Publishers, func.count('books_publishers_link.book').label('count'))\
.join(db.books_publishers_link).join(db.Books).filter(common_filters())\ .join(db.books_publishers_link).join(db.Books).filter(common_filters())\
.group_by('books_publishers_link.publisher').order_by(db.Publishers.sort).all() .group_by('books_publishers_link.publisher').order_by(db.Publishers.sort).all()
@ -711,7 +700,7 @@ def get_unique_other_books(library_books, author_books):
@web.route("/series") @web.route("/series")
@login_required_if_no_ano @login_required_if_no_ano
def series_list(): def series_list():
if current_user.show_series(): if current_user.check_visibility(ub.SIDEBAR_SERIES):
entries = db.session.query(db.Series, func.count('books_series_link.book').label('count'))\ 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())\ .join(db.books_series_link).join(db.Books).filter(common_filters())\
.group_by('books_series_link.series').order_by(db.Series.sort).all() .group_by('books_series_link.series').order_by(db.Series.sort).all()
@ -741,7 +730,7 @@ def series(book_id, page):
@web.route("/language") @web.route("/language")
@login_required_if_no_ano @login_required_if_no_ano
def language_overview(): def language_overview():
if current_user.show_language(): if current_user.check_visibility(ub.SIDEBAR_LANGUAGE):
charlist = list() charlist = list()
if current_user.filter_language() == u"all": if current_user.filter_language() == u"all":
languages = speaking_language() languages = speaking_language()
@ -787,7 +776,7 @@ def language(name, page):
@web.route("/category") @web.route("/category")
@login_required_if_no_ano @login_required_if_no_ano
def category_list(): def category_list():
if current_user.show_category(): if current_user.check_visibility(ub.SIDEBAR_CATEGORY):
entries = db.session.query(db.Tags, func.count('books_tags_link.book').label('count'))\ entries = db.session.query(db.Tags, func.count('books_tags_link.book').label('count'))\
.join(db.books_tags_link).join(db.Books).order_by(db.Tags.name).filter(common_filters())\ .join(db.books_tags_link).join(db.Books).order_by(db.Tags.name).filter(common_filters())\
.group_by('books_tags_link.tag').all() .group_by('books_tags_link.tag').all()
@ -1523,30 +1512,13 @@ def profile():
content.default_language = to_save["default_language"] content.default_language = to_save["default_language"]
if "locale" in to_save: if "locale" in to_save:
content.locale = to_save["locale"] content.locale = to_save["locale"]
content.sidebar_view = 0
if "show_random" in to_save: val = 0
content.sidebar_view += ub.SIDEBAR_RANDOM for key,v in to_save.items():
if "show_language" in to_save: if key.startswith('show'):
content.sidebar_view += ub.SIDEBAR_LANGUAGE val += int(key[5:])
if "show_series" in to_save: content.sidebar_view = val
content.sidebar_view += ub.SIDEBAR_SERIES if "Show_detail_random" in to_save:
if "show_category" in to_save:
content.sidebar_view += ub.SIDEBAR_CATEGORY
if "show_recent" in to_save:
content.sidebar_view += ub.SIDEBAR_RECENT
if "show_sorted" in to_save:
content.sidebar_view += ub.SIDEBAR_SORTED
if "show_hot" in to_save:
content.sidebar_view += ub.SIDEBAR_HOT
if "show_best_rated" in to_save:
content.sidebar_view += ub.SIDEBAR_BEST_RATED
if "show_author" in to_save:
content.sidebar_view += ub.SIDEBAR_AUTHOR
if "show_publisher" in to_save:
content.sidebar_view += ub.SIDEBAR_PUBLISHER
if "show_read_and_unread" in to_save:
content.sidebar_view += ub.SIDEBAR_READ_AND_UNREAD
if "show_detail_random" in to_save:
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

Loading…
Cancel
Save