Пример #1
0
def manageteam(id):
    project = Project.query.filter_by(id=id).first_or_404()
    form = TeamForm()
    team = Team.query.filter_by(project_id=int(id)).order_by(
        Team.role.asc()).all()
    if form.validate_on_submit():
        member = Team(role=form.role.data,
                      firstname=form.fName.data,
                      lastname=form.lName.data,
                      email=form.email.data,
                      project_id=project.id)
        exists = Team.query.filter_by(project_id=int(id),
                                      role=form.role.data).first()
        if not exists:
            db.session.add(member)
            db.session.commit()
            flash('Team Member {} {} added'.format(form.fName.data,
                                                   form.lName.data))
        else:
            db.session.commit()
            flash('Team Member {} {} updated'.format(form.fName.data,
                                                     form.lName.data))
        return redirect(url_for('manageteam', id=project.id))
    return render_template('manageteam.html',
                           title='Manage Team Members',
                           team=team,
                           form=form,
                           project=project)
Пример #2
0
def _create_team(request):
    team = Team()
    form = TeamForm(request.form)
    form.populate_obj(team)
    db.session.add(team)
    db.session.commit()
    return team
Пример #3
0
def flumride_submit():
    if not logic.is_submit_open():
        milliseconds = logic.get_milliseconds_until_submit_opens()
        return render_template("flumride/countdown.html",
                               milliseconds=milliseconds)

    remaining_tickets_for_type = [
        logic.get_number_of_tickets_for_this_type_left(ind)
        for ind, ticket in enumerate(app.config['FLUMRIDE']['ticket_types'])
    ]

    if sum(remaining_tickets_for_type) <= 0 or logic.has_submit_closed():
        return render_template("flumride/submit_temp_closed.html")

    form = TeamForm()
    if form.validate_on_submit():
        team = _create_team(request)
        mail.send(team.email, team.price, team.name)
        return render_template("flumride/confirmation.html", team=team)
    else:
        #Need to fetch remaing tickets again since the number may have changed if a user stayed on the page a long time
        remaining_tickets_for_type = [
            logic.get_number_of_tickets_for_this_type_left(ind) for ind, ticket
            in enumerate(app.config['FLUMRIDE']['ticket_types'])
        ]
        number_of_non_sfs_left = logic.get_number_of_non_sfs_left()
        return render_template(
            "flumride/submit.html",
            form=form,
            number_of_non_sfs_left=number_of_non_sfs_left,
            remaining_tickets_for_type=remaining_tickets_for_type)
Пример #4
0
def team_request(tour_id: int):
    form = TeamForm()
    session = create_session()
    tour = session.query(Tournament).get(tour_id)
    if not tour:
        abort(404)
    try:
        if form.validate_on_submit():  # Validate posted data
            team = Team().fill(
                name=form.name.data,
                motto=form.motto.data,
                trainer_id=current_user.id,
                tournament_id=tour.id,
            )
            emails = set()
            vk_uids = []
            for field in form.players.entries:  # Check players
                email = field.data.lower()
                if email in emails:
                    field.errors.append("Участник указан несколько раза")
                    raise ValidationError
                emails.add(email)
                user = session.query(User).filter(User.email == email).first()
                if not user:
                    field.errors.append("Пользователь не найден.")
                    raise ValidationError
                team.players.append(user)
                if user.integration_with_VK:
                    vk_uids.append(user.id)
            session.add(team)
            session.commit()

            # Send notifications to players
            msg = Message(subject='Участие в турнире MatBoy',
                          recipients=list(emails),
                          sender=config.MAIL_DEFAULT_SENDER,
                          html=render_template('mails/email/invite_team.html',
                                               team=team,
                                               tour=tour))
            thr_email = Thread(target=send_message, args=[msg])
            thr_vk = Thread(target=bot.notification_message,
                            args=[
                                render_template('mails/vk/invite_team.vkmsg',
                                                team=team,
                                                tour=tour), vk_uids
                            ])
            thr_email.start()
            thr_vk.start()
            return redirect(team.link)
    except ValidationError:
        pass

    return render_template("team_form.html",
                           edit=False,
                           tour=tour,
                           form=form,
                           menu=make_menu(session,
                                          tour_id=tour_id,
                                          now='Командная заявка'))
Пример #5
0
def add_team(request):
    if request.user.is_authenticated:
        user = request.user
        form = TeamForm(request.POST)
        if form.is_valid():
            todo = form.save(commit=False)
            todo.owner = user
            todo.save()
            todo.users.add(user)
            todo.save()
            return redirect("/teams")
Пример #6
0
def teams_post(id):
    form = TeamForm()
    user = User.query.get(id)
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        team = Team(
            teamName=form.data['teamName'],
        )
        team.users.append(user)
        db.session.add(team)
        db.session.commit()
        return team.to_dict()
    return "Oops, something went wrong!"
