mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 12:30:00 +00:00
Archived Flag available in book list array
This commit is contained in:
parent
bb20979c71
commit
4c7b5999f7
64
cps/db.py
64
cps/db.py
@ -685,8 +685,11 @@ class CalibreDB():
|
|||||||
pos_content_cc_filter, ~neg_content_cc_filter, archived_filter)
|
pos_content_cc_filter, ~neg_content_cc_filter, archived_filter)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_checkbox_sorted(inputlist, state, offset, limit, order):
|
def get_checkbox_sorted(inputlist, state, offset, limit, order, combo=False):
|
||||||
outcome = list()
|
outcome = list()
|
||||||
|
if combo:
|
||||||
|
elementlist = {ele[0].id: ele for ele in inputlist}
|
||||||
|
else:
|
||||||
elementlist = {ele.id: ele for ele in inputlist}
|
elementlist = {ele.id: ele for ele in inputlist}
|
||||||
for entry in state:
|
for entry in state:
|
||||||
try:
|
try:
|
||||||
@ -702,10 +705,10 @@ class CalibreDB():
|
|||||||
|
|
||||||
# Fill indexpage with all requested data from database
|
# Fill indexpage with all requested data from database
|
||||||
def fill_indexpage(self, page, pagesize, database, db_filter, order, *join):
|
def fill_indexpage(self, page, pagesize, database, db_filter, order, *join):
|
||||||
return self.fill_indexpage_with_archived_books(page, pagesize, database, db_filter, order, False, *join)
|
return self.fill_indexpage_with_archived_books(page, pagesize, db_filter, order, False, database, join)
|
||||||
|
|
||||||
def fill_indexpage_with_archived_books(self, page, pagesize, database, db_filter, order, allow_show_archived,
|
def fill_indexpage_with_archived_books(self, page, pagesize, db_filter, order, allow_show_archived,
|
||||||
*join):
|
*args):
|
||||||
pagesize = pagesize or self.config.config_books_per_page
|
pagesize = pagesize or self.config.config_books_per_page
|
||||||
if current_user.show_detail_random():
|
if current_user.show_detail_random():
|
||||||
randm = self.session.query(Books) \
|
randm = self.session.query(Books) \
|
||||||
@ -714,20 +717,32 @@ class CalibreDB():
|
|||||||
.limit(self.config.config_random_books).all()
|
.limit(self.config.config_random_books).all()
|
||||||
else:
|
else:
|
||||||
randm = false()
|
randm = false()
|
||||||
|
if len(args) > 1:
|
||||||
|
if isinstance(args[0], DeclarativeMeta):
|
||||||
|
query = self.session.query(args[0])
|
||||||
|
else:
|
||||||
|
query = self.session.query(*args[0])
|
||||||
|
join = args[1]
|
||||||
|
else:
|
||||||
|
join = tuple()
|
||||||
|
query = self.session.query(args)
|
||||||
off = int(int(pagesize) * (page - 1))
|
off = int(int(pagesize) * (page - 1))
|
||||||
query = self.session.query(database)
|
|
||||||
if len(join) == 6:
|
indx = len(join)
|
||||||
query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4]).outerjoin(join[5])
|
element = 0
|
||||||
if len(join) == 5:
|
while indx:
|
||||||
query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4])
|
if indx >= 3:
|
||||||
if len(join) == 4:
|
query = query.outerjoin(join[element], join[element+1]).outerjoin(join[element+2])
|
||||||
query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3])
|
indx -= 3
|
||||||
if len(join) == 3:
|
element += 3
|
||||||
query = query.outerjoin(join[0], join[1]).outerjoin(join[2])
|
elif indx == 2:
|
||||||
elif len(join) == 2:
|
query = query.outerjoin(join[element], join[element+1])
|
||||||
query = query.outerjoin(join[0], join[1])
|
indx -= 2
|
||||||
elif len(join) == 1:
|
element += 2
|
||||||
query = query.outerjoin(join[0])
|
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))
|
.filter(self.common_filters(allow_show_archived))
|
||||||
entries = list()
|
entries = list()
|
||||||
@ -785,7 +800,9 @@ class CalibreDB():
|
|||||||
authorterms = re.split("[, ]+", term)
|
authorterms = re.split("[, ]+", term)
|
||||||
for authorterm in authorterms:
|
for authorterm in authorterms:
|
||||||
q.append(Books.authors.any(func.lower(Authors.name).ilike("%" + authorterm + "%")))
|
q.append(Books.authors.any(func.lower(Authors.name).ilike("%" + authorterm + "%")))
|
||||||
query = self.session.query(Books)
|
query = (self.session.query(Books, ub.ArchivedBook.is_archived)
|
||||||
|
.outerjoin(ub.ArchivedBook, and_(Books.id == ub.ArchivedBook.book_id,
|
||||||
|
int(current_user.id) == ub.ArchivedBook.user_id)))
|
||||||
if len(join) == 6:
|
if len(join) == 6:
|
||||||
query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4]).outerjoin(join[5])
|
query = query.outerjoin(join[0], join[1]).outerjoin(join[2]).outerjoin(join[3], join[4]).outerjoin(join[5])
|
||||||
if len(join) == 3:
|
if len(join) == 3:
|
||||||
@ -816,7 +833,7 @@ class CalibreDB():
|
|||||||
offset = 0
|
offset = 0
|
||||||
limit_all = result_count
|
limit_all = result_count
|
||||||
|
|
||||||
ub.store_ids(result)
|
ub.store_combo_ids(result)
|
||||||
return result[offset:limit_all], result_count, pagination
|
return result[offset:limit_all], result_count, pagination
|
||||||
|
|
||||||
# Creates for all stored languages a translated speaking name in the array for the UI
|
# Creates for all stored languages a translated speaking name in the array for the UI
|
||||||
@ -831,15 +848,6 @@ class CalibreDB():
|
|||||||
.group_by(text('books_languages_link.lang_code')).all()
|
.group_by(text('books_languages_link.lang_code')).all()
|
||||||
for lang in languages:
|
for lang in languages:
|
||||||
lang.name = isoLanguages.get_language_name(get_locale(), lang.lang_code)
|
lang.name = isoLanguages.get_language_name(get_locale(), lang.lang_code)
|
||||||
#try:
|
|
||||||
# if lang.lang_code.lower() == "und":
|
|
||||||
# lang.name = isoLanguages.get_language_name(get_locale(), lang.lang_code)
|
|
||||||
# # lang.name = _("Undetermined")
|
|
||||||
# else:
|
|
||||||
# cur_l = LC.parse(lang.lang_code)
|
|
||||||
# lang.name = cur_l.get_language_name(get_locale())
|
|
||||||
#except UnknownLocaleError:
|
|
||||||
# lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
|
||||||
return languages
|
return languages
|
||||||
|
|
||||||
def update_title_sort(self, config, conn=None):
|
def update_title_sort(self, config, conn=None):
|
||||||
|
@ -126,6 +126,12 @@ def store_ids(result):
|
|||||||
ids.append(element.id)
|
ids.append(element.id)
|
||||||
searched_ids[current_user.id] = ids
|
searched_ids[current_user.id] = ids
|
||||||
|
|
||||||
|
def store_combo_ids(result):
|
||||||
|
ids = list()
|
||||||
|
for element in result:
|
||||||
|
ids.append(element[0].id)
|
||||||
|
searched_ids[current_user.id] = ids
|
||||||
|
|
||||||
|
|
||||||
class UserBase:
|
class UserBase:
|
||||||
|
|
||||||
|
43
cps/web.py
43
cps/web.py
@ -677,10 +677,10 @@ def render_archived_books(page, order):
|
|||||||
archived_filter = db.Books.id.in_(archived_book_ids)
|
archived_filter = db.Books.id.in_(archived_book_ids)
|
||||||
|
|
||||||
entries, random, pagination = calibre_db.fill_indexpage_with_archived_books(page, 0,
|
entries, random, pagination = calibre_db.fill_indexpage_with_archived_books(page, 0,
|
||||||
db.Books,
|
|
||||||
archived_filter,
|
archived_filter,
|
||||||
order,
|
order,
|
||||||
allow_show_archived=True)
|
True,
|
||||||
|
db.Books)
|
||||||
|
|
||||||
name = _(u'Archived Books') + ' (' + str(len(archived_book_ids)) + ')'
|
name = _(u'Archived Books') + ' (' + str(len(archived_book_ids)) + ')'
|
||||||
pagename = "archived"
|
pagename = "archived"
|
||||||
@ -770,20 +770,19 @@ def list_books():
|
|||||||
sort = request.args.get("sort", "id")
|
sort = request.args.get("sort", "id")
|
||||||
order = request.args.get("order", "").lower()
|
order = request.args.get("order", "").lower()
|
||||||
state = None
|
state = None
|
||||||
join = tuple()
|
join = list()
|
||||||
|
|
||||||
if sort == "state":
|
if sort == "state":
|
||||||
state = json.loads(request.args.get("state", "[]"))
|
state = json.loads(request.args.get("state", "[]"))
|
||||||
# order = [db.Books.timestamp.asc()] if order == "asc" else [db.Books.timestamp.desc()] # ToDo wrong: sort ticked
|
|
||||||
elif sort == "tags":
|
elif sort == "tags":
|
||||||
order = [db.Tags.name.asc()] if order == "asc" else [db.Tags.name.desc()]
|
order = [db.Tags.name.asc()] if order == "asc" else [db.Tags.name.desc()]
|
||||||
join = db.books_tags_link,db.Books.id == db.books_tags_link.c.book, db.Tags
|
join = db.books_tags_link, db.Books.id == db.books_tags_link.c.book, db.Tags
|
||||||
elif sort == "series":
|
elif sort == "series":
|
||||||
order = [db.Series.name.asc()] if order == "asc" else [db.Series.name.desc()]
|
order = [db.Series.name.asc()] if order == "asc" else [db.Series.name.desc()]
|
||||||
join = db.books_series_link,db.Books.id == db.books_series_link.c.book, db.Series
|
join = db.books_series_link, db.Books.id == db.books_series_link.c.book, db.Series
|
||||||
elif sort == "publishers":
|
elif sort == "publishers":
|
||||||
order = [db.Publishers.name.asc()] if order == "asc" else [db.Publishers.name.desc()]
|
order = [db.Publishers.name.asc()] if order == "asc" else [db.Publishers.name.desc()]
|
||||||
join = db.books_publishers_link,db.Books.id == db.books_publishers_link.c.book, db.Publishers
|
join = db.books_publishers_link, db.Books.id == db.books_publishers_link.c.book, db.Publishers
|
||||||
elif sort == "authors":
|
elif sort == "authors":
|
||||||
order = [db.Authors.name.asc(), db.Series.name, db.Books.series_index] if order == "asc" \
|
order = [db.Authors.name.asc(), db.Series.name, db.Books.series_index] if order == "asc" \
|
||||||
else [db.Authors.name.desc(), db.Series.name.desc(), db.Books.series_index.desc()]
|
else [db.Authors.name.desc(), db.Series.name.desc(), db.Books.series_index.desc()]
|
||||||
@ -798,24 +797,38 @@ def list_books():
|
|||||||
order = [db.Books.timestamp.desc()]
|
order = [db.Books.timestamp.desc()]
|
||||||
|
|
||||||
total_count = filtered_count = calibre_db.session.query(db.Books).filter(calibre_db.common_filters(False)).count()
|
total_count = filtered_count = calibre_db.session.query(db.Books).filter(calibre_db.common_filters(False)).count()
|
||||||
|
|
||||||
if state is not None:
|
if state is not None:
|
||||||
if search:
|
if search:
|
||||||
books = calibre_db.search_query(search).all()
|
books = calibre_db.search_query(search).all()
|
||||||
filtered_count = len(books)
|
filtered_count = len(books)
|
||||||
else:
|
else:
|
||||||
books = calibre_db.session.query(db.Books).filter(calibre_db.common_filters()).all()
|
books = (calibre_db.session.query(db.Books,ub.ArchivedBook.is_archived)
|
||||||
entries = calibre_db.get_checkbox_sorted(books, state, off, limit, order)
|
.outerjoin(ub.ArchivedBook, and_(db.Books.id == ub.ArchivedBook.book_id,
|
||||||
|
int(current_user.id) == ub.ArchivedBook.user_id))
|
||||||
|
.filter(calibre_db.common_filters()).all())
|
||||||
|
entries = calibre_db.get_checkbox_sorted(books, state, off, limit, order, True)
|
||||||
elif search:
|
elif search:
|
||||||
entries, filtered_count, __ = calibre_db.get_search_results(search, off, order, limit, *join)
|
entries, filtered_count, __ = calibre_db.get_search_results(search, off, order, limit, *tuple(join))
|
||||||
else:
|
else:
|
||||||
entries, __, __ = calibre_db.fill_indexpage((int(off) / (int(limit)) + 1), limit, db.Books, True, order, *join)
|
join.append(ub.ArchivedBook)
|
||||||
|
join.append(and_(db.Books.id == ub.ArchivedBook.book_id,int(current_user.id) == ub.ArchivedBook.user_id))
|
||||||
|
entries, __, __ = calibre_db.fill_indexpage((int(off) / (int(limit)) + 1),
|
||||||
|
limit,
|
||||||
|
(db.Books, ub.ArchivedBook),
|
||||||
|
True,
|
||||||
|
order,
|
||||||
|
*tuple(join))
|
||||||
|
|
||||||
|
result = list()
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
for index in range(0, len(entry.languages)):
|
val = entry[0]
|
||||||
entry.languages[index].language_name = isoLanguages.get_language_name(get_locale(), entry.languages[
|
val.is_archived = entry[1] == True
|
||||||
|
for index in range(0, len(val.languages)):
|
||||||
|
val.languages[index].language_name = isoLanguages.get_language_name(get_locale(), val.languages[
|
||||||
index].lang_code)
|
index].lang_code)
|
||||||
table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": entries}
|
result.append(val)
|
||||||
|
|
||||||
|
table_entries = {'totalNotFiltered': total_count, 'total': filtered_count, "rows": result}
|
||||||
js_list = json.dumps(table_entries, cls=db.AlchemyEncoder)
|
js_list = json.dumps(table_entries, cls=db.AlchemyEncoder)
|
||||||
|
|
||||||
response = make_response(js_list)
|
response = make_response(js_list)
|
||||||
|
Loading…
Reference in New Issue
Block a user