示例#1
0
文件: views.py 项目: pv/mediasnake
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)
示例#2
0
文件: views.py 项目: pv/mediasnake
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")