def add_forum_bot(team_id=0): if not team_id or not g.user.is_team_leader(team_id): flash(u'You must be a team leader to add a forum helper.', 'error') return redirect(url_for('teams.my_teams')) form = ForumBotForm() form.game_id.choices = [ (-1, "Any match is added") ] form.game_id.choices += [ (game.id, "A %s match is added" % game.name) for \ game in Game.query.all() ] if form.validate_on_submit(): if form.game_id.data <= 0: game_id = None else: game_id = form.game_id.data forum_bot = ForumBot(team_id=team_id, game_id=game_id, type=form.type.data, url=form.url.data, forum_id=form.forum_id.data, user_name=form.user_name.data, password=form.password.data) db.session.add(forum_bot) db.session.commit() flash(u'The forum helper was successfully added.', 'success') return redirect(url_for('forum_bots',team_id=team_id)) return rt('team_admin/forum_bot_form.html', team={'id' : team_id, 'name':g.user.teams[team_id].name}, page={'top':'my_teams', 'sub':'forum_bots'}, adding=True, form=form)
def forum_bot(team_id, forum_bot_id, action): if not g.user.is_team_leader(team_id): flash(u'You must be a team leader to add a forum helper.', 'error') return redirect(url_for('teams.my_teams')) forum_bot = ForumBot.query.filter_by(id=forum_bot_id).first() if not forum_bot or team_id != forum_bot.team_id: flash(u'Forum helper not found.', 'error') return redirect(url_for('teams.my_teams')) if action == 'edit': form = ForumBotForm(request.form, obj=forum_bot) # can't change the team to which the forum_bot belongs when editing form.game_id.choices = [(-1, "Any match is added")] form.game_id.choices += [ (game.id, "A %s match is added" % game.name) for \ game in Game.query.all() ] if form.validate_on_submit(): if form.game_id.data <= 0: form.game_id.data = None else: form.game_id.data = form.game_id.data form.populate_obj(forum_bot) db.session.commit() flash(u'The forum helper was successfully updated.', 'success') else: return rt('team_admin/forum_bot_form.html', page={ 'top': 'my_teams', 'sub': 'forum_bots' }, team={ 'id': team_id, 'name': g.user.teams[team_id].name }, forum_bot_id=forum_bot_id, adding=False, form=form) elif action == 'delete': if request.method == 'POST': db.session.delete(forum_bot) db.session.commit() flash(u'The forum helper was successfully deleted.', 'success') return redirect(url_for('forum_bots', team_id=team_id))
def forum_bot(team_id,forum_bot_id, action): if not g.user.is_team_leader(team_id): flash(u'You must be a team leader to add a forum helper.', 'error') return redirect(url_for('teams.my_teams')) forum_bot = ForumBot.query.filter_by(id=forum_bot_id).first() if not forum_bot or team_id != forum_bot.team_id: flash(u'Forum helper not found.', 'error') return redirect(url_for('teams.my_teams')) if action == 'edit': form = ForumBotForm(request.form, obj=forum_bot) # can't change the team to which the forum_bot belongs when editing form.game_id.choices = [ (-1, "Any match is added") ] form.game_id.choices += [ (game.id, "A %s match is added" % game.name) for \ game in Game.query.all() ] if form.validate_on_submit(): if form.game_id.data <= 0: form.game_id.data = None else: form.game_id.data = form.game_id.data form.populate_obj(forum_bot) db.session.commit() flash(u'The forum helper was successfully updated.', 'success') else: return rt('team_admin/forum_bot_form.html', page={'top':'my_teams', 'sub':'forum_bots'}, team={'id' : team_id, 'name':g.user.teams[team_id].name}, forum_bot_id=forum_bot_id, adding=False, form=form) elif action == 'delete': if request.method == 'POST': db.session.delete(forum_bot) db.session.commit() flash(u'The forum helper was successfully deleted.', 'success') return redirect(url_for('forum_bots', team_id=team_id))
def add_forum_bot(team_id=0): if not team_id or not g.user.is_team_leader(team_id): flash(u'You must be a team leader to add a forum helper.', 'error') return redirect(url_for('teams.my_teams')) form = ForumBotForm() form.game_id.choices = [(-1, "Any match is added")] form.game_id.choices += [ (game.id, "A %s match is added" % game.name) for \ game in Game.query.all() ] if form.validate_on_submit(): if form.game_id.data <= 0: game_id = None else: game_id = form.game_id.data forum_bot = ForumBot(team_id=team_id, game_id=game_id, type=form.type.data, url=form.url.data, forum_id=form.forum_id.data, user_name=form.user_name.data, password=form.password.data) db.session.add(forum_bot) db.session.commit() flash(u'The forum helper was successfully added.', 'success') return redirect(url_for('forum_bots', team_id=team_id)) return rt('team_admin/forum_bot_form.html', team={ 'id': team_id, 'name': g.user.teams[team_id].name }, page={ 'top': 'my_teams', 'sub': 'forum_bots' }, adding=True, form=form)