def rename_card(request): updated_card = json.loads(request.data) cards = data_handler.get_all_cards() for card in cards: if card['id'] == updated_card['cardId']: card['title'] = updated_card['cardTitle'] data_handler.write_cards(cards) return updated_card
def delete_card(request): cards = data_handler.get_all_cards() card_id = json.loads(request.data)['id'] for card in cards: if card['id'] == card_id: cards.remove(card) data_handler.write_cards(cards) return {'success': True}
def move_card(request): data_from_request = json.loads(request.data) cards = data_handler.get_all_cards() set_new_card_order(cards, data_from_request["order"]) status_id = get_status_id_by_name(data_from_request["status"]) update_card_data(cards, data_from_request, status_id) data_handler.write_cards(cards) return {"success": True}
def add_new_card(request): cards = data_handler.get_all_cards() new_card_data = json.loads(request.data) new_card = { 'id': get_max_id(cards) + 1, 'board_id': new_card_data['board_id'], 'title': new_card_data['title'], 'status_id': new_card_data['status_id'], 'order': new_card_data['order'], } cards = change_card_order(cards, new_card_data['board_id']) cards.append(new_card) data_handler.write_cards(cards) return new_card
def delete_cards_by_board_id(board_id): cards = data_handler.get_all_cards() for card in cards.copy(): if card['board_id'] == board_id: cards.remove(card) data_handler.write_cards(cards)