示例#1
0
def content(bid, cid):
    book = Book.get(bid)
    chapter = Chapter.get(cid, bid)
    if not (book and chapter):
        abort(404)

    # NOTE read/set cookies for recent reading
    recent_reading = request.cookies.get('recent_reading')
    rec_book_chapters = []
    if recent_reading:
        for bid_cid in recent_reading.split('|'):
            _bid, _cid = [int(id) for id in bid_cid.split(':', 1)]
            if not _bid == bid:
                if Book.get(_bid) and Chapter.get(_cid, _bid):
                    rec_book_chapters.append(
                        (Book.get(_bid), Chapter.get(_cid, _bid))
                    )
    rec_book_chapters.insert(0, (book, chapter))
    rec_book_chapters = rec_book_chapters[:10]

    resp = make_response(render_template('content.html', **locals()))
    recent_reading_str = '|'.join(['%s:%s' % (book.id, chapter.id)
                         for book, chapter in rec_book_chapters])
    resp.set_cookie('recent_reading', recent_reading_str)
    return resp
示例#2
0
def m_chapter_modal(bid, cid):
    chapter = Chapter.get(cid, bid)
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        chapter.update(title, content)
        return redirect(request.referrer)
    return render_template('admin/chapter_modal.html', **locals())
示例#3
0
def recent_reading(request):
    recent_reading = request.cookies.get('recent_reading')
    recent_book_chapters = []
    if recent_reading:
        for bid_cid in recent_reading.split('|'):
            bid, cid = [int(id) for id in bid_cid.split(':', 1)]
            book = Book.get(bid)
            chapter = Chapter.get(cid, bid)
            if (book and chapter):
                recent_book_chapters.append((book, chapter))
        recent_book_chapters = recent_book_chapters[:10]
    return recent_book_chapters