Make verse numbers, footnote anchors, themes, dynamic inserts unselectable. Fixes...
[wolnelektury.git] / src / catalogue / api / helpers.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django.db.models import Q
5 from catalogue.models import Book
6
7
8 def books_after(books, after, new_api):
9     if not new_api:
10         return books.filter(slug__gt=after)
11     try:
12         author, title, book_id = after.split(Book.SORT_KEY_SEP)
13     except ValueError:
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))))
18
19
20 def order_books(books, new_api):
21     if new_api:
22         return books.order_by('sort_key_author', 'sort_key', 'id')
23     return books.order_by('slug')