示例#1
0
def add_server(team_id=0):
    if not g.user.is_team_leader(team_id):
        flash(u'You must be a team leader to add a server.', 'error')
        return redirect(url_for('teams.my_teams'))

    servers = Server.query.\
            filter_by(team_id=team_id).\
            order_by(Server.name.asc()).\
            all()

    api = request.values.get('api') == '1'

    form = ServerForm()
    form.name.validators[0].values = [s.name for s in servers]
    if form.validate_on_submit():
        server = Server(team_id=team_id,
                        name=form.name.data,
                        address=form.address.data)
        db.session.add(server)
        db.session.commit()
        flash(u'The server was successfully added.', 'success')

        if api:
            return jsonify(success=True,
                           server_id=server.id,
                           csrf=form.csrf_token.data,
                           server_name=server.name)

        if form.f.data == 'add_match':
            return redirect(url_for('matches.add', new_server_id=server.id))
        elif form.f.data:
            return redirect(
                url_for('matches.show',
                        action='edit',
                        match_id=int(form.f.data),
                        new_server_id=server.id))

        return redirect(url_for('servers', team_id=team_id))

    form.f.data = request.values.get('f') or ''

    return rt('team_admin/server_form.html',
              page={
                  'top': 'my_teams',
                  'sub': 'servers'
              },
              team={
                  'id': team_id,
                  'name': g.user.teams[team_id].name
              },
              adding=True,
              form=form)
示例#2
0
def server(team_id, server_id, action):
    if not g.user.is_team_leader(team_id):
        flash(u'You must be a team leader to add a server.', 'error')
        return redirect(url_for('teams.my_teams'))

    server = Server.query.filter_by(id=server_id).first()

    if not server or not g.user.is_team_leader(server.team_id):
        flash(u'Server not found.', 'error')
        return redirect(url_for('teams.my_teams'))

    if action == 'edit':
        servers = Server.query.\
                filter_by(team_id=team_id).\
                order_by(Server.name.asc()).\
                all()

        form = ServerForm(request.form, obj=server)
        form.name.validators[0].values = [ s.name for s in servers if s.id != \
                server_id ]

        if form.validate_on_submit():
            form.populate_obj(server)
            db.session.commit()
            flash(u'The server was successfully updated.', 'success')
        else:
            return rt('team_admin/server_form.html',
                      team={
                          'id': team_id,
                          'name': g.user.teams[team_id].name
                      },
                      page={
                          'top': 'my_teams',
                          'sub': 'servers'
                      },
                      server_id=server_id,
                      adding=False,
                      form=form)
    elif action == 'delete':
        if request.method == 'POST':
            db.session.delete(server)
            db.session.commit()
            flash(u'The server was successfully deleted.', 'success')

    return redirect(url_for('servers', team_id=team_id))
示例#3
0
def add_server(team_id=0):
    if not g.user.is_team_leader(team_id):
        flash(u'You must be a team leader to add a server.', 'error')
        return redirect(url_for('teams.my_teams'))

    servers = Server.query.\
            filter_by(team_id=team_id).\
            order_by(Server.name.asc()).\
            all()

    api = request.values.get('api') == '1'

    form = ServerForm()
    form.name.validators[0].values = [ s.name for s in servers ]
    if form.validate_on_submit():
        server = Server(team_id=team_id,
                        name=form.name.data,
                        address=form.address.data)
        db.session.add(server)
        db.session.commit()
        flash(u'The server was successfully added.', 'success')

        if api:
            return jsonify(success=True, server_id=server.id,
                    csrf=form.csrf_token.data,
                    server_name=server.name)

        if form.f.data == 'add_match':
            return redirect(url_for('matches.add', new_server_id=server.id))
        elif form.f.data:
            return redirect(url_for('matches.show', action='edit',
                match_id=int(form.f.data), new_server_id=server.id))

        return redirect(url_for('servers',team_id=team_id))

    form.f.data = request.values.get('f') or ''

    return rt('team_admin/server_form.html',
            page={'top':'my_teams', 'sub':'servers'},
            team={'id':team_id,'name':g.user.teams[team_id].name},
            adding=True, form=form)
示例#4
0
def server(team_id, server_id, action):
    if not g.user.is_team_leader(team_id):
        flash(u'You must be a team leader to add a server.', 'error')
        return redirect(url_for('teams.my_teams'))

    server = Server.query.filter_by(id=server_id).first()

    if not server or not g.user.is_team_leader(server.team_id):
        flash(u'Server not found.', 'error')
        return redirect(url_for('teams.my_teams'))

    if action == 'edit':
        servers = Server.query.\
                filter_by(team_id=team_id).\
                order_by(Server.name.asc()).\
                all()

        form = ServerForm(request.form, obj=server)
        form.name.validators[0].values = [ s.name for s in servers if s.id != \
                server_id ]

        if form.validate_on_submit():
            form.populate_obj(server)
            db.session.commit()
            flash(u'The server was successfully updated.', 'success')
        else:
            return rt('team_admin/server_form.html',
                    team={'id':team_id, 'name':g.user.teams[team_id].name},
                    page={'top':'my_teams', 'sub':'servers'},
                    server_id=server_id,
                    adding=False, form=form)
    elif action == 'delete':
        if request.method == 'POST':
            db.session.delete(server)
            db.session.commit()
            flash(u'The server was successfully deleted.', 'success')

    return redirect(url_for('servers',team_id=team_id))