예제 #1
0
파일: views.py 프로젝트: sloria/scribnote
 def get(self):
     """Get the reading list for the authenticated user."""
     reading_list = current_user.reading_list.all()
     res = {
         'result': serialize_book(reading_list, many=True).data,
         'user': serialize_user(current_user._get_current_object()).data
     }
     return res
예제 #2
0
파일: views.py 프로젝트: sloria/scribnote
    def post(self):
        """Add a book to the authenticated user's reading list.

        :param-json int book_id: ID of the book to add.
        """
        book = self._get_book_from_request()
        current_user.add_to_reading_list(book)
        current_user.save()
        return {
            'result': serialize_book(book).data,
            'user': serialize_user(current_user._get_current_object()).data,
        }, http.OK
예제 #3
0
파일: views.py 프로젝트: sloria/scribnote
    def put(self):
        """Toggle the ``read`` status of a book.

        :param-json int book_id: ID of the book to modify.
        """
        book = self._get_book_from_request()
        current_user.toggle_read(book)
        current_user.save()
        has_read = current_user.has_read(book)
        return {
            'result': serialize_book(book, extra={'read': has_read}).data,
            'user': serialize_user(current_user._get_current_object()).data,
        }, http.OK