Beispiel #1
0
def list_pages_(page_id, path_id, book_name):
    form = ComposePageForm()
    paths = BookHandler.get_paths(page_id=page_id, path_id=path_id)
    book_id = BookHandler.get_book(page_id=page_id, path_id=path_id)['id']
    pages = BookHandler.get_pages_by_path(path_id)
    data = {
        'pages': pages,
        'paths': paths,
        'page_id': page_id,
        'path_id': path_id,
        'book_id': book_id
    }
    return render_template('book_part_pages.html', form=form, data=data)
Beispiel #2
0
def compose_edit(book_name, book_id):
    """
    Shows tree of book
    """
    paths = BookHandler.get_paths_by_book_id(book_id)

    data = {'paths': paths, 'book_id': book_id}
    return render_template('book_parts.html', data=data)
Beispiel #3
0
def book_part(page_id, path_id, book_name):
    form = ComposePageForm()
    paths = BookHandler.get_paths(page_id=page_id, path_id=path_id)
    book_id = BookHandler.get_book(page_id=page_id, path_id=path_id)['id']
    page = None
    if page_id != 'new':
        page = BookHandler.get_page_by_id(page_id)

    if not path_id:
        print(page, end=' page \n')
        path_id = page['path_id']

    data = {
        'page': page,
        'paths': paths,
        'page_id': page_id,
        'path_id': path_id,
        'book_id': book_id
    }
    return render_template('compose_page.html', form=form, data=data)
Beispiel #4
0
def compose_new():
    """
    Compose form for creating new book. Uses post method for saving.
    Returns Book Id and Book Title
    """
    form = ComposeForm()
    if request.method == 'GET':
        return render_template('compose_new.html', form=form)
    else:
        book = BookHandler.create_book(request)
        res = {'book_id': book.id, 'book_title': book.title}
        return jsonify(res), 200
Beispiel #5
0
def read_book(book_name, book_id, page_id, path_id, direction='c'):
    """
    Book reading pages, /book/[ANY]/(read, o, p, c, n)/[ANY] catches the request
    'book/[foo]/read' used for beginning of the book, opens first page of that book
    p is 'book/[foo]/p' opens previous page using that page id
    c is 'book/[foo]/c' opens page with that id
    n is 'book/[foo]/n' opens next page using that page id
    o is 'book/[foo]/o' used for option page, opens first page of that path
    :param direction: p, c, n
    """
    if page_id:
        pages = BookHandler.get_pages_by_page(page_id)
    elif path_id:
        pages = BookHandler.get_pages_by_path(path_id)
    else:
        pages = BookHandler.get_pages_by_book(book_id)

    page, options, parent_page = None, None, None
    data = {}

    # If page id doesnt exist, return first page of the book
    if len(pages) > 0 and page_id is None:
        page = pages[0]
        data['title'] = BookHandler.get_book(page_id=page['id']).get('title')

    # If page id exist, iterate over pages.
    # When page id matches,
    # if direction p return index -1
    # if direction c return index
    # if direction n return index +1
    # If list ends with n direction, show options (child paths)
    elif len(pages) > 0 and page_id:
        data['title'] = BookHandler.get_book(page_id=page_id).get('title')
        for i, p in enumerate(pages):
            if p['id'] == page_id:
                if direction == 'p' and i >= 1:
                    page = pages[i - 1]
                elif direction == 'c':
                    page = pages[i]
                elif direction == 'n':
                    if i <= len(pages) - 2:
                        page = pages[i + 1]
                    elif i == len(pages) - 1:
                        data['prev_page_id'] = pages[i].get('id')
                        options = BookHandler.get_children_by_page(page_id)

    data['page'] = page
    data['options'] = options
    return render_template('read.html', **data)
Beispiel #6
0
def home():
    """
    Homepage, shows popular 3 books
    """
    data = {'popular_books': BookHandler.get_public_books()[:3]}
    return render_template('index.html', **data), 200
Beispiel #7
0
def get_tree(book_id):
    paths, err = BookHandler.get_tree(book_id)
    return jsonify(paths[0]), 200
Beispiel #8
0
def delete_path(path_id):
    path = BookHandler.delete_path(path_id)
    return jsonify('success'), 200
Beispiel #9
0
def end_path(path_id):
    path = BookHandler.end_path(path_id)
    return jsonify('success'), 200
Beispiel #10
0
def rename_path(path_id):
    path = BookHandler.rename_path(path_id, request)
    return jsonify('success'), 200
Beispiel #11
0
def add_path(parent_path_id):
    path_name = 'Yeni Node'
    path = BookHandler.add_path(parent_path_id, path_name)
    path_id = path.get('id')
    return jsonify({'id': path_id}), 200
Beispiel #12
0
def sage_page(page_id):
    page = BookHandler.save_page(page_id, request)
    return jsonify({'page_id': page.id}), 200
Beispiel #13
0
def get_pages(path_id):
    if request.method == 'POST':
        pages = BookHandler.get_pages_by_path(path_id)
        return jsonify(pages)
Beispiel #14
0
def book_landing(book_name, book_id):
    """
    Book landing page, shows the details
    """
    data = {'book': BookHandler.get_book(None, None, book_id)}
    return render_template('book-landing.html', **data)
Beispiel #15
0
def my_books():
    """
    Lists books of the user
    """
    books = BookHandler.get_books()
    return render_template('my-books.html', books=books)