Ejemplo n.º 1
0
def board():
    if request.method == 'GET':
        board_ids = Board.get_board_ids_by_netid(g.user.netid)
        boards = map(Board.get_board_by_id, board_ids)
        return render_template("board.html", boards=boards)
    else:
        # request.method == 'POST'
        name = request.form.get('name')
        if not name:
            flash("Board name can not be empty.")
            return redirect(url_for('board'))
        Board.add_board(name)
        return redirect(url_for('board'))
Ejemplo n.º 2
0
def board_lists(board_id):
    """
    Returns all the lists belongs to the board specified by board id.
    """
    if not Board.has_access_to(g.user.netid, board_id):
        return error(Error.NO_ACCESS_TO_BOARD)

    lists = List.get_lists_by_board_id(board_id)
    return ok({"lists": map(lambda x: x.to_dict(), lists)})
Ejemplo n.º 3
0
def all_boards():
    """
    Returns all the boards the user has access to
    or adds a board.
    """
    if request.method == 'GET':
        board_ids = Board.get_board_ids_by_netid(g.user.netid)
        boards = map(lambda id_: Board.get_board_by_id(id_).to_dict(), board_ids)
        return ok({'boards': boards})

    elif request.method == 'POST':
        # add a board
        board_name = request.form.get("name")

        if not board_name:
            return error(Error.EMPTY_BOARD_ID, 400)

        b = Board.add_board(board_name)
        Access.add_access(b.id, g.user.netid)
        return ok({"created": True, "board": b.to_dict()})
Ejemplo n.º 4
0
def add_list():
    """
    Adds a list specified by list name and board id.
    Returns the created list id.
    """
    list_name = request.form.get("name")
    board_id = request.form.get("board_id")

    if not list_name:
        return error(Error.EMPTY_LIST_NAME, 400)
    elif not board_id:
        return error(Error.EMPTY_BOARD_ID, 400)

    if not Board.has_access_to(g.user.netid, board_id):
        return error(Error.NO_ACCESS_TO_BOARD, 400)

    list_ = List.add_list(board_id, list_name)
    return ok({"created": True, "list": list_.to_dict()})
Ejemplo n.º 5
0
def board_list(board_id):
    """
    GET: get all lists of the specified board
    POST: add a list to the specified board

    Return JSON.
    """
    if request.method == 'GET':
        lists = List.get_lists_by_board_id(board_id)
        return ok({"lists": map(lambda x: x.to_dict(), lists)})
    elif request.method == 'POST':
        name = request.form.get("name")
        if not name:
            return error(Error.EMPTY_LIST_NAME, 400)

        if not Board.has_access_to(g.user.netid, board_id):
            return error(Error.NO_ACCESS_TO_BOARD, 400)

        list_ = List.add_list(board_id, name)
        return ok({"created": True, "list": list_.to_dict()})
Ejemplo n.º 6
0
def board_page(board_id):
    if not Board.has_access_to(g.user.netid, board_id):
        return render_template("no_access.html")
    lists = List.get_lists_by_board_id(board_id)
    return render_template("board_page.html", lists=lists)
Ejemplo n.º 7
0
def board_count():
    """
    Returns number of boards the user has access to.
    """
    count = Board.get_board_count_by_netid(g.user.netid)
    return ok({'count': count})