Пример #1
0
 def fill_indexpage_with_archived_books(self, page, pagesize, database,
                                        db_filter, order,
                                        allow_show_archived, *join):
     pagesize = pagesize or self.config.config_books_per_page
     if current_user.show_detail_random():
         randm = self.session.query(Books) \
             .filter(self.common_filters(allow_show_archived)) \
             .order_by(func.random()) \
             .limit(self.config.config_random_books).all()
     else:
         randm = false()
     off = int(int(pagesize) * (page - 1))
     query = self.session.query(database)
     if len(join) == 3:
         query = query.outerjoin(join[0], join[1]).outerjoin(join[2])
     elif len(join) == 2:
         query = query.outerjoin(join[0], join[1])
     elif len(join) == 1:
         query = query.outerjoin(join[0])
     query = query.filter(db_filter)\
         .filter(self.common_filters(allow_show_archived))
     entries = list()
     pagination = list()
     try:
         pagination = Pagination(page, pagesize, len(query.all()))
         entries = query.order_by(*order).offset(off).limit(pagesize).all()
     except Exception as ex:
         log.debug_or_exception(ex)
     #for book in entries:
     #    book = self.order_authors(book)
     return entries, randm, pagination
Пример #2
0
    def fill_indexpage_with_archived_books(self, page, database, pagesize, db_filter, order, allow_show_archived,
                                           join_archive_read, config_read_column, *join):
        pagesize = pagesize or self.config.config_books_per_page
        if current_user.show_detail_random():
            randm = self.session.query(Books) \
                .filter(self.common_filters(allow_show_archived)) \
                .order_by(func.random()) \
                .limit(self.config.config_random_books).all()
        else:
            randm = false()
        if join_archive_read:
            if not config_read_column:
                query = (self.session.query(database, ub.ReadBook.read_status, ub.ArchivedBook.is_archived)
                         .select_from(Books)
                         .outerjoin(ub.ReadBook,
                               and_(ub.ReadBook.user_id == int(current_user.id), ub.ReadBook.book_id == Books.id)))
            else:
                try:
                    read_column = cc_classes[config_read_column]
                    query = (self.session.query(database, read_column.value, ub.ArchivedBook.is_archived)
                             .select_from(Books)
                             .outerjoin(read_column, read_column.book == Books.id))
                except (KeyError, AttributeError):
                    log.error("Custom Column No.%d is not existing in calibre database", read_column)
                    # Skip linking read column and return None instead of read status
                    query =self.session.query(database, None, ub.ArchivedBook.is_archived)
            query = query.outerjoin(ub.ArchivedBook, and_(Books.id == ub.ArchivedBook.book_id,
                                                          int(current_user.id) == ub.ArchivedBook.user_id))
        else:
            query = self.session.query(database)
        off = int(int(pagesize) * (page - 1))

        indx = len(join)
        element = 0
        while indx:
            if indx >= 3:
                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])
                indx -= 2
                element += 2
            elif indx == 1:
                query = query.outerjoin(join[element])
                indx -= 1
                element += 1
        query = query.filter(db_filter)\
            .filter(self.common_filters(allow_show_archived))
        entries = list()
        pagination = list()
        try:
            pagination = Pagination(page, pagesize,
                                    len(query.all()))
            entries = query.order_by(*order).offset(off).limit(pagesize).all()
        except Exception as ex:
            log.debug_or_exception(ex)
        # display authors in right order
        entries = self.order_authors(entries, True, join_archive_read)
        return entries, randm, pagination
Пример #3
0
def fill_indexpage(page, database, db_filter, order, *join):
    if current_user.show_detail_random():
        randm = db.session.query(db.Books).filter(common_filters())\
            .order_by(func.random()).limit(config.config_random_books)
    else:
        randm = false()
    off = int(int(config.config_books_per_page) * (page - 1))
    pagination = Pagination(page, config.config_books_per_page,
                            len(db.session.query(database).filter(db_filter).filter(common_filters()).all()))
    entries = db.session.query(database).join(*join, isouter=True).filter(db_filter).filter(common_filters()).\
        order_by(*order).offset(off).limit(config.config_books_per_page).all()
    for book in entries:
        book = order_authors(book)
    return entries, randm, pagination
Пример #4
0
    def fill_indexpage_with_archived_books(self, page, database, pagesize, db_filter, order, allow_show_archived,
                                           join_archive_read, config_read_column, *join):
        pagesize = pagesize or self.config.config_books_per_page
        if current_user.show_detail_random():
            random_query = self.generate_linked_query(config_read_column, database)
            randm = (random_query.filter(self.common_filters(allow_show_archived))
                     .order_by(func.random())
                     .limit(self.config.config_random_books).all())
        else:
            randm = false()
        if join_archive_read:
            query = self.generate_linked_query(config_read_column, database)
        else:
            query = self.session.query(database)
        off = int(int(pagesize) * (page - 1))

        indx = len(join)
        element = 0
        while indx:
            if indx >= 3:
                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])
                indx -= 2
                element += 2
            elif indx == 1:
                query = query.outerjoin(join[element])
                indx -= 1
                element += 1
        query = query.filter(db_filter)\
            .filter(self.common_filters(allow_show_archived))
        entries = list()
        pagination = list()
        try:
            pagination = Pagination(page, pagesize,
                                    len(query.all()))
            entries = query.order_by(*order).offset(off).limit(pagesize).all()
        except Exception as ex:
            log.error_or_exception(ex)
        # display authors in right order
        entries = self.order_authors(entries, True, join_archive_read)
        return entries, randm, pagination
Пример #5
0
 def fill_indexpage_with_archived_books(self, page, database, db_filter, order, allow_show_archived, *join):
     if current_user.show_detail_random():
         randm = self.session.query(Books) \
             .filter(self.common_filters(allow_show_archived)) \
             .order_by(func.random()) \
             .limit(self.config.config_random_books)
     else:
         randm = false()
     off = int(int(self.config.config_books_per_page) * (page - 1))
     query = self.session.query(database) \
         .join(*join, isouter=True) \
         .filter(db_filter) \
         .filter(self.common_filters(allow_show_archived))
     pagination = Pagination(page, self.config.config_books_per_page,
                             len(query.all()))
     entries = query.order_by(*order).offset(off).limit(self.config.config_books_per_page).all()
     for book in entries:
         book = self.order_authors(book)
     return entries, randm, pagination