示例#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
示例#2
0
文件: views.py 项目: pahkey/wikidocs
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
示例#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
示例#4
0
文件: views.py 项目: pahkey/wikidocs
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