40
cps/db.py
40
cps/db.py
@@ -104,6 +104,7 @@ class Identifiers(Base):
|
||||
book = Column(Integer, ForeignKey('books.id'), nullable=False)
|
||||
|
||||
def __init__(self, val, id_type, book):
|
||||
super().__init__()
|
||||
self.val = val
|
||||
self.type = id_type
|
||||
self.book = book
|
||||
@@ -178,7 +179,7 @@ class Identifiers(Base):
|
||||
elif self.val.lower().startswith("javascript:"):
|
||||
return quote(self.val)
|
||||
elif self.val.lower().startswith("data:"):
|
||||
link , __, __ = str.partition(self.val, ",")
|
||||
link, __, __ = str.partition(self.val, ",")
|
||||
return link
|
||||
else:
|
||||
return "{0}".format(self.val)
|
||||
@@ -192,6 +193,7 @@ class Comments(Base):
|
||||
text = Column(String(collation='NOCASE'), nullable=False)
|
||||
|
||||
def __init__(self, comment, book):
|
||||
super().__init__()
|
||||
self.text = comment
|
||||
self.book = book
|
||||
|
||||
@@ -209,6 +211,7 @@ class Tags(Base):
|
||||
name = Column(String(collation='NOCASE'), unique=True, nullable=False)
|
||||
|
||||
def __init__(self, name):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
|
||||
def get(self):
|
||||
@@ -230,6 +233,7 @@ class Authors(Base):
|
||||
link = Column(String, nullable=False, default="")
|
||||
|
||||
def __init__(self, name, sort, link=""):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.sort = sort
|
||||
self.link = link
|
||||
@@ -252,6 +256,7 @@ class Series(Base):
|
||||
sort = Column(String(collation='NOCASE'))
|
||||
|
||||
def __init__(self, name, sort):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.sort = sort
|
||||
|
||||
@@ -272,6 +277,7 @@ class Ratings(Base):
|
||||
rating = Column(Integer, CheckConstraint('rating>-1 AND rating<11'), unique=True)
|
||||
|
||||
def __init__(self, rating):
|
||||
super().__init__()
|
||||
self.rating = rating
|
||||
|
||||
def get(self):
|
||||
@@ -291,6 +297,7 @@ class Languages(Base):
|
||||
lang_code = Column(String(collation='NOCASE'), nullable=False, unique=True)
|
||||
|
||||
def __init__(self, lang_code):
|
||||
super().__init__()
|
||||
self.lang_code = lang_code
|
||||
|
||||
def get(self):
|
||||
@@ -314,6 +321,7 @@ class Publishers(Base):
|
||||
sort = Column(String(collation='NOCASE'))
|
||||
|
||||
def __init__(self, name, sort):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.sort = sort
|
||||
|
||||
@@ -338,6 +346,7 @@ class Data(Base):
|
||||
name = Column(String, nullable=False)
|
||||
|
||||
def __init__(self, book, book_format, uncompressed_size, name):
|
||||
super().__init__()
|
||||
self.book = book
|
||||
self.format = book_format
|
||||
self.uncompressed_size = uncompressed_size
|
||||
@@ -357,6 +366,7 @@ class Metadata_Dirtied(Base):
|
||||
book = Column(Integer, ForeignKey('books.id'), nullable=False, unique=True)
|
||||
|
||||
def __init__(self, book):
|
||||
super().__init__()
|
||||
self.book = book
|
||||
|
||||
|
||||
@@ -391,6 +401,7 @@ class Books(Base):
|
||||
|
||||
def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover,
|
||||
authors, tags, languages=None):
|
||||
super().__init__()
|
||||
self.title = title
|
||||
self.sort = sort
|
||||
self.author_sort = author_sort
|
||||
@@ -399,12 +410,12 @@ class Books(Base):
|
||||
self.series_index = series_index
|
||||
self.last_modified = last_modified
|
||||
self.path = path
|
||||
self.has_cover = (has_cover != None)
|
||||
self.has_cover = (has_cover is not None)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Books('{0},{1}{2}{3}{4}{5}{6}{7}{8}')>".format(self.title, self.sort, self.author_sort,
|
||||
self.timestamp, self.pubdate, self.series_index,
|
||||
self.last_modified, self.path, self.has_cover)
|
||||
self.timestamp, self.pubdate, self.series_index,
|
||||
self.last_modified, self.path, self.has_cover)
|
||||
|
||||
@property
|
||||
def atom_timestamp(self):
|
||||
@@ -448,11 +459,13 @@ 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)
|
||||
|
||||
|
||||
@@ -512,7 +525,6 @@ 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)
|
||||
@@ -722,8 +734,8 @@ class CalibreDB:
|
||||
def common_filters(self, allow_show_archived=False, return_all_languages=False):
|
||||
if not allow_show_archived:
|
||||
archived_books = (ub.session.query(ub.ArchivedBook)
|
||||
.filter(ub.ArchivedBook.user_id == int(current_user.id))
|
||||
.filter(ub.ArchivedBook.is_archived == True)
|
||||
.filter(ub.ArchivedBook.user_id==int(current_user.id))
|
||||
.filter(ub.ArchivedBook.is_archived==True)
|
||||
.all())
|
||||
archived_book_ids = [archived_book.book_id for archived_book in archived_books]
|
||||
archived_filter = Books.id.notin_(archived_book_ids)
|
||||
@@ -959,7 +971,7 @@ class CalibreDB:
|
||||
pagination = None
|
||||
result = self.search_query(term, config, *join).order_by(*order).all()
|
||||
result_count = len(result)
|
||||
if offset != None and limit != None:
|
||||
if offset is not None and limit is not None:
|
||||
offset = int(offset)
|
||||
limit_all = offset + int(limit)
|
||||
pagination = Pagination((offset / (int(limit)) + 1), limit, result_count)
|
||||
@@ -989,7 +1001,7 @@ class CalibreDB:
|
||||
if not return_all_languages:
|
||||
no_lang_count = (self.session.query(Books)
|
||||
.outerjoin(books_languages_link).outerjoin(Languages)
|
||||
.filter(Languages.lang_code == None)
|
||||
.filter(Languages.lang_code==None)
|
||||
.filter(self.common_filters())
|
||||
.count())
|
||||
if no_lang_count:
|
||||
@@ -1087,9 +1099,3 @@ class Category:
|
||||
self.id = cat_id
|
||||
self.rating = rating
|
||||
self.count = 1
|
||||
|
||||
'''class Count:
|
||||
count = None
|
||||
|
||||
def __init__(self, count):
|
||||
self.count = count'''
|
||||
|
||||
Reference in New Issue
Block a user