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/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"))