Merge branch 'master' into Develop

This commit is contained in:
Ozzie Isaacs
2026-04-03 09:09:43 +02:00
11 changed files with 35 additions and 15 deletions

View File

@@ -35,7 +35,7 @@ def clean_string(unsafe_text, book_id=0):
try:
if bleach:
allowed_tags = list(ALLOWED_TAGS)
allowed_tags.extend(["p", "span", "div", "pre", "br", "h1", "h2", "h3", "h4", "h5", "h6"])
allowed_tags.extend(["p", "span", "div", "pre", "br", "h1", "h2", "h3", "h4", "h5", "h6", "img"])
safe_text = clean_html(unsafe_text, tags=set(allowed_tags))
else:
safe_text = clean_html(unsafe_text)

View File

@@ -944,16 +944,13 @@ class CalibreDB:
def get_typeahead(self, database, query, replace=('', ''), tag_filter=true()):
query = query or ''
self.create_functions()
# self.session.connection().connection.connection.create_function("lower", 1, lcase)
entries = self.session.query(database).filter(tag_filter). \
filter(func.lower(database.name).ilike("%" + query + "%")).all()
# json_dumps = json.dumps([dict(name=escape(r.name.replace(*replace))) for r in entries])
json_dumps = json.dumps([dict(name=r.name.replace(*replace)) for r in entries])
return json_dumps
def check_exists_book(self, authr, title):
self.create_functions()
# self.session.connection().connection.connection.create_function("lower", 1, lcase)
q = list()
author_terms = re.split(r'\s*&\s*', authr)
for author_term in author_terms:
@@ -1111,7 +1108,7 @@ class CalibreDB:
.group_by(text('books_languages_link.lang_code')).all()
tags = list()
for lang in languages:
tag = Category(isoLanguages.get_language_name(get_locale(), lang[0].lang_code), lang[0].lang_code)
tag = Category(isoLanguages.get_language_name(get_locale(), None, lang[0].lang_code), lang[0].lang_code)
tags.append([tag, lang[1]])
# Append all books without language to list
if not return_all_languages:
@@ -1121,7 +1118,7 @@ class CalibreDB:
.filter(self.common_filters())
.count())
if no_lang_count:
tags.append([Category(_("None"), "none"), no_lang_count])
tags.append([Category(_("None"), None, "none"), no_lang_count])
return sorted(tags, key=lambda x: x[0].name.lower(), reverse=reverse_order)
else:
if not languages:
@@ -1175,14 +1172,25 @@ def lcase(s):
return s.lower()
def title_sort(title, config):
# calibre sort stuff
title_pat = re.compile(config.config_title_regex, re.IGNORECASE)
match = title_pat.search(title)
if match:
prep = match.group(1)
title = title[len(prep):] + ', ' + prep
return strip_whitespaces(title)
class Category:
name = None
sort = None
id = None
count = None
rating = None
def __init__(self, name, cat_id, rating=None):
self.name = name
self.sort = name
self.id = cat_id
self.rating = rating
self.count = 1

View File

@@ -1611,7 +1611,7 @@ def add_objects(db_book_object, db_object, db_session, db_type, add_elements):
if db_type == 'author':
new_element = db_object(add_element, helper.get_sorted_author(add_element.replace('|', ',')))
elif db_type == 'series':
new_element = db_object(add_element, add_element)
new_element = db_object(add_element, db.title_sort(add_element, config))
elif db_type == 'custom':
new_element = db_object(value=add_element)
elif db_type == 'publisher':
@@ -1642,7 +1642,7 @@ def create_objects_for_addition(db_element, add_element, db_type):
elif db_type == 'series':
if db_element.name != add_element:
db_element.name = add_element
db_element.sort = add_element
db_element.sort = db.title_sort(add_element, config)
elif db_type == 'author':
if db_element.name != add_element:
db_element.name = add_element

View File

