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))
Example #2
0
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())
Example #4
0
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"))
Example #5
0
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"))
Example #6
0
 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"))
Example #8
0
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))
Example #9
0
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)
Example #11
0
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)
Example #12
0
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"))
Example #13
0
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'))
Example #14
0
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"))
Example #15
0
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
Example #16
0
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"))
Example #18
0
def team_owners():
    return render_template("teams/owners.html", teams=Team.team_owners())
Example #19
0
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])
Example #20
0
def teams_index():
    return render_template("teams/list.html",
                           teams=Team.find_teams_and_coaches())
Example #21
0
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])
Example #22
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)
Example #23
0
def teams_statistics():
    return render_template("teams/statistics.html",
                           goals=Team.team_goals(),
                           penalties=Team.team_penalties())