def edit_team():
    team_id = request.get_json()['id']
    new_team_name = request.get_json()['name']
    if request.get_json()['new_member'] != '' and (
            new_team_name == Team.get_team_by_id(team_id).get_name()
            or not Team.get_team_by_name(new_team_name)):
        new_member = request.get_json()['new_member']
        Team.get_team_by_id(team_id).set_name(new_team_name)
        student_id = int(''.join(filter(lambda x: x.isdigit(), new_member)))
        if Student.get_student_team_id(student_id):
            Team.get_team_by_id(team_id).relocate_member(student_id)
        else:
            Team.get_team_by_id(team_id).add_member(
                User.get_user_by_id(student_id))
        student_name = Student.get_user_by_id(student_id).get_name()
        edited_data = (new_team_name, student_name, student_id)
        edited_data_json = json.dumps(edited_data)
        return edited_data_json
    elif new_team_name == Team.get_team_by_id(
            team_id).get_name() or not Team.get_team_by_name(new_team_name):
        Team.get_team_by_id(team_id).set_name(new_team_name)
        edited_data = new_team_name
        edited_data_json = json.dumps(edited_data)
        return edited_data_json
    else:
        return ''
def add_team():
    team_name = request.get_json()
    if not Team.get_team_by_name(team_name):
        team = Team.add_team(team_name)
        team_in_json = json.dumps(team.__dict__, ensure_ascii=False)
        return team_in_json
    return ""
def team_new():
    if request.method == "POST":
        team_name = request.form['name']
        if not Team.get_team_by_name(team_name):
            Team.add_team(team_name)
            return redirect(url_for('teams_ctrl.teams'))
        flash('Team name already in use')
    return render_template("add_team_form.html",
                           title="Add new team",
                           mainmenu=mainmenu)