-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
102 lines (77 loc) · 3.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from flask import *
from build import *
app = Flask(__name__, static_url_path="", static_folder="static")
app.config.from_object(__name__)
app.config.update(dict(
SECRET_KEY='development key',
DEBUG='True'))
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
def init_db():
DatabaseConnection.db.connect()
@app.route('/')
def show_start_html():
boards_query = Board.select().order_by(Board.id.asc())
boards = []
for item in boards_query:
boards.append(item.board_title)
saved_boards_dict = {}
saved_boards_dict['saved_boards'] = boards
json_board_obj = json.dumps(saved_boards_dict)
return render_template("start2.html", json_board_obj=json_board_obj)
@app.route('/board/<board_id>')
def show_board(board_id):
return render_template("board.html")
@app.route("/board/show_cards", methods=['GET', 'POST'])
def show_cards_for_board():
result = request.get_json(force=True)
board = Board.select().where(Board.board_title == result["board_name"]).get()
cards_of_board = Cards.select().where(Cards.board_id == board.id)
cards = []
for card in cards_of_board:
card = {"background": card.background_color, "card_title": card.card_title, "card_desc": card.card_desc,
"card_id": card.card_id, "status": card.status.name}
cards.append(card)
return json.dumps({"cards" : cards})
@app.route('/boards/<id>', methods=['POST'])
def board_to_db(id):
json_obj = request.get_json(force=True)
new_board = Board(board_title=json_obj["board_title"],
board_id=json_obj["board_id"])
new_board.save()
return json.dumps(json_obj)
@app.route('/boards/save_cards', methods=['GET', 'POST'])
def card_to_db():
json_obj = request.get_json(force=True)
new_card_status_id = Status.select().where(Status.name == json_obj["card_status"]).get()
new_card_board_id = Board.select().where(Board.board_title == json_obj["board_name"]).get()
new_card = Cards(card_id=json_obj["card_id"],
card_title=json_obj["card_title"],
card_desc=json_obj["card_description"],
status=new_card_status_id,
board=new_card_board_id,
background_color=json_obj["background_color"])
new_card.save()
return json.dumps(json_obj)
@app.route('/boards/update_status', methods=['POST'])
def update_card_status():
json_obj = request.get_json(force=True)
new_status_of_card = Status.select().where(Status.name == json_obj["card_status"]).get()
Cards.update(status=new_status_of_card).where(Cards.card_id == json_obj["card_id"]).execute()
return json.dumps(json_obj)
@app.route('/boards/delete_cards', methods=['POST'])
def delete_card():
json_obj = request.get_json(force=True)
Cards.delete().where(Cards.card_id == json_obj["card_id"]).execute()
return json.dumps({"status": "OK"})
@app.route('/boards/<title>', methods=['DELETE'])
def del_board(title):
# json_obj = request.get_json(force=True)
board_obj = Board.select().where(Board.board_title == title).get()
Cards.delete().where(Cards.board_id == board_obj.id).execute()
Board.delete().where(Board.board_title == title).execute()
return json.dumps({"status": "OK"})
def main():
app.run()
init_db()
if __name__ == '__main__':
main()