def editPlayers(teamName, playerName): if request.method == "POST": t = Team(teamName) about = request.form.get("about", None) if about == "" or about == " ": about = "This Player is a prominent Player in " + teamName t.insertPlayer(playername=request.form.get("playerName", None), country=request.form.get("country", None), age=request.form.get("playerAge", None), dateofbirth=request.form.get("playerDateOfBirth", None), numberofgoals=request.form.get("numberOfGoals", None), photo=request.form.get("playerPhoto", None), playerposition=request.form.get("playerPosition", None), playercost=request.form.get("playerCost", None), jerseynum=request.form.get("playerJerseyNum", 0), about=about, operation="update", oldPlayerName=playerName) return redirect(url_for("teamPlayers", teamName=teamName)) elif request.method == "GET": mydict = { "Goalkeeper": "Goalkeeper", "Right full back": "Right full back", "Left full back": " Left full back", "Right half back": "Right half back", "Centre half back": "Centre half back", "Left half back": "Left half back" } a = db.info.aggregate([{ "$unwind": "$players" }, { "$match": { "teamName": teamName, "players.playerName": playerName } }, { "$project": { "players": 1, "_id": 0 } }], useCursor=False) abc = "" for ab in a: abc = ab["players"] return render_template("playerEditForm.html", teamPlayerData=abc, mydict=mydict, target=abc["playerPosition"])
def editPlayers(teamName, playerId): if request.method == "POST": t = Team(teamName) about = request.form.get("about", None) if about.strip() == "": about = "This Player is a prominent Player in " + teamName t.insertPlayer(playername=request.form.get("playerName", None), country=request.form.get("country", None), age=request.form.get("playerAge", None), dateofbirth=request.form.get("playerDateOfBirth", None), numberofgoals=request.form.get("numberOfGoals", None), photo=request.form.get("playerPhoto", None), playerposition=request.form.get("playerPosition", None), playercost=request.form.get("playerCost", None), jerseynum=request.form.get("playerJerseyNum", 0), about=about, operation="update", oldPlayerid=playerId) flash( "You Just Updated " + request.form.get("playerName", None) + " Information", "message") return redirect(url_for("teamPlayers", teamName=teamName)) elif request.method == "GET": conn = sqlite3.connect("football.db") conn.execute('PRAGMA FOREIGN_KEYS = ON ') cursor = conn.execute("SELECT * FROM PLAYER WHERE PLAYER_ID =?", (playerId, )).fetchone() mydict = { "Goalkeeper": "Goalkeeper", "Right full back": "Right full back", "Left full back": " Left full back", "Right half back": "Right half back", "Centre half back": "Centre half back", "Left half back": "Left half back" } b = [ "teamName", "playerId", "playerName", "country", "playerAge", "playerPhoto", "playerDate", "numberOfGoals", "playerPosition", "playerCost", "playerJerseyNum", "about" ] abc = dict(zip(b, cursor)) return render_template("playerEditForm.html", teamPlayerData=abc, mydict=mydict, target=abc["playerPosition"])
def addPlayers(teamName): if request.method == "POST": t = Team(teamName) about = request.form.get("about", None) if about == "" or about == " ": about = "This Player is a prominent Player in " + teamName t.insertPlayer(playername=request.form.get("playerName", None), country=request.form.get("country", None), age=request.form.get("playerAge", None), dateofbirth=request.form.get("playerDateOfBirth", None), numberofgoals=request.form.get("numberOfGoals", None), photo=request.form.get("playerPhoto", None), playerposition=request.form.get("playerPosition", None), playercost=request.form.get("playerCost", None), jerseynum=request.form.get("playerJerseyNum", 0), about=about, operation="insert", oldPlayerid="") return redirect(url_for("teamPlayers", teamName=teamName)) elif request.method == "GET": return render_template("playerAddForm.html")