Пример #7
0
def edit_team(tour_id: int, team_id: int):
    form = TeamForm()
    session = create_session()
    team = session.query(Team).get(team_id)
    if not team:
        abort(404)
    tour = team.tournament
    if tour.id != tour_id:
        abort(404)
    if not tour.have_permission(current_user):
        abort(403)

    try:
        if form.validate_on_submit():  # Validate posted data
            team.fill(
                name=form.name.data,
                motto=form.motto.data,
            )
            emails = set()
            team.players.clear()
            for field in form.players.entries:  # Check players
                email = field.data.lower()
                if email in emails:
                    field.errors.append("Участник указан несколько раза")
                    raise ValidationError
                emails.add(email)
                user = session.query(User).filter(User.email == email).first()
                if not user:
                    field.errors.append("Пользователь не найден.")
                    raise ValidationError
                team.players.append(user)
            session.commit()
            return redirect(team.link)
    except ValidationError:
        pass

    if request.method.upper() == 'GET':
        form.name.data = team.name
        form.motto.data = team.motto
        form.players.entries.clear()
        form.players.last_index = -1
        for p in team.players:
            form.players.append_entry(p.email)

    return render_template("team_form.html",
                           edit=True,
                           tour=tour,
                           form=form,
                           menu=make_menu(session,
                                          team_id=team_id,
                                          now='Изменить данные команды'))
Пример #8
0
def add_team():
    form = TeamForm(request.form)

    if form.validate_on_submit():
        team = Team()
        team.fio = form.fio.data
        file = request.files['avatar']
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        team.avatar = filename
        db.session.add(team)
        db.session.commit()
        return redirect('/')
    return render_template('add_team.html', form=form)
Пример #9
0
def predict():
    form = TeamForm()
    players = [
        form.player1.data, form.player2.data, form.player3.data,
        form.player4.data, form.player5.data
    ]
    champs = [
        form.champ1.data, form.champ2.data, form.champ3.data, form.champ4.data,
        form.champ5.data
    ]
    pch = [(players[i], champs[i]) for i in range(len(players))]
    if form.validate_on_submit():
        flash('input is {}'.format(pch))
        return redirect('/predict')  #send input to model as list of tuples
    return render_template('team.html', form=form)
Пример #10
0
def flumride_edit_team(id):
    team = Team.get(id)
    assert team

    if request.method == 'POST':
        form = TeamForm(request.form)
        team.name = form.name.data
        team.email = form.email.data
        team.city = form.city.data
        team.slogan = form.slogan.data
        team.has_payed = form.has_payed.data
        db.session.commit()
        return redirect(url_for('flumride_teams', _anchor=team.id))
    else:
        form = TeamForm(obj=team)
        return render_template("flumride/edit_team.html", form=form)
Пример #11
0
def teams(request):
    if request.user.is_authenticated:
        user = request.user
        form = TeamForm()
        teams = Team.objects.filter(owner=user).order_by('-title')
        context = {'form': form, 'teams': teams}
        return render(request, 'teams.html', context=context)
Пример #12
0
def register_team():
    form = TeamForm()
    if form.validate_on_submit():
        team = Team.query.filter_by(name=form.team_name.data).first()
        if team is not None:
            flash('This team already exists')
            return redirect(url_for('register_team'))

        members = [Member(name=form.team_member_1.data)]
        if form.team_member_2.data != '':
            members.append(Member(name=form.team_member_2.data))
        if form.team_member_3.data != '':
            members.append(Member(name=form.team_member_3.data))
        if form.team_member_4.data != '':
            members.append(Member(name=form.team_member_4.data))

        team = Team(name=form.team_name.data, members=members)
        db.session.add(team)
        db.session.commit()
        return redirect(url_for('overview'))
    return render_template('register_team.html', title='Sign In', form=form)
Пример #13
0
def predict():
    form = TeamForm()
    bplayers = [
        form.blueplayer1.data, form.blueplayer2.data, form.blueplayer3.data,
        form.blueplayer4.data, form.blueplayer5.data
    ]
    bchamps = [
        form.bluechamp1.data, form.bluechamp2.data, form.bluechamp3.data,
        form.bluechamp4.data, form.bluechamp5.data
    ]
    broles = [
        form.bluerole1.data, form.bluerole2.data, form.bluerole3.data,
        form.bluerole4.data, form.bluerole5.data
    ]

    rplayers = [
        form.redplayer1.data, form.redplayer2.data, form.redplayer3.data,
        form.redplayer4.data, form.redplayer5.data
    ]
    rchamps = [
        form.redchamp1.data, form.redchamp2.data, form.redchamp3.data,
        form.redchamp4.data, form.redchamp5.data
    ]
    rroles = [
        form.redrole1.data, form.redrole2.data, form.redrole3.data,
        form.redrole4.data, form.redrole5.data
    ]

    bpch = [[broles[i], "100", bchamps[i], bplayers[i]]
            for i in range(len(bplayers))]
    rpch = [[rroles[i], "200", rchamps[i], rplayers[i]]
            for i in range(len(rplayers))]
    pch = []
    pch += bpch
    pch += rpch
    if form.validate_on_submit():
        result = get_result(pch)
        flash('The chance Blue team win is {}'.format(result))
        return redirect('/predict')  #send input to model as list of tuples
    return render_template('team.html', form=form)
Пример #14
0
def team_request(tour_id: int):
    form = TeamForm()
    session = create_session()
    tour = session.query(Tournament).get(tour_id)
    if not tour:
        abort(404)
    if form.validate_on_submit():
        team = Team().fill(
            name=form.name.data,
            motto=form.motto.data,
            trainer_id=current_user.id,
            tournament_id=tour.id,
        )

        for email in form.players.data:
            user = session.query(User).filter(User.email == email).first()
            if not user:
                return render_template("team_request.html", tour=tour, form=form)
            team.players.append(user)
        session.add(team)
        session.commit()
        return redirect(f"/team/{team.id}")

    return render_template("team_request.html", tour=tour, form=form)