|
|
@@ -1,5 +1,5 @@
|
|
1
|
1
|
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
|
2
|
|
-from fpl_lib import SFL, Team
|
|
|
2
|
+from fpl_lib import SFL, Team, Leauge
|
|
3
|
3
|
from flask_pymongo import PyMongo
|
|
4
|
4
|
from bson.objectid import ObjectId
|
|
5
|
5
|
|
|
|
@@ -18,6 +18,37 @@ def search_player(name):
|
|
18
|
18
|
results = sfp.search_player(name)
|
|
19
|
19
|
return jsonify(output=results)
|
|
20
|
20
|
|
|
|
21
|
+@app.route('/lgs', methods=["GET", "POST"])
|
|
|
22
|
+def lgs():
|
|
|
23
|
+ lgs = mongo.db.lgs.find()
|
|
|
24
|
+
|
|
|
25
|
+
|
|
|
26
|
+ teams = mongo.db.teams.find()
|
|
|
27
|
+ if request.method == "POST":
|
|
|
28
|
+ if 'createLg' in request.form:
|
|
|
29
|
+ name = request.form.get('title', None)
|
|
|
30
|
+
|
|
|
31
|
+ team = Leauge(name, mongo)
|
|
|
32
|
+ team.create()
|
|
|
33
|
+ return redirect(url_for(".lgs"))
|
|
|
34
|
+
|
|
|
35
|
+
|
|
|
36
|
+
|
|
|
37
|
+
|
|
|
38
|
+ lg = None
|
|
|
39
|
+ if 'lg_id' in request.args:
|
|
|
40
|
+ #lg = mongo.db.lgs.find_one({'_id': ObjectId(request.args.get('lg_id'))})
|
|
|
41
|
+ lg = Leauge.from_id(request.args.get('lg_id'), mongo)
|
|
|
42
|
+
|
|
|
43
|
+ if 'selectTeam' in request.form:
|
|
|
44
|
+ team_values = request.form.getlist('teams')
|
|
|
45
|
+ print(f"teams = {team_values}")
|
|
|
46
|
+ for t in team_values:
|
|
|
47
|
+ lg.add_team(t)
|
|
|
48
|
+ lg.save()
|
|
|
49
|
+
|
|
|
50
|
+ return render_template('lgs.html', lgs = lgs, lg=lg, teams = teams)
|
|
|
51
|
+
|
|
21
|
52
|
@app.route('/team/<team_id>', methods=["GET", "POST"])
|
|
22
|
53
|
def team(team_id):
|
|
23
|
54
|
team = mongo.db.teams.find_one({"_id": ObjectId(team_id)})
|
|
|
@@ -79,8 +110,8 @@ def index():
|
|
79
|
110
|
selectPlayers = [int(x) for x in selectPlayers]
|
|
80
|
111
|
mongo.db.teams.update_one({"_id": ObjectId(selectTeam)}, {"$set": {"players": selectPlayers}})
|
|
81
|
112
|
|
|
82
|
|
- print("select players")
|
|
83
|
|
- print(selectPlayers)
|
|
|
113
|
+ print("select players")
|
|
|
114
|
+ print(selectPlayers)
|
|
84
|
115
|
|
|
85
|
116
|
if teamCreate:
|
|
86
|
117
|
print("Team Create")
|