Exemplo n.º 1
0
def comic(request, id):
    comic, pages = _get_comic(id)

    try:
        bookmark = Bookmark.objects.get(comic=comic)
    except Bookmark.DoesNotExist:
        bookmark = Bookmark(comic=comic)
        bookmark.page = 0
        bookmark.save()

    active_page = bookmark.page

    if active_page >= len(pages):
        active_page = len(pages) - 1
    if active_page < 0:
        active_page = 0

    context = {"comic": comic, "active_page": active_page, "num_pages": len(pages)}

    return render(request, "mediasnakecomics/comic.html", context)
Exemplo n.º 2
0
def bookmark(request, id):
    if request.method != "POST":
        raise Http404

    try:
        page = int(request.POST["page"])
    except (ValueError, KeyError):
        return HttpResponse("400 Bad request", status=400)

    try:
        comic = Comic.objects.get(pk=id)
    except Comic.DoesNotExist:
        raise Http404

    try:
        bookmark = Bookmark.objects.get(comic=comic)
    except Bookmark.DoesNotExist:
        bookmark = Bookmark(comic=comic)

    bookmark.page = page
    bookmark.save()

    return HttpResponse("{}", content_type="application/json")