1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.db.models import Q
5 from catalogue.models import Book
8 def books_after(books, after, new_api):
10 return books.filter(slug__gt=after)
12 author, title, book_id = after.split(Book.SORT_KEY_SEP)
14 return Book.objects.none()
15 return books.filter(Q(sort_key_author__gt=author)
16 | (Q(sort_key_author=author) & Q(sort_key__gt=title))
17 | (Q(sort_key_author=author) & Q(sort_key=title) & Q(id__gt=int(book_id))))
20 def order_books(books, new_api):
22 return books.order_by('sort_key_author', 'sort_key', 'id')
23 return books.order_by('slug')