|
|
|
@ -20,7 +20,6 @@
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import json
|
|
|
|
|
import traceback
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from urllib.parse import quote
|
|
|
|
|
import unidecode
|
|
|
|
@ -33,7 +32,6 @@ from sqlalchemy.orm import relationship, sessionmaker, scoped_session
|
|
|
|
|
from sqlalchemy.orm.collections import InstrumentedList
|
|
|
|
|
from sqlalchemy.ext.declarative import DeclarativeMeta
|
|
|
|
|
from sqlalchemy.exc import OperationalError
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# Compatibility with sqlalchemy 2.0
|
|
|
|
|
from sqlalchemy.orm import declarative_base
|
|
|
|
@ -42,7 +40,6 @@ except ImportError:
|
|
|
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
|
from sqlalchemy.sql.expression import and_, true, false, text, func, or_
|
|
|
|
|
from sqlalchemy.ext.associationproxy import association_proxy
|
|
|
|
|
from sqlalchemy import desc
|
|
|
|
|
from flask_login import current_user
|
|
|
|
|
from flask_babel import gettext as _
|
|
|
|
|
from flask_babel import get_locale
|
|
|
|
@ -52,7 +49,7 @@ from . import logger, ub, isoLanguages
|
|
|
|
|
from .pagination import Pagination
|
|
|
|
|
|
|
|
|
|
from weakref import WeakSet
|
|
|
|
|
from thefuzz.fuzz import partial_ratio, partial_token_set_ratio, partial_token_sort_ratio, ratio
|
|
|
|
|
from thefuzz.fuzz import partial_token_sort_ratio, ratio
|
|
|
|
|
|
|
|
|
|
# %-level, 100 means exact match, 75 allows exactly 1 wrong character in a 4 letter word
|
|
|
|
|
FUZZY_SEARCH_ACCURACY = 75
|
|
|
|
@ -441,13 +438,11 @@ class CustomColumns(Base):
|
|
|
|
|
content['is_editable'] = self.editable
|
|
|
|
|
content['rec_index'] = sequence + 22 # toDo why ??
|
|
|
|
|
if isinstance(value, datetime):
|
|
|
|
|
content['#value#'] = {"__class__": "datetime.datetime",
|
|
|
|
|
"__value__": value.strftime("%Y-%m-%dT%H:%M:%S+00:00")}
|
|
|
|
|
content['#value#'] = {"__class__": "datetime.datetime", "__value__": value.strftime("%Y-%m-%dT%H:%M:%S+00:00")}
|
|
|
|
|
else:
|
|
|
|
|
content['#value#'] = value
|
|
|
|
|
content['#extra#'] = extra
|
|
|
|
|
content['is_multiple2'] = {} if not self.is_multiple else {"cache_to_list": "|", "ui_to_list": ",",
|
|
|
|
|
"list_to_ui": ", "}
|
|
|
|
|
content['is_multiple2'] = {} if not self.is_multiple else {"cache_to_list": "|", "ui_to_list": ",", "list_to_ui": ", "}
|
|
|
|
|
return json.dumps(content, ensure_ascii=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -507,6 +502,7 @@ class CalibreDB:
|
|
|
|
|
if init:
|
|
|
|
|
self.init_db(expire_on_commit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_db(self, expire_on_commit=True):
|
|
|
|
|
if self._init:
|
|
|
|
|
self.init_session(expire_on_commit)
|
|
|
|
@ -821,18 +817,18 @@ class CalibreDB:
|
|
|
|
|
element = 0
|
|
|
|
|
while indx:
|
|
|
|
|
if indx >= 3:
|
|
|
|
|
query = query.outerjoin(join[element], join[element + 1]).outerjoin(join[element + 2])
|
|
|
|
|
query = query.outerjoin(join[element], join[element+1]).outerjoin(join[element+2])
|
|
|
|
|
indx -= 3
|
|
|
|
|
element += 3
|
|
|
|
|
elif indx == 2:
|
|
|
|
|
query = query.outerjoin(join[element], join[element + 1])
|
|
|
|
|
query = query.outerjoin(join[element], join[element+1])
|
|
|
|
|
indx -= 2
|
|
|
|
|
element += 2
|
|
|
|
|
elif indx == 1:
|
|
|
|
|
query = query.outerjoin(join[element])
|
|
|
|
|
indx -= 1
|
|
|
|
|
element += 1
|
|
|
|
|
query = query.filter(db_filter) \
|
|
|
|
|
query = query.filter(db_filter)\
|
|
|
|
|
.filter(self.common_filters(allow_show_archived))
|
|
|
|
|
entries = list()
|
|
|
|
|
pagination = list()
|
|
|
|
@ -1008,8 +1004,8 @@ class CalibreDB:
|
|
|
|
|
return sorted(tags, key=lambda x: x[0].name.lower(), reverse=reverse_order)
|
|
|
|
|
else:
|
|
|
|
|
if not languages:
|
|
|
|
|
languages = self.session.query(Languages) \
|
|
|
|
|
.join(books_languages_link) \
|
|
|
|
|
languages = self.session.query(Languages)\
|
|
|
|
|
.join(books_languages_link)\
|
|
|
|
|
.join(Books) \
|
|
|
|
|
.filter(self.common_filters(return_all_languages=return_all_languages)) \
|
|
|
|
|
.group_by(text('books_languages_link.lang_code')).all()
|
|
|
|
@ -1104,7 +1100,6 @@ class Category:
|
|
|
|
|
self.rating = rating
|
|
|
|
|
self.count = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'''class Count:
|
|
|
|
|
count = None
|
|
|
|
|
|
|
|
|
|