You forgot XML.
[wolnelektury.git] / src / api / handlers.py
index 0926991..cd24561 100644 (file)
@@ -19,8 +19,8 @@ from api.models import BookUserData
 from catalogue.forms import BookImportForm
 from catalogue.models import Book, Tag, BookMedia, Fragment, Collection
 from catalogue.models.tag import prefetch_relations
 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 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
 from picture.models import Picture
 from picture.forms import PictureImportForm
 from social.utils import likes
@@ -63,6 +63,7 @@ def read_tags(tags, request, allowed):
 
     def process(category, slug):
         if category == 'book':
 
     def process(category, slug):
         if category == 'book':
+            # FIXME: Unused?
             try:
                 books.append(Book.objects.get(slug=slug))
             except Book.DoesNotExist:
             try:
                 books.append(Book.objects.get(slug=slug))
             except Book.DoesNotExist:
@@ -179,7 +180,7 @@ class BookDetails(object):
         try:
             author, title, book_id = after.split(SORT_KEY_SEP)
         except ValueError:
         try:
             author, title, book_id = after.split(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))))
         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))))
@@ -221,6 +222,7 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails):
     model = Book
     fields = book_list_fields
 
     model = Book
     fields = book_list_fields
 
+    # FIXME: Unused?
     @classmethod
     def genres(cls, book):
         """ Returns all media for a book. """
     @classmethod
     def genres(cls, book):
         """ Returns all media for a book. """
@@ -239,6 +241,7 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails):
              are returned.
         """
         if pk is not None:
              are returned.
         """
         if pk is not None:
+            # FIXME: Unused?
             try:
                 return Book.objects.get(pk=pk)
             except Book.DoesNotExist:
             try:
                 return Book.objects.get(pk=pk)
             except Book.DoesNotExist:
@@ -330,7 +333,7 @@ class BooksHandler(BookDetailHandler):
 
 class EpubHandler(BookDetailHandler):
     def read(self, request, slug):
 
 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 rc.FORBIDDEN
         try:
             book = Book.objects.get(slug=slug)
@@ -606,6 +609,7 @@ class TagsHandler(BaseHandler, TagDetails):
     def read(self, request, category=None, pk=None):
         """ Lists all tags in the category (eg. all themes). """
         if pk is not None:
     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:
             try:
                 return Tag.objects.exclude(category='set').get(pk=pk)
             except Book.DoesNotExist:
@@ -730,7 +734,7 @@ class UserDataHandler(BaseHandler):
         if not request.user.is_authenticated():
             return rc.FORBIDDEN
         if slug is None:
         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:
         try:
             book = Book.objects.get(slug=slug)
         except Book.DoesNotExist:
@@ -759,6 +763,7 @@ class UserDataHandler(BaseHandler):
 class UserShelfHandler(BookDetailHandler):
     fields = book_list_fields + ['liked']
 
 class UserShelfHandler(BookDetailHandler):
     fields = book_list_fields + ['liked']
 
+    # FIXME: Unused?
     def parse_bool(self, s):
         if s in ('true', 'false'):
             return s == 'true'
     def parse_bool(self, s):
         if s in ('true', 'false'):
             return s == 'true'