mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 20:39:59 +00:00
Merge remote-tracking branch 'adv/mature-content'
This commit is contained in:
commit
b596734c36
@ -72,6 +72,13 @@
|
|||||||
<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 content.config_title_regex != None %}{{ content.config_title_regex }}{% endif %}" autocomplete="off">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<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"
|
||||||
|
value="{% if content.config_mature_content_tags != None%}{{ content.config_mature_content_tags }}{% endif %}"
|
||||||
|
autocomplete="off"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="config_log_level">{{_('Log Level')}}</label>
|
<label for="config_log_level">{{_('Log Level')}}</label>
|
||||||
<select name="config_log_level" id="config_log_level" class="form-control">
|
<select name="config_log_level" id="config_log_level" class="form-control">
|
||||||
|
@ -41,7 +41,10 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="checkbox" name="show_random" id="show_random" {% if content.show_random_books() %}checked{% endif %}>
|
<input type="checkbox" name="show_random" id="show_random" {% if content.show_random_books() %}checked{% endif %}>
|
||||||
<label for="show_random">{{_('Show random books')}}</label>
|
<label for="show_random">{{_('Show random books')}}</label>
|
||||||
@ -78,7 +81,7 @@
|
|||||||
<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">
|
||||||
{% if g.user and g.user.role_admin() and not profile %}
|
{% if g.user and g.user.role_admin() and not profile %}
|
||||||
{% if not content.role_anonymous() %}
|
{% if not content.role_anonymous() %}
|
||||||
|
17
cps/ub.py
17
cps/ub.py
@ -157,6 +157,7 @@ class User(UserBase, Base):
|
|||||||
locale = Column(String(2), default="en")
|
locale = Column(String(2), default="en")
|
||||||
sidebar_view = Column(Integer, default=1)
|
sidebar_view = Column(Integer, default=1)
|
||||||
default_language = Column(String(3), default="all")
|
default_language = Column(String(3), default="all")
|
||||||
|
mature_content = Column(Boolean, default=True)
|
||||||
|
|
||||||
|
|
||||||
# Class for anonymous user is derived from User base and complets overrides methods and properties for the
|
# Class for anonymous user is derived from User base and complets overrides methods and properties for the
|
||||||
@ -266,6 +267,7 @@ class Settings(Base):
|
|||||||
config_use_goodreads = Column(Boolean)
|
config_use_goodreads = Column(Boolean)
|
||||||
config_goodreads_api_key = Column(String)
|
config_goodreads_api_key = Column(String)
|
||||||
config_goodreads_api_secret = Column(String)
|
config_goodreads_api_secret = Column(String)
|
||||||
|
config_mature_content_tags = Column(String) # type: str
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
pass
|
pass
|
||||||
@ -297,7 +299,7 @@ class Config:
|
|||||||
self.loadSettings()
|
self.loadSettings()
|
||||||
|
|
||||||
def loadSettings(self):
|
def loadSettings(self):
|
||||||
data = session.query(Settings).first()
|
data = session.query(Settings).first() # type: Settings
|
||||||
self.config_calibre_dir = data.config_calibre_dir
|
self.config_calibre_dir = data.config_calibre_dir
|
||||||
self.config_port = data.config_port
|
self.config_port = data.config_port
|
||||||
self.config_calibre_web_title = data.config_calibre_web_title
|
self.config_calibre_web_title = data.config_calibre_web_title
|
||||||
@ -326,6 +328,7 @@ class Config:
|
|||||||
self.config_use_goodreads = data.config_use_goodreads
|
self.config_use_goodreads = data.config_use_goodreads
|
||||||
self.config_goodreads_api_key = data.config_goodreads_api_key
|
self.config_goodreads_api_key = data.config_goodreads_api_key
|
||||||
self.config_goodreads_api_secret = data.config_goodreads_api_secret
|
self.config_goodreads_api_secret = data.config_goodreads_api_secret
|
||||||
|
self.config_mature_content_tags = data.config_mature_content_tags
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def get_main_dir(self):
|
def get_main_dir(self):
|
||||||
@ -371,6 +374,8 @@ class Config:
|
|||||||
return bool((self.config_default_role is not None) and
|
return bool((self.config_default_role is not None) and
|
||||||
(self.config_default_role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS))
|
(self.config_default_role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS))
|
||||||
|
|
||||||
|
def mature_content_tags(self):
|
||||||
|
return self.config_mature_content_tags.split(",")
|
||||||
|
|
||||||
def get_Log_Level(self):
|
def get_Log_Level(self):
|
||||||
ret_value=""
|
ret_value=""
|
||||||
@ -470,6 +475,11 @@ def migrate_Database():
|
|||||||
'side_lang': SIDEBAR_LANGUAGE, 'side_series': SIDEBAR_SERIES, 'side_category': SIDEBAR_CATEGORY,
|
'side_lang': SIDEBAR_LANGUAGE, 'side_series': SIDEBAR_SERIES, 'side_category': SIDEBAR_CATEGORY,
|
||||||
'side_hot': SIDEBAR_HOT, 'side_autor': SIDEBAR_AUTHOR, 'detail_random': DETAIL_RANDOM})
|
'side_hot': SIDEBAR_HOT, 'side_autor': SIDEBAR_AUTHOR, 'detail_random': DETAIL_RANDOM})
|
||||||
session.commit()
|
session.commit()
|
||||||
|
try:
|
||||||
|
session.query(exists().where(User.mature_content)).scalar()
|
||||||
|
except exc.OperationalError:
|
||||||
|
conn = engine.connect()
|
||||||
|
conn.execute("ALTER TABLE user ADD column `mature_content` INTEGER DEFAULT 1")
|
||||||
if session.query(User).filter(User.role.op('&')(ROLE_ANONYMOUS) == ROLE_ANONYMOUS).first() is None:
|
if session.query(User).filter(User.role.op('&')(ROLE_ANONYMOUS) == ROLE_ANONYMOUS).first() is None:
|
||||||
create_anonymous_user()
|
create_anonymous_user()
|
||||||
try:
|
try:
|
||||||
@ -484,6 +494,11 @@ def migrate_Database():
|
|||||||
conn.execute("ALTER TABLE Settings ADD column `config_use_goodreads` INTEGER DEFAULT 0")
|
conn.execute("ALTER TABLE Settings ADD column `config_use_goodreads` INTEGER DEFAULT 0")
|
||||||
conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_key` String DEFAULT ''")
|
conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_key` String DEFAULT ''")
|
||||||
conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_secret` String DEFAULT ''")
|
conn.execute("ALTER TABLE Settings ADD column `config_goodreads_api_secret` String DEFAULT ''")
|
||||||
|
try:
|
||||||
|
session.query(exists().where(Settings.config_mature_content_tags)).scalar()
|
||||||
|
except exc.OperationalError:
|
||||||
|
conn = engine.connect()
|
||||||
|
conn.execute("ALTER TABLE Settings ADD column `config_mature_content_tags` String DEFAULT ''")
|
||||||
|
|
||||||
def clean_database():
|
def clean_database():
|
||||||
# Remove expired remote login tokens
|
# Remove expired remote login tokens
|
||||||
|
108
cps/web.py
108
cps/web.py
@ -505,15 +505,19 @@ def fill_indexpage(page, database, db_filter, order):
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
if current_user.show_detail_random():
|
if current_user.show_detail_random():
|
||||||
random = db.session.query(db.Books).filter(lang_filter).order_by(func.random()).limit(config.config_random_books)
|
random = db.session.query(db.Books).filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.order_by(func.random()).limit(config.config_random_books)
|
||||||
else:
|
else:
|
||||||
random = false
|
random = false
|
||||||
off = int(int(config.config_books_per_page) * (page - 1))
|
off = int(int(config.config_books_per_page) * (page - 1))
|
||||||
pagination = Pagination(page, config.config_books_per_page,
|
pagination = Pagination(page, config.config_books_per_page,
|
||||||
len(db.session.query(database).filter(db_filter).filter(lang_filter).all()))
|
len(db.session.query(database)
|
||||||
entries = db.session.query(database).filter(db_filter).filter(lang_filter).order_by(order).offset(off).limit(
|
.filter(db_filter).filter(lang_filter).filter(~content_rating_filter).all()))
|
||||||
config.config_books_per_page)
|
entries = db.session.query(database).filter(db_filter).filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.order_by(order).offset(off).limit(config.config_books_per_page)
|
||||||
return entries, random, pagination
|
return entries, random, pagination
|
||||||
|
|
||||||
|
|
||||||
@ -638,12 +642,15 @@ def feed_search(term):
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
if term:
|
if term:
|
||||||
entries = db.session.query(db.Books).filter(db.or_(db.Books.tags.any(db.Tags.name.like("%" + term + "%")),
|
entries = db.session.query(db.Books).filter(db.or_(db.Books.tags.any(db.Tags.name.like("%" + term + "%")),
|
||||||
db.Books.series.any(db.Series.name.like("%" + term + "%")),
|
db.Books.series.any(db.Series.name.like("%" + term + "%")),
|
||||||
db.Books.authors.any(db.Authors.name.like("%" + term + "%")),
|
db.Books.authors.any(db.Authors.name.like("%" + term + "%")),
|
||||||
db.Books.publishers.any(db.Publishers.name.like("%" + term + "%")),
|
db.Books.publishers.any(db.Publishers.name.like("%" + term + "%")),
|
||||||
db.Books.title.like("%" + term + "%"))).filter(lang_filter).all()
|
db.Books.title.like("%" + term + "%")))\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter).all()
|
||||||
entriescount = len(entries) if len(entries) > 0 else 1
|
entriescount = len(entries) if len(entries) > 0 else 1
|
||||||
pagination = Pagination(1, entriescount, entriescount)
|
pagination = Pagination(1, entriescount, entriescount)
|
||||||
xml = render_title_template('feed.xml', searchterm=term, entries=entries, pagination=pagination)
|
xml = render_title_template('feed.xml', searchterm=term, entries=entries, pagination=pagination)
|
||||||
@ -675,7 +682,10 @@ def feed_discover():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Books).filter(lang_filter).order_by(func.random()).limit(config.config_books_per_page)
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
|
entries = db.session.query(db.Books).filter(lang_filter).filter(~content_rating_filter).order_by(func.random())\
|
||||||
|
.limit(config.config_books_per_page)
|
||||||
pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page))
|
pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page))
|
||||||
xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
|
xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
|
||||||
response = make_response(xml)
|
response = make_response(xml)
|
||||||
@ -707,6 +717,8 @@ def feed_hot():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
all_books = ub.session.query(ub.Downloads, ub.func.count(ub.Downloads.book_id)).order_by(
|
all_books = ub.session.query(ub.Downloads, ub.func.count(ub.Downloads.book_id)).order_by(
|
||||||
ub.func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id)
|
ub.func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id)
|
||||||
hot_books = all_books.offset(off).limit(config.config_books_per_page)
|
hot_books = all_books.offset(off).limit(config.config_books_per_page)
|
||||||
@ -715,7 +727,9 @@ def feed_hot():
|
|||||||
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.Downloads.book_id).first()
|
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.Downloads.book_id).first()
|
||||||
if downloadBook:
|
if downloadBook:
|
||||||
entries.append(
|
entries.append(
|
||||||
db.session.query(db.Books).filter(lang_filter).filter(db.Books.id == book.Downloads.book_id).first())
|
db.session.query(db.Books).filter(lang_filter).filter(~content_rating_filter)
|
||||||
|
.filter(db.Books.id == book.Downloads.book_id).first()
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
ub.session.query(ub.Downloads).filter(book.Downloads.book_id == ub.Downloads.book_id).delete()
|
ub.session.query(ub.Downloads).filter(book.Downloads.book_id == ub.Downloads.book_id).delete()
|
||||||
ub.session.commit()
|
ub.session.commit()
|
||||||
@ -737,7 +751,10 @@ def feed_authorindex():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Authors).join(db.books_authors_link).join(db.Books).filter(lang_filter)\
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
|
entries = db.session.query(db.Authors).join(db.books_authors_link).join(db.Books)\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter)\
|
||||||
.group_by('books_authors_link.author').order_by(db.Authors.sort).limit(config.config_books_per_page).offset(off)
|
.group_by('books_authors_link.author').order_by(db.Authors.sort).limit(config.config_books_per_page).offset(off)
|
||||||
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
|
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
|
||||||
len(db.session.query(db.Authors).all()))
|
len(db.session.query(db.Authors).all()))
|
||||||
@ -771,8 +788,11 @@ def feed_categoryindex():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Tags).join(db.books_tags_link).join(db.Books).filter(lang_filter).\
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
group_by('books_tags_link.tag').order_by(db.Tags.name).offset(off).limit(config.config_books_per_page)
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
|
entries = db.session.query(db.Tags).join(db.books_tags_link).join(db.Books)\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.group_by('books_tags_link.tag').order_by(db.Tags.name).offset(off).limit(config.config_books_per_page)
|
||||||
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
|
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
|
||||||
len(db.session.query(db.Tags).all()))
|
len(db.session.query(db.Tags).all()))
|
||||||
xml = render_title_template('feed.xml', listelements=entries, folder='feed_category', pagination=pagination)
|
xml = render_title_template('feed.xml', listelements=entries, folder='feed_category', pagination=pagination)
|
||||||
@ -805,8 +825,11 @@ def feed_seriesindex():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Series).join(db.books_series_link).join(db.Books).filter(lang_filter).\
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
group_by('books_series_link.series').order_by(db.Series.sort).offset(off).all()
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
|
entries = db.session.query(db.Series).join(db.books_series_link).join(db.Books)\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.group_by('books_series_link.series').order_by(db.Series.sort).offset(off).all()
|
||||||
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
|
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
|
||||||
len(db.session.query(db.Series).all()))
|
len(db.session.query(db.Series).all()))
|
||||||
xml = render_title_template('feed.xml', listelements=entries, folder='feed_series', pagination=pagination)
|
xml = render_title_template('feed.xml', listelements=entries, folder='feed_series', pagination=pagination)
|
||||||
@ -1075,8 +1098,11 @@ def hot_books(page):
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
if current_user.show_detail_random():
|
if current_user.show_detail_random():
|
||||||
random = db.session.query(db.Books).filter(lang_filter).order_by(func.random()).limit(config.config_random_books)
|
random = db.session.query(db.Books).filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.order_by(func.random()).limit(config.config_random_books)
|
||||||
else:
|
else:
|
||||||
random = false
|
random = false
|
||||||
off = int(int(config.config_books_per_page) * (page - 1))
|
off = int(int(config.config_books_per_page) * (page - 1))
|
||||||
@ -1088,7 +1114,9 @@ def hot_books(page):
|
|||||||
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.Downloads.book_id).first()
|
downloadBook = db.session.query(db.Books).filter(db.Books.id == book.Downloads.book_id).first()
|
||||||
if downloadBook:
|
if downloadBook:
|
||||||
entries.append(
|
entries.append(
|
||||||
db.session.query(db.Books).filter(lang_filter).filter(db.Books.id == book.Downloads.book_id).first())
|
db.session.query(db.Books).filter(lang_filter).filter(~content_rating_filter)
|
||||||
|
.filter(db.Books.id == book.Downloads.book_id).first()
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
ub.session.query(ub.Downloads).filter(book.Downloads.book_id == ub.Downloads.book_id).delete()
|
ub.session.query(ub.Downloads).filter(book.Downloads.book_id == ub.Downloads.book_id).delete()
|
||||||
ub.session.commit()
|
ub.session.commit()
|
||||||
@ -1124,9 +1152,12 @@ def author_list():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Authors, func.count('books_authors_link.book').label('count')).join(
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
db.books_authors_link).join(db.Books).filter(
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
lang_filter).group_by('books_authors_link.author').order_by(db.Authors.sort).all()
|
entries = db.session.query(db.Authors, func.count('books_authors_link.book').label('count'))\
|
||||||
|
.join(db.books_authors_link).join(db.Books)\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.group_by('books_authors_link.author').order_by(db.Authors.sort).all()
|
||||||
return render_title_template('list.html', entries=entries, folder='author', title=_(u"Author list"))
|
return render_title_template('list.html', entries=entries, folder='author', title=_(u"Author list"))
|
||||||
|
|
||||||
|
|
||||||
@ -1158,9 +1189,12 @@ def series_list():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Series, func.count('books_series_link.book').label('count')).join(
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
db.books_series_link).join(db.Books).filter(
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
lang_filter).group_by('books_series_link.series').order_by(db.Series.sort).all()
|
entries = db.session.query(db.Series, func.count('books_series_link.book').label('count'))\
|
||||||
|
.join(db.books_series_link).join(db.Books)\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.group_by('books_series_link.series').order_by(db.Series.sort).all()
|
||||||
return render_title_template('list.html', entries=entries, folder='series', title=_(u"Series list"))
|
return render_title_template('list.html', entries=entries, folder='series', title=_(u"Series list"))
|
||||||
|
|
||||||
|
|
||||||
@ -1231,9 +1265,12 @@ def category_list():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Tags, func.count('books_tags_link.book').label('count')).join(
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
db.books_tags_link).join(db.Books).filter(
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
lang_filter).group_by('books_tags_link.tag').all()
|
entries = db.session.query(db.Tags, func.count('books_tags_link.book').label('count'))\
|
||||||
|
.join(db.books_tags_link).join(db.Books)\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter)\
|
||||||
|
.group_by('books_tags_link.tag').all()
|
||||||
return render_title_template('list.html', entries=entries, folder='category', title=_(u"Category list"))
|
return render_title_template('list.html', entries=entries, folder='category', title=_(u"Category list"))
|
||||||
|
|
||||||
|
|
||||||
@ -1274,7 +1311,10 @@ def show_book(book_id):
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
entries = db.session.query(db.Books).filter(db.Books.id == book_id).filter(lang_filter).first()
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
|
entries = db.session.query(db.Books)\
|
||||||
|
.filter(db.Books.id == book_id).filter(lang_filter).filter(~content_rating_filter).first()
|
||||||
if entries:
|
if entries:
|
||||||
for index in range(0, len(entries.languages)):
|
for index in range(0, len(entries.languages)):
|
||||||
try:
|
try:
|
||||||
@ -1551,11 +1591,14 @@ def search():
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
entries = db.session.query(db.Books).filter(db.or_(db.Books.tags.any(db.Tags.name.like("%" + term + "%")),
|
entries = db.session.query(db.Books).filter(db.or_(db.Books.tags.any(db.Tags.name.like("%" + term + "%")),
|
||||||
db.Books.series.any(db.Series.name.like("%" + term + "%")),
|
db.Books.series.any(db.Series.name.like("%" + term + "%")),
|
||||||
db.Books.authors.any(db.Authors.name.like("%" + term + "%")),
|
db.Books.authors.any(db.Authors.name.like("%" + term + "%")),
|
||||||
db.Books.publishers.any(db.Publishers.name.like("%" + term + "%")),
|
db.Books.publishers.any(db.Publishers.name.like("%" + term + "%")),
|
||||||
db.Books.title.like("%" + term + "%"))).filter(lang_filter).all()
|
db.Books.title.like("%" + term + "%")))\
|
||||||
|
.filter(lang_filter).filter(~content_rating_filter).all()
|
||||||
return render_title_template('search.html', searchterm=term, entries=entries)
|
return render_title_template('search.html', searchterm=term, entries=entries)
|
||||||
else:
|
else:
|
||||||
return render_title_template('search.html', searchterm="")
|
return render_title_template('search.html', searchterm="")
|
||||||
@ -2319,7 +2362,7 @@ def configuration_helper(origin):
|
|||||||
success = False
|
success = False
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
to_save = request.form.to_dict()
|
to_save = request.form.to_dict()
|
||||||
content = ub.session.query(ub.Settings).first()
|
content = ub.session.query(ub.Settings).first() # type: ub.Settings
|
||||||
if "config_calibre_dir" in to_save:
|
if "config_calibre_dir" in to_save:
|
||||||
if content.config_calibre_dir != to_save["config_calibre_dir"]:
|
if content.config_calibre_dir != to_save["config_calibre_dir"]:
|
||||||
content.config_calibre_dir = to_save["config_calibre_dir"]
|
content.config_calibre_dir = to_save["config_calibre_dir"]
|
||||||
@ -2393,6 +2436,9 @@ def configuration_helper(origin):
|
|||||||
if "config_goodreads_api_secret" in to_save:
|
if "config_goodreads_api_secret" in to_save:
|
||||||
content.config_goodreads_api_secret = to_save["config_goodreads_api_secret"]
|
content.config_goodreads_api_secret = to_save["config_goodreads_api_secret"]
|
||||||
|
|
||||||
|
# Mature Content configuration
|
||||||
|
if "config_mature_content_tags" in to_save:
|
||||||
|
content.config_mature_content_tags = to_save["config_mature_content_tags"].strip()
|
||||||
|
|
||||||
content.config_default_role = 0
|
content.config_default_role = 0
|
||||||
if "admin_role" in to_save:
|
if "admin_role" in to_save:
|
||||||
@ -2470,6 +2516,7 @@ def new_user():
|
|||||||
content.nickname = to_save["nickname"]
|
content.nickname = to_save["nickname"]
|
||||||
content.email = to_save["email"]
|
content.email = to_save["email"]
|
||||||
content.default_language = to_save["default_language"]
|
content.default_language = to_save["default_language"]
|
||||||
|
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
|
content.sidebar_view = 0
|
||||||
@ -2557,7 +2604,7 @@ def edit_mailsettings():
|
|||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def edit_user(user_id):
|
def edit_user(user_id):
|
||||||
content = ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first()
|
content = ub.session.query(ub.User).filter(ub.User.id == int(user_id)).first() # type: ub.User
|
||||||
downloads = list()
|
downloads = list()
|
||||||
languages = db.session.query(db.Languages).all()
|
languages = db.session.query(db.Languages).all()
|
||||||
for lang in languages:
|
for lang in languages:
|
||||||
@ -2665,6 +2712,8 @@ def edit_user(user_id):
|
|||||||
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
|
||||||
|
|
||||||
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"]
|
||||||
if "locale" in to_save and to_save["locale"]:
|
if "locale" in to_save and to_save["locale"]:
|
||||||
@ -2695,7 +2744,10 @@ def edit_book(book_id):
|
|||||||
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
lang_filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
|
||||||
else:
|
else:
|
||||||
lang_filter = True
|
lang_filter = True
|
||||||
book = db.session.query(db.Books).filter(db.Books.id == book_id).filter(lang_filter).first()
|
content_rating_filter = false() if current_user.mature_content else \
|
||||||
|
db.Books.tags.any(db.Tags.name.in_(config.mature_content_tags()))
|
||||||
|
book = db.session.query(db.Books)\
|
||||||
|
.filter(db.Books.id == book_id).filter(lang_filter).filter(~content_rating_filter).first()
|
||||||
author_names = []
|
author_names = []
|
||||||
|
|
||||||
# Book not found
|
# Book not found
|
||||||
|
Loading…
Reference in New Issue
Block a user