from catalogue.forms import BookImportForm
from catalogue.models import Book, Tag, BookMedia, Fragment, Collection
from catalogue.models.tag import prefetch_relations
-from catalogue.utils import is_subscribed
-from librarian.cover import WLCover
+from paypal.rest import user_is_subscribed
from picture.models import Picture
from picture.forms import PictureImportForm
from social.utils import likes
API_BASE = WL_BASE = MEDIA_BASE = lazy(
lambda: u'https://' + Site.objects.get_current().domain, unicode)()
-SORT_KEY_SEP = ','
-
category_singular = {
'authors': 'author',
'kinds': 'kind',
def process(category, slug):
if category == 'book':
+ # FIXME: Unused?
try:
books.append(Book.objects.get(slug=slug))
except Book.DoesNotExist:
@classmethod
def href(cls, book):
""" Returns an URI for a Book in the API. """
- return API_BASE + reverse("api_book", args=[book.slug])
+ return API_BASE + reverse("catalogue_api_book", args=[book.slug])
@classmethod
def url(cls, book):
def simple_cover(cls, book):
return MEDIA_BASE + book.simple_cover.url if book.simple_cover else ''
- @classmethod
- def cover_color(cls, book):
- return WLCover.epoch_colors.get(book.extra_info.get('epoch'), '#000000')
-
- @classmethod
- def full_sort_key(cls, book):
- return '%s%s%s%s%s' % (book.sort_key_author, SORT_KEY_SEP, book.sort_key, SORT_KEY_SEP, book.id)
-
@staticmethod
def books_after(books, after, new_api):
if not new_api:
return books.filter(slug__gt=after)
try:
- author, title, book_id = after.split(SORT_KEY_SEP)
+ author, title, book_id = after.split(Book.SORT_KEY_SEP)
except ValueError:
- return []
+ return Book.objects.none()
return books.filter(Q(sort_key_author__gt=author)
| (Q(sort_key_author=author) & Q(sort_key__gt=title))
| (Q(sort_key_author=author) & Q(sort_key=title) & Q(id__gt=int(book_id))))
model = Book
fields = book_list_fields
+ # FIXME: Unused?
@classmethod
def genres(cls, book):
""" Returns all media for a book. """
are returned.
"""
if pk is not None:
+ # FIXME: Unused?
try:
return Book.objects.get(pk=pk)
except Book.DoesNotExist:
class EpubHandler(BookDetailHandler):
def read(self, request, slug):
- if not is_subscribed(request.user):
+ if not user_is_subscribed(request.user):
return rc.FORBIDDEN
try:
book = Book.objects.get(slug=slug)
return None
def read(self, request):
+ key_sep = '$'
search_string = request.GET.get('search')
is_lektura = self.parse_bool(request.GET.get('lektura'))
is_audiobook = self.parse_bool(request.GET.get('audiobook'))
preview = self.parse_bool(request.GET.get('preview'))
new_api = request.GET.get('new_api')
- if new_api:
- key_sep = ','
- else:
- key_sep = '$'
after = request.GET.get('after')
count = int(request.GET.get('count', 50))
books = self.order_books(Book.objects.distinct(), new_api)
remaining_count = count - len(filtered_books)
new_books = [
BookProxy(book, '%s%s%s' % (
- label, key_sep, book.slug if not new_api else self.full_sort_key(book)))
+ label, key_sep, book.slug if not new_api else book.full_sort_key()))
for book in book_list[:remaining_count]]
filtered_books += new_books
if len(filtered_books) == count:
add_file_getters()
-class CollectionDetails(object):
- """Custom Collection fields."""
-
- @classmethod
- def href(cls, collection):
- """ Returns URI in the API for the collection. """
-
- return API_BASE + reverse("api_collection", args=[collection.slug])
-
- @classmethod
- def url(cls, collection):
- """ Returns URL on the site. """
-
- return WL_BASE + collection.get_absolute_url()
-
- @classmethod
- def books(cls, collection):
- return Book.objects.filter(collection.get_query())
-
-
-class CollectionDetailHandler(BaseHandler, CollectionDetails):
- allowed_methods = ('GET',)
- fields = ['url', 'title', 'description', 'books']
-
- @piwik_track
- def read(self, request, slug):
- """ Returns details of a collection, identified by slug. """
- try:
- return Collection.objects.get(slug=slug)
- except Collection.DoesNotExist:
- return rc.NOT_FOUND
-
-
-class CollectionsHandler(BaseHandler, CollectionDetails):
- allowed_methods = ('GET',)
- model = Collection
- fields = ['url', 'href', 'title']
-
- @piwik_track
- def read(self, request):
- """ Returns all collections. """
- return Collection.objects.all()
-
-
class TagDetails(object):
"""Custom Tag fields."""
def read(self, request, category=None, pk=None):
""" Lists all tags in the category (eg. all themes). """
if pk is not None:
+ # FIXME: Unused?
try:
return Tag.objects.exclude(category='set').get(pk=pk)
except Book.DoesNotExist:
if not request.user.is_authenticated():
return rc.FORBIDDEN
if slug is None:
- return {'username': request.user.username, 'premium': is_subscribed(request.user)}
+ return {'username': request.user.username, 'premium': user_is_subscribed(request.user)}
try:
book = Book.objects.get(slug=slug)
except Book.DoesNotExist:
class UserShelfHandler(BookDetailHandler):
fields = book_list_fields + ['liked']
+ # FIXME: Unused?
def parse_bool(self, s):
if s in ('true', 'false'):
return s == 'true'