예제 #1
0
def list_other_boards(many):
    """
    List the boards of all users.

    :param many: ``True`` iff multiple boards can be selected.
    :type many: bool
    :return: A list of boards.
    :rtype: flask.Response
    """
    boards = DBBoard.query().all()
    user = User.get_by_id(session['user'])
    return render_template('list_boards.html', boards=boards, many=many, root=True, user=user)
예제 #2
0
def list_boards(many):
    """
    List the available user boards.

    :param many: ``True`` iff multiple boards can be selected.
    :type many: bool
    :return: A list of the users boards.
    :rtype: flask.Response
    """

    user = User.get_by_id(session["user"])
    boards = DBBoard.query().filter_by(user=user).all()
    return render_template("list_boards.html", boards=boards, many=many, root=False, user=user)
예제 #3
0
def view_many_boards(board_ids, solution, mode, root):
    """
    View many boards.
    """
    user = User.get_by_id(session['user'])
    query = DBBoard.query().filter(DBBoard.id.in_(board_ids))
    if not root:
        query = query.filter_by(user=user)
    boards = query.all()

    if mode == INSITE_BOARD_VIEW:
        return render_template('view_board.html', many=True, boards=boards, board_ids=board_ids,
                               is_solution=solution, root=root, user=user)
    elif mode == PRINT_BOARD_VIEW:
        return render_template('print_board.html', multi_board=True, boards=boards, is_solution=solution)
    elif mode == PDF_BOARD_VIEW:
        filename = 'solution.pdf' if solution else 'board.pdf'
        return render_pdf_template('pdf_board.tex', filename, multi_board=True, boards=boards, is_solution=solution)
    else:
        flash('Invalid mode', 'warning')
        return redirect(url_for('main_page'))
예제 #4
0
def create_board():
    """
    Create a new board or some new boards.

    * If this page is requested with a GET method, the board generation form is returned.
    * If this page is requested with a POST method, a board generation form is processed, and new board/s is/are
        generated. Later a board generation form is returned, with a message that new boards were generated, with a
        link to the newly generated board/s.

    :return: As explained above.
    :rtype: flask.Response
    """
    just_created = False
    user = User.get_by_id(session["user"])

    if request.method == "POST":
        try:
            board_type = request.form["type"]
            width, height = BOARD_TO_DIMENSION[board_type](request.form)
            count = int(request.form["count"])

            boards = [DBBoard.create_board(user, generate(width, height)) for _ in xrange(count)]
            commit()

            board_ids = [board.id for board in boards]
            session["last_boards"] = board_ids

            if len(board_ids) == 1:
                flash("Created one board", "success")
            else:
                flash("Created %d boards" % len(board_ids), "success")
            just_created = True
        except (KeyError, ValueError):
            flash("Invalid request data", "danger")
        except:
            flash("Internal server error", "danger")
    return render_template("create_board.html", just_created=just_created, user=user)
예제 #5
0
def view_one_board(board_id, solution, mode, root):
    """
    View a single board.
    """
    user = User.get_by_id(session['user'])
    board = DBBoard.get_by_id(board_id)

    if board is None or (board.user != user and not root):
        flash('Board not found', 'warning')
        return redirect(url_for('main_page'))

    if mode == INSITE_BOARD_VIEW:
        return render_template('view_board.html', many=False, board=board, board_id=board_id, is_solution=solution,
                               root=root, user=user)
    elif mode == PRINT_BOARD_VIEW:
        return render_template('print_board.html', multi_board=False, board=board, board_id=board_id,
                               is_solution=solution)
    elif mode == PDF_BOARD_VIEW:
        filename = 'solution.pdf' if solution else 'board.pdf'
        return render_pdf_template('pdf_board.tex', filename, multi_board=False, board=board, board_id=board_id,
                                   is_solution=solution)
    else:
        flash('Invalid mode', 'warning')
        return redirect(url_for('main_page'))