示例#1
0
def book(request, isbn13):
    book = get_adapter().book(isbn13)
    serializer = BookSerializer(book, request)

    context = {
        "book": serializer.data
    }
    return render(request, 'traditional/pages/book.html', context)
示例#2
0
def books(request):
    page = request.GET.get('page', 1)
    results = get_adapter().books(page)

    serializer = BookListSerializer(results, request)
    context = {
        "books": serializer.data,
    }
    return render(request, 'traditional/pages/books.html', context)
示例#3
0
def add_my_bookmarks(request):
    isbn13 = request.GET.get('isbn13')
    book = get_adapter().book(isbn13)
    success, message = Bookmark.add_my_bookmarks(request.user, book)

    response = {
        "success": success,
        "message": message
    }
    return JsonResponse(response)
示例#4
0
def search(request):
    q, page = request.GET.get('q', ""), request.GET.get('page', 1)
    results = get_adapter().search(q, page)

    is_lucky = request.GET.get('lucky', False)
    if is_lucky and len(results) > 0:
        isbn13 = results[0]['isbn13']
        url = reverse('traditional:book', kwargs={"isbn13": isbn13})
        return HttpResponseRedirect(url)

    serializer = BookListSerializer(results, request)
    context = {
        "books": serializer.data,
    }
    return render(request, 'traditional/pages/search.html', context)
示例#5
0
 def get(self, request):
     adapter = get_adapter()
     results = adapter.books(paginated=False)
     return Response({"books": results})
示例#6
0
 def get(self, request, isbn13):
     adapter = get_adapter()
     results = adapter.book(isbn13)
     return Response(results)
示例#7
0
 def get(self, request):
     q = request.query_params.get('q')
     adapter = get_adapter()
     results = adapter.search(q)
     return Response(results)
示例#8
0
 def get(self, request, *args, **kwargs):
     adapter = get_adapter()
     results = adapter.books()
     return Response(results)