def enter_lineup(): golfer_1 = request.form['golfer_1'] golfer_2 = request.form['golfer_2'] golfer_3 = request.form['golfer_3'] golfer_4 = request.form['golfer_4'] golfer_5 = request.form['golfer_5'] tiebreak = request.form['two-round'] states = ['NJ', 'CO', 'NY', 'PA'] if session["location"] in states: if Lineup.validate_lineup(golfer_1, golfer_2, golfer_3, golfer_4, golfer_5) is not True: text = "Choose Five Different Golfers" golfers = Golfer.find_golfers() golfers = sorted(golfers, key=Golfer.get_name) balance = User.get_balance(session['username']) return render_template("lineup_entry.html", golfers=golfers, contest_id=session["contest_id"], username=session['username'], balance=balance, text=text) else: buy_in = Contest.get_contest_buyin(session["contest_id"]) buy_in = int(buy_in) balance = User.get_balance(session['username']) if balance >= buy_in: User.remove_funds(session["username"], buy_in) Lineup.create_lineup(session["contest_id"], session["username"], golfer_1, golfer_2, golfer_3, golfer_4, golfer_5, tiebreak) session["contest_id"] = "" return redirect('/') else: text = "Insufficient Funds Please Add Funds to Enter Contest" golfers = Golfer.find_golfers() golfers = sorted(golfers, key=Golfer.get_name) balance = User.get_balance(session['username']) return render_template("lineup_entry.html", golfers=golfers, contest_id=session["contest_id"], username=session['username'], balance=balance, text=text) else: return render_template("invalidlocation.html")
def contest_entries(contest_id): lineups = Lineup.get_entries(contest_id) lineups = sorted(lineups, key=operator.attrgetter("Score")) contest = Contest.get_from_mongo(contest_id) balance = User.get_balance(session['username']) return render_template("contest_entries.html", lineups=lineups, contest=contest, username=session['username'], balance=balance)
def edit_lineup(lineup_id): lineup = Lineup.get_lineup(lineup_id) tiebreak = lineup[0].Tiebreak golfers = Golfer.find_golfers() golfers = sorted(golfers, key=Golfer.get_name) selected = [] for i in golfers: if i.Golfer_Name == lineup[0].Golfer_1: selected.append("selected") else: selected.append("") selected2 = [] for i in golfers: if i.Golfer_Name == lineup[0].Golfer_2: selected2.append("selected") else: selected2.append("") selected3 = [] for i in golfers: if i.Golfer_Name == lineup[0].Golfer_3: selected3.append("selected") else: selected3.append("") selected4 = [] for i in golfers: if i.Golfer_Name == lineup[0].Golfer_4: selected4.append("selected") else: selected4.append("") selected5 = [] for i in golfers: if i.Golfer_Name == lineup[0].Golfer_5: selected5.append("selected") else: selected5.append("") golfers1 = zip(golfers, selected) golfers2 = zip(golfers, selected2) golfers3 = zip(golfers, selected3) golfers4 = zip(golfers, selected4) golfers5 = zip(golfers, selected5) balance = User.get_balance(session['username']) return render_template("lineup_update.html", tiebreak=tiebreak, golfers=golfers1, golfers2=golfers2, golfers3=golfers3, golfers4=golfers4, golfers5=golfers5, balance=balance, lineup_id=lineup_id)
def live_lineups(): username = session['username'] live = Lineup.get_contests_username(username) live = filter(lambda x: x.Start_Date <= datetime.date.today(), live) live = list(filter(lambda x: x.End_Date >= datetime.date.today(), live)) live = sorted(live, key=operator.attrgetter('Start_Date')) balance = User.get_balance(session['username']) if len(live) == 0: text = "You Do Not Have Any Live Contests" else: text = "" if session.get('email') is None: return render_template("nologin.html", type="Live") else: return render_template("live.html", username=session['username'], text=text, balance=balance, live=live)
def upcoming_lineups(): username = session['username'] upcoming = Lineup.get_contests_username(username) upcoming = list( filter(lambda x: x.Start_Date > datetime.date.today(), upcoming)) upcoming = sorted(upcoming, key=operator.attrgetter('Start_Date')) balance = User.get_balance(session['username']) if len(upcoming) == 0: text = "You Do Not Have Any Upcoming Contests" else: text = "" if session.get('email') is None: return render_template("nologin.html", type="Upcoming") else: return render_template("upcoming.html", text=text, username=session['username'], balance=balance, upcoming=upcoming)
def previous_lineups(): username = session['username'] completed = Lineup.get_contests_username(username) completed = filter( lambda x: x.End_Date >= datetime.date.today() - datetime.timedelta( days=14), completed) completed = list( filter(lambda x: x.End_Date <= datetime.date.today(), completed)) completed = sorted(completed, key=operator.attrgetter('Start_Date')) balance = User.get_balance(session['username']) if len(completed) == 0: text = "You Do Not Have Contests From The Last 14 Days" else: text = "" if session.get('email') is None: return render_template("nologin.html", type="Completed") else: return render_template("completed.html", username=session['username'], text=text, balance=balance, completed=completed)
def delete_lineup(lineup_id): Lineup.delete_lineup(lineup_id) return redirect("/upcoming")
def update_lineup(lineup_id): golfer_1 = request.form['golfer_1'] golfer_2 = request.form['golfer_2'] golfer_3 = request.form['golfer_3'] golfer_4 = request.form['golfer_4'] golfer_5 = request.form['golfer_5'] tiebreak = request.form['two-round'] states = ['NJ', 'CO', 'NY', 'PA'] if session["location"] in states: if Lineup.validate_lineup(golfer_1, golfer_2, golfer_3, golfer_4, golfer_5) is not True: text = "Choose Five Different Golfers" golfers = Golfer.find_golfers() golfers = sorted(golfers, key=Golfer.get_name) selected = [] for i in golfers: if i.Golfer_Name == golfer_1: selected.append("selected") else: selected.append("") selected2 = [] for i in golfers: if i.Golfer_Name == golfer_2: selected2.append("selected") else: selected2.append("") selected3 = [] for i in golfers: if i.Golfer_Name == golfer_3: selected3.append("selected") else: selected3.append("") selected4 = [] for i in golfers: if i.Golfer_Name == golfer_4: selected4.append("selected") else: selected4.append("") selected5 = [] for i in golfers: if i.Golfer_Name == golfer_5: selected5.append("selected") else: selected5.append("") golfers1 = zip(golfers, selected) golfers2 = zip(golfers, selected2) golfers3 = zip(golfers, selected3) golfers4 = zip(golfers, selected4) golfers5 = zip(golfers, selected5) balance = User.get_balance(session['username']) return render_template("lineup_update.html", tiebreak=tiebreak, golfers=golfers1, golfers2=golfers2, golfers3=golfers3, golfers4=golfers4, golfers5=golfers5, username=session['username'], balance=balance, text=text, lineup_id=lineup_id) else: Lineup.update_lineup(lineup_id, golfer_1, golfer_2, golfer_3, golfer_4, golfer_5, tiebreak) session["contest_id"] = "" return redirect('/') else: return render_template("invalidlocation.html")