+class FilterBooksHandler(BooksHandler):
+ anonymous = AnonFilterBooksHandler
+ fields = book_list_fields + ['key', 'liked']
+
+ # hack, because piston is stupid
+ @classmethod
+ def liked(cls, book):
+ return getattr(book, 'liked', None)
+
+ def read(self, request):
+ qsp = AnonFilterBooksHandler().read(request)
+ likes = set(Book.tagged.with_any(request.user.tag_set.all()).values_list('id', flat=True))
+ for book in qsp.list:
+ book.set('liked', book.id in likes)
+ return qsp
+
+
+class BookPreviewHandler(BookDetailHandler):
+ fields = BookDetailHandler.fields + ['slug']
+
+ def read(self, request):
+ return Book.objects.filter(preview=True)
+
+