def add_new_status_to_board(board_id: int, new_status_name: str): if new_status_name in persistence.get_statuses_list(): status_id = persistence.get_status_id_by_status_name(new_status_name) persistence.get_status_board_connections().append({ 'board_id': board_id, 'status_id': status_id, 'order': persistence.new_order_number_to_board_status_connections( board_id, status_id) }) persistence.export_data('board_statuses') else: new_id = persistence.new_id_to_csv(persistence.STATUSES_FILE) new_status = {'id': new_id, 'title': new_status_name} persistence.get_statuses_dict().append(new_status) persistence.export_data('statuses') persistence.get_status_board_connections().append({ 'board_id': board_id, 'status_id': new_id, 'order': persistence.new_order_number_to_board_status_connections( board_id, status_id) }) persistence.export_data('board_statuses')
def get_statuses_by_board_id(board_id): board_status_connections = persistence.get_status_board_connections() statuses_to_board = [] for connection in board_status_connections: if int(connection['board_id']) == board_id: new_status = { 'id': connection['status_id'], 'title': persistence.get_status_by_id(connection['status_id']), 'order': connection['order'] } statuses_to_board.append(new_status) return statuses_to_board
def delete_status(board_id, status_id): # delete status board connection connections = persistence.get_status_board_connections() for connection in connections: if connection['board_id'] == str( board_id) and connection['status_id'] == str(status_id): connections.remove(connection) persistence.export_data('board_statuses') # delete cards for this board and status cards = persistence.get_cards() for card in cards: if card['board_id'] == str(board_id) and card['status_id'] == str( status_id): cards.remove(card) persistence.export_data('cards')
def delete_board(board_id): # delete board from boards.csv boards = persistence.get_boards() for board in boards: if board['id'] == str(board_id): boards.remove(board) persistence.export_data('boards') # delete board status connections to this board connections = persistence.get_status_board_connections() for conn in connections: if conn['board_id'] == str(board_id): connections.remove(conn) persistence.export_data('board_statuses') # delete cards connected to this boards cards = persistence.get_cards() for card in cards: if card['board_id'] == str(board_id): cards.remove(card) persistence.export_data('cards')
def add_board(board_name, creator_username="******", private=0): new_board = { "id": persistence.new_id_to_csv(persistence.BOARDS_FILE), "title": board_name, "creator": creator_username, "private": private } persistence.get_boards().append(new_board) persistence.export_data("boards") # add starter statuses to new boards starter_statuses = [{ 'board_id': new_board['id'], 'status_id': i, 'order': persistence.new_order_number_to_board_status_connections( new_board['id'], i) } for i in range(0, 4)] board_status_connections = persistence.get_status_board_connections() for connection in starter_statuses: board_status_connections.append(connection) persistence.export_data('board_statuses')
def rename_status(board_id, status_id, new_status): new_status_id = persistence.get_status_id_by_status_name(new_status) if new_status_id: pass else: new_status_id = persistence.new_id_to_csv(persistence.STATUSES_FILE) new_status = {'id': new_status_id, 'title': new_status} persistence.get_statuses_dict().append(new_status) persistence.export_data('statuses') cards = persistence.get_cards() for card in cards: if int(card['status_id']) == status_id and int( card['board_id']) == board_id: card['status_id'] = new_status_id persistence.export_data('cards') connections = persistence.get_status_board_connections() for connection in connections: if int(connection['board_id']) == board_id and int( connection['status_id']) == status_id: connection['status_id'] = new_status_id break persistence.export_data('board_statuses')