def teams_index(): return render_template("teams/list.html", teams=Team.find_users_teams(current_user.id), form=TeamForm(), units=Team.units_in_teams(current_user.id), unit_numbers=Team.number_of_units_in_teams( current_user.id))
def teams_create(): form = TeamForm(request.form) if not form.validate(): return render_template("teams/new.html", form=form) tm = Team(form.name.data) tm.account_id = current_user.id db.session().add(tm) db.session().commit() #Luodaan liitostauluun paikat tiimille (Jäävät alussa "Free" asetukselle) team_id = tm.id mate1 = Teammate(team_id) mate1.role = 1 mate2 = Teammate(team_id) mate2.role = 2 mate3 = Teammate(team_id) mate3.role = 3 mate4 = Teammate(team_id) mate4.role = 4 mate5 = Teammate(team_id) mate5.role = 5 db.session().add(mate1) db.session().add(mate2) db.session().add(mate3) db.session().add(mate4) db.session().add(mate5) db.session().commit() return redirect(url_for("teams_index"))
def teams_show(team_id): return render_template( "teams/show.html", team_id=team_id, team=Team.find_team(team_id), units=Team.get_units_in_team(team_id), number_of_units=Team.number_of_units_in_team(team_id), form=AddUnitForm())
def teams_create(): form = TeamForm(request.form) if not form.validate(): return render_template("teams/new.html", form=form) t = Team(form.name.data) t.account_id = current_user.id db.session().add(t) db.session().commit() return redirect(url_for("teams_index"))
def teams_create(): if current_user.isAdmin == False: return redirect(url_for("teams_index")) form = TeamForm(request.form) if not form.validate(): return render_template("teams/new.html", form=form) t = Team(form.name.data) t.home = form.home.data db.session().add(t) db.session().commit() return redirect(url_for("teams_index"))
def validate_team_name(form, field): sel_team_name = str(dict(field.choices).get(field.data)) a = Team.find_team_id(sel_team_name) if not a: raise validators.ValidationError( 'Team name must match with team names already in database (list teams to see options)' )
def teams_add_unit(team_id): form = AddUnitForm(request.form) if not form.validate(): return render_template( "teams/show.html", form=form, number_of_units=Team.number_of_units_in_team(team_id), team=Team.find_team(team_id)) unit_name = form.name.data unit_ids = Unit.get_unit_ids_with_name(unit_name) if unit_ids: tu = TeamUnit(team_id=team_id, unit_id=unit_ids[0]) db.session.add(tu) db.session.commit() return redirect(url_for("teams_index"))
def teams_form(): user = User.query.filter_by(id=current_user.id).first() teams = Team.find_teams_of_a_user(current_user.id) teams_list = [(team[0], team[1]) for team in teams] form = TeamForm() form.team_list.choices = teams_list if request.method == "GET": return render_template("/teams/teamform.html", form=form, teams=teams) if request.form["btn"] == "Add team": if request.method == "POST": form = TeamForm(request.form) name = form.team_name.data team = Team.query.filter_by(name=name).first() if team: user.user_teams.append(team) db.session().commit() teams = Team.find_teams_of_a_user(current_user.id) form = TeamForm() return redirect(url_for("teams_form")) new_team = Team(name) db.session().add(new_team) new_team.members.append(user) db.session().commit() return redirect(url_for("teams_form")) if request.form["btn"] == "Modify team": if request.method == "POST": form = TeamForm(request.form) selected_id = form.team_list.data return redirect(url_for('teams_edit', team_id=selected_id))
class MatchForm(FlaskForm): id = StringField("Match ID") match_date = DateField("Match date", format='%Y-%m-%d') team_choices = Team.all_team_data() home_team = SelectField(u'Home team', choices=team_choices, coerce=int) away_team = SelectField(u'Away team', choices=team_choices, coerce=int) class Meta: csrf = False
def team_signup(): error = None form = TeamForm() if form.validate_on_submit(): try: t = Team(name=form.name.data) db.session.add(t) db.session.commit() flash("Team created") except Exception as e: error = e return redirect(url_for("user_signup", team_id=t.id)) return render_template("/teams/new.html", form=form, error=error)
def teams_index(): #Jos joukkueella ei ole yhtään tulosta, joukkueiden järjestäminen #tulosten perusteella ei toimi Postgresql:llä oikein. Siksi järjestäminen #tapahtuu tässä eikä sql-kyselyn yhteydessä. teams = Team.list_teams_with_points() for row in teams: if row["points"] is None: row["points"] = 0 def sortingFunc(e): return e["points"] teams.sort(reverse=True, key=sortingFunc) return render_template("teams/list.html", teams=teams)
def auth_signup(): if request.method == "GET": return render_template("auth/signupform.html", form=SignupForm()) form = SignupForm(request.form) if not form.validate(): return render_template("auth/signupform.html", form=form, error="Username or password too short") username = form.username.data team_name = form.team.data role_id = 2 if os.environ.get("HEROKU"): password = form.password.data else: password = bcrypt.generate_password_hash(form.password.data) user = User.query.filter_by(username=username).first() if user: return render_template("auth/signupform.html", form=form, error="Username already exists") new_user = User(username=username, password=password, role_id=role_id) db.session().add(new_user) team = Team.query.filter_by(name=team_name).first() if not team: team = Team(team_name) db.session().add(team) db.session().commit() created_user = User.query.filter_by(username=username).first() new_user.representive_team_id = team.id team.members.append(created_user) db.session().commit() login_user(new_user) return redirect(url_for("index"))
def teams_edit(team_id): teams = Team.find_teams_of_a_user(current_user.id) team_ids = [team[0] for team in teams] form = TeamForm() team = Team.query.filter_by(id=team_id).first() if request.method == "GET": if int(team_id) in team_ids: return render_template("/teams/editteam.html", team=team, form=form) else: print("Team is not a current user's team") return redirect(url_for("index")) if request.form["btn"] == "Set as representive": user = User.query.filter_by(id=current_user.id).first() user.representive_team_id = team_id db.session().commit() return render_template("/teams/editteam.html", team=team, form=form) if request.form["btn"] == "Change name": if request.method == "POST": form = TeamForm(request.form) new_name = form.team_name.data team.name = new_name db.session().commit() return render_template("/teams/editteam.html", team=team, form=form) if request.form["btn"] == "Remove from my teams": if request.method == "POST": user = User.query.filter_by(id=current_user.id).first() if (user.representive_team_id == int(team_id)): errorMsg = "Cannot remove representive team. Set another team as reprsentive team first." return render_template("/teams/editteam.html", team=team, form=form, error=errorMsg) else: user.remove_team(team_id) return redirect(url_for('teams_form'))
def players_create(): form = PlayerForm(request.form) if not form.validate(): return render_template("players/new.html", form=form) sel_team_name = str(dict(form.team_name.choices).get(form.team_name.data)) team_id = Team.find_team_id(sel_team_name) p = Player(form.name.data, form.number.data, form.position.data, team_id[0]) db.session().add(p) db.session().commit() return redirect(url_for("players_index"))
class PlayerForm(FlaskForm): name = StringField("Name (First Surname)", [validators.InputRequired()]) def validate_name(form, field): first_last = str(field.data).split(" ") if first_last.__len__() < 2: raise validators.ValidationError( 'Input: Firstname Lastname (space in between)') elif len(first_last[0]) < 2 or len(first_last[1]) < 2: raise validators.ValidationError( 'First or last name must be at least 2 characters') number = StringField("Number") def validate_number(form, field): int_number = int(field.data) if not (0 < int_number and int_number < 100): raise validators.ValidationError('Number must be between 1 and 99') position = StringField("Position (VL,OL,KH,VP,OP,MV)") def validate_position(form, field): positions = ['VL', 'OL', 'KH', 'VP', 'OP', 'MV'] if not (str(field.data) in positions): raise validators.ValidationError( 'Position must be: VL,OL,KH,VP,OP,MV') team_choices = Team.all_team_data() team_name = SelectField(u'Team name', choices=team_choices, coerce=int) def validate_team_name(form, field): sel_team_name = str(dict(field.choices).get(field.data)) a = Team.find_team_id(sel_team_name) if not a: raise validators.ValidationError( 'Team name must match with team names already in database (list teams to see options)' ) class Meta: csrf = False
def account_delete(account_id): # remove teams from matches and contests, and delete them for team_id in Team.find_teams_by_coach(account_id): Match.delete_match_history(team_id) ContestTeam.remove_team_from_all_contests(team_id) t = Team.query.get(team_id) db.session.delete(t) db.session.commit() # empty and delete contests for contest_id in Contest.find_contests_by_coach(account_id): ContestTeam.remove_all_teams_from_contest(contest_id) c = Contest.query.get(contest_id) db.session.delete(c) db.session.commit() # delete account c = Coach.query.get(account_id) db.session.delete(c) db.session.commit() return redirect(url_for("accounts_index"))
def teams_create(): form = TeamForm(request.form) if not form.validate(): return render_template("teams/list.html", teams=Team.find_users_teams(current_user.id), units=Team.units_in_teams(current_user.id), unit_numbers=Team.number_of_units_in_teams( current_user.id), form=form) t = Team(form.name.data) t.account_id = current_user.id db.session.add(t) db.session().commit() return redirect(url_for("teams_index"))
def team_owners(): return render_template("teams/owners.html", teams=Team.team_owners())
def penalties_form(match_id, team_name): team_id = Team.find_team_id(team_name) return render_template("penalties/new.html", form=PenaltyForm(team_id[0]), match_id=match_id, team_id=team_id[0])
def teams_index(): return render_template("teams/list.html", teams=Team.find_teams_and_coaches())
def goals_form(match_id, team_name): team_id = Team.find_team_id(team_name) return render_template("goals/new.html", form=GoalForm(team_id[0]), match_id=match_id, team_id=team_id[0])
def signup_form(contest_id): form = TeamSignup() form.find_user_teams(teams=Team.find_eligible_teams_for_contest( contest_id=contest_id, coach_id=current_user.get_id())) return render_template("contestteam/new.html", contest_id = contest_id, form=form)
def teams_statistics(): return render_template("teams/statistics.html", goals=Team.team_goals(), penalties=Team.team_penalties())