@@ -1091,8 +1091,13 @@ def get_download_link(book_id, book_format, client):
file_name = book.title
if len(book.authors) > 0:
file_name = file_name + ' - ' + book.authors[0].name
original_name = file_name
file_name = get_valid_filename(file_name, replace_whitespace=False, force_unidecode=True)
quoted_file_name = file_name if client == "kindle" else quote(file_name)
if client == "kindle":
quoted_file_name = file_name
else:
native_name = get_valid_filename(original_name, replace_whitespace=False, force_unidecode=False)
quoted_file_name = quote(native_name)
headers = Headers()
headers["Content-Type"] = mimetypes.types_map.get('.' + book_format, "application/octet-stream")
headers["Content-Disposition"] = ('attachment; filename="{}.{}"; filename*=UTF-8\'\'{}.{}').format(

View File

@@ -30,6 +30,7 @@ from uuid import uuid4
from flask import Blueprint, request, url_for, g
from flask_babel import format_date
from .cw_login import current_user
from .clean_html import clean_string as html_clean_string
from . import constants, logger
@@ -181,3 +182,9 @@ def contains_music(book_formats):
if format.format.lower() in g.constants.EXTENSIONS_AUDIO:
result = True
return result
@jinjia.app_template_filter('clean_string')
def clean_string(unsafe_text):
return html_clean_string(unsafe_text)

View File

@@ -811,6 +811,8 @@ def HandleStateRequest(book_uuid):
ub.session.merge(kobo_reading_state)
ub.session_commit()
update_results_response["LastModified"] = convert_to_kobo_timestamp_string(kobo_reading_state.last_modified)
update_results_response["PriorityTimestamp"] = convert_to_kobo_timestamp_string(kobo_reading_state.priority_timestamp)
return jsonify({
"RequestResult": "Success",
"UpdateResults": [update_results_response],

View File

@@ -258,7 +258,6 @@ def render_adv_search_results(term, offset=None, order=None, limit=None):
cc = calibre_db.get_cc_columns(config, filter_config_custom_read=True)
calibre_db.create_functions()
# calibre_db.session.connection().connection.connection.create_function("lower", 1, db.lcase)
query = calibre_db.generate_linked_query(config.config_read_column, db.Books)
q = query.outerjoin(db.books_series_link, db.Books.id == db.books_series_link.c.book)\
.outerjoin(db.Series)\

View File

@@ -74,7 +74,7 @@
{% if entry.comments|length > 0 and entry.comments[0].text|length > 0 %}
<div>
<h2 id="decription">{{ _('Description:') }}</h2>
{{ entry.comments[0].text|safe }}
{{ entry.comments[0].text|clean_string|safe }}
</div>
{% endif %}
</div>

View File

@@ -284,7 +284,7 @@
{% if entry.comments|length > 0 and entry.comments[0].text|length > 0 %}
<div class="comments">
<h3 id="decription">{{ _('Description:') }}</h3>
{{ entry.comments[0].text|safe }}
{{ entry.comments[0].text|clean_string|safe }}
</div>
{% endif %}

View File

@@ -175,7 +175,7 @@
{% if entry.comments|length > 0 and entry.comments[0].text|length > 0%}
<div class="comments">
<h3 id="decription">{{_('Description:')}}</h3>
{{entry.comments[0].text|safe}}
{{entry.comments[0].text|clean_string|safe}}
</div>
{% endif %}

View File

@@ -301,7 +301,6 @@ def get_matching_tags():
tag_dict = {'tags': []}
q = calibre_db.session.query(db.Books).filter(calibre_db.common_filters(True))
calibre_db.create_functions()
# calibre_db.session.connection().connection.connection.create_function("lower", 1, db.lcase)
author_input = request.args.get('authors') or ''
title_input = request.args.get('title') or ''
include_tag_inputs = request.args.getlist('include_tag') or ''
@@ -1026,7 +1025,7 @@ def series_list():
.count())
if no_series_count:
entries.append([db.Category(_("None"), "-1"), no_series_count])
entries = sorted(entries, key=lambda x: x[0].name.lower(), reverse=not order_no)
entries = sorted(entries, key=lambda x: (x[0].sort or x[0].name).lower(), reverse=not order_no)
return render_title_template('list.html',
entries=entries,
folder='web.books_list',