mirror of
https://github.com/janeczku/calibre-web
synced 2025-11-07 02:33:01 +00:00
Refactored sidebar (some parts are missing)
This commit is contained in:
129
cps/ub.py
129
cps/ub.py
@@ -31,6 +31,8 @@ import json
|
||||
import datetime
|
||||
from binascii import hexlify
|
||||
import cli
|
||||
from flask import g
|
||||
from flask_babel import gettext as _
|
||||
|
||||
try:
|
||||
from flask_dance.consumer.backend.sqla import OAuthConsumerMixin
|
||||
@@ -66,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
|
||||
@@ -94,6 +96,47 @@ engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False)
|
||||
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:
|
||||
|
||||
@property
|
||||
@@ -159,39 +202,6 @@ class UserBase:
|
||||
def check_visibility(self, 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):
|
||||
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
|
||||
(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
|
||||
(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):
|
||||
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.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_SORTED + MATURE_CONTENT + SIDEBAR_PUBLISHER
|
||||
SIDEBAR_SORTED + SIDEBAR_PUBLISHER
|
||||
|
||||
user.password = generate_password_hash(DEFAULT_PASS)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user