Exemplo n.º 1
0
def create_team():
    if g.user.team:
        return redirect(url_for('team', team_id=g.user.team.id))
    form = CreateTeamForm()
    if form.validate_on_submit():
        new_team = Team(form.name.data, form.description.data)
        g.user.team = new_team
        db.session.add(new_team)
        db.session.add(g.user)
        db.session.commit()
        flash('Team created successfully.', category='success')
        return redirect(url_for('team', team_id=g.user.team.id))
    return render_template('create_team.html', form=form)
Exemplo n.º 2
0
def create_team():
    """
    A user creates a new team and sets some team parameters
    The suer by default becomes the team leader
    """

    from forms import CreateTeamForm
    form = CreateTeamForm()

    player_memberships = Membership.query.filter_by(user_id=g.user.id).all()
    if len(player_memberships) == 3:
        flash('You are in three teams already. Chill.', "warning")
        return redirect(url_for('user_page', steam_id=g.user.steam_id))

    from consts import TIME_ZONES_DICT

    if form.validate_on_submit():
        team = Team()
        team.name = form.team_name.data
        team.skill_level = form.team_skill_level.data
        team.time_zone = form.team_time_zone.data
        team.week_days = form.read_scrim_days()
        team.type = form.team_type.data
        db.session.add(team)
        db.session.commit()

        membership = Membership()
        membership.team_id = team.id
        membership.user_id = g.user.id
        membership.role = "Captain"
        db.session.add(membership)
        db.session.commit()

        return redirect(url_for('user_page', steam_id=g.user.steam_id))
    else:
        return render_template('create_team.html', create_team_form=form)