예제 #1
0
파일: list.py 프로젝트: CoCornell/CoCornell
def delete_list(list_id):
    """
    Deletes a list.
    """
    if not List.has_access_to(g.user.netid, list_id):
        return redirect(url_for('board'))
    List.delete_list_by_id(list_id)
    return jsonify({"deleted": True})
예제 #2
0
파일: card.py 프로젝트: CoCornell/CoCornell
def list_(list_id):
    """
    Returns all cards in the list specified by list id.
    """
    if not List.has_access_to(g.user.netid, list_id):
        return error(Error.NO_ACCESS_TO_LIST)

    l = List.get_list_by_id(list_id).to_dict()
    cards = List.get_cards_by_list_id(list_id)
    l['cards'] = map(lambda x: x.to_dict(), cards)
    return ok({"list": l})
예제 #3
0
파일: list.py 프로젝트: CoCornell/CoCornell
def list_(list_id):
    """
    Returns or deletes the list specified by list id.
    """
    if not List.has_access_to(g.user.netid, list_id):
        return error(Error.NO_ACCESS_TO_LIST)

    if request.method == 'GET':
        l = List.get_list_by_id(list_id).to_dict()
        cards = List.get_cards_by_list_id(list_id)
        l['cards'] = map(lambda x: x.to_dict(), cards)
        return ok({"list": l})

    if request.method == 'DELETE':
        List.delete_list_by_id(list_id)
        return ok({"deleted": True})
예제 #4
0
def upload_image():
    """
    Upload an image to a list,
    return JSON.
    """
    list_id = request.form.get("list_id")
    base64_str = request.form.get("file")

    if not list_id:
        return error(Error.EMPTY_LIST_ID, 400)
    if not base64_str:
        return error(Error.EMPTY_IMAGE, 400)
    if not List.has_access_to(g.user.netid, list_id):
        return error(Error.NO_ACCESS_TO_LIST, 400)

    decoded = base64.decodestring(base64_str)
    filename = str(uuid.uuid4()) + ".png"
    image_path = app.config['IMAGE_PATH'] + filename
    with open(image_path, "wb") as f:
        f.write(decoded)

    card = Card.add_card(list_id, filename, True)

    image_path = app.config['IMAGE_PATH'] + filename
    thread = Thread(target=async_ocr, args=[app, image_path, card.id])
    thread.start()

    return ok({"created": True, "card": card.to_dict()})
예제 #5
0
def board(board_id):
    """
    Returns all the lists of the board specified by board_id.
    """
    lists = List.get_lists_by_board_id(board_id)
    lists = map(lambda x: x.to_dict(), lists)
    return ok({'lists': lists})
예제 #6
0
파일: card.py 프로젝트: CoCornell/CoCornell
def delete_card(card_id):
    """
    Deletes a card.
    """
    if not List.has_access_to_card(g.user.netid, card_id):
        return redirect(url_for('board'))
    Card.delete_card_by_id(card_id)
    return jsonify({"deleted": True})
예제 #7
0
파일: list.py 프로젝트: CoCornell/CoCornell
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)})
예제 #8
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()})
예제 #9
0
파일: card.py 프로젝트: CoCornell/CoCornell
def add_card():
    """
    Adds a card to a list.
    """
    content = request.form.get("content")
    list_id = request.form.get("list_id")

    if not content:
        return error(Error.EMPTY_CONTENT, 400)
    if not List.has_access_to(g.user.netid, list_id):
        return error(Error.NO_ACCESS_TO_BOARD, 400)

    card = Card.add_card(list_id, content)
    return ok({"created": True, "card": card.to_dict()})
예제 #10
0
파일: list.py 프로젝트: CoCornell/CoCornell
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()})
예제 #11
0
파일: card.py 프로젝트: CoCornell/CoCornell
def add_card():
    """
    Adds a card specified by card content and list id.
    Returns the created card id.
    """
    content = request.form.get("content")
    list_id = request.form.get("list_id")

    if not content:
        return error(Error.EMPTY_CONTENT, 400)
    elif not list_id:
        return error(Error.EMPTY_LIST_ID, 400)

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

    card = Card.add_card(list_id, content)
    return ok({"created": True, "card": card.to_dict()})
예제 #12
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)