Example #1
0
def book(request, _id):
    cache = cache_get(request, "book_%s" % _id)
    if cache: return HttpResponse(cache)

    try:
        book = Book.objects.get(id=_id)
    except Book.DoesNotExist:
        return redirect("/")

    toc = getToc(request, book)

    check_auth(request, book)
    context = {"book": book, "toc": toc}
    update_context(request, context)
    result = my_render(request, 'book/book.html', context)
    cache_put(request, "book_%s" % _id, result.content)
    return result
Example #2
0
def book(request, _id):
    cache = cache_get(request, "book_%s" % _id)
    if cache: return HttpResponse(cache)

    try:
        book = Book.objects.get(id=_id)
    except Book.DoesNotExist:
        return redirect("/")

    toc = getToc(request, book)

    check_auth(request, book)
    context = {"book": book, "toc":toc}
    update_context(request, context)
    result = my_render(request, 'book/book.html', context)
    cache_put(request, "book_%s" % _id, result.content)
    return result
Example #3
0
def page(request, _id):
    cache = cache_get(request, _id)
    if cache: return HttpResponse(cache)

    try:
        page = Page.objects.get(id=_id)
    except Page.DoesNotExist:
        return redirect("/")

    if page.is_closed_for_buy() and not page.book.is_owner(request.user):
        return redirect("/buy/%s" % page.book.id)

    check_auth(request, page.book, page)
    toc = getToc(request, page.book)
    context = {"page": page, "book": page.book, "toc": toc}
    update_context(request, context)
    result = my_render(request, 'book/page.html', context)
    cache_put(request, _id, result.content)
    return result
Example #4
0
def page(request, _id):
    cache = cache_get(request, _id)
    if cache: return HttpResponse(cache)

    try:
        page = Page.objects.get(id=_id)
    except Page.DoesNotExist:
        return redirect("/")

    if page.is_closed_for_buy() and not page.book.is_owner(request.user):
        return redirect("/buy/%s" % page.book.id)

    check_auth(request, page.book, page)
    toc = getToc(request, page.book)
    context = {"page": page, "book": page.book, "toc": toc}
    update_context(request, context)
    result = my_render(request, 'book/page.html', context)
    cache_put(request, _id, result.content)
    return result