def edit_team(team_id): if not g.user.is_admin and g.user.team is None: flash("You are not a part of a team yet!") return redirect(url_for('index')) if not g.user.is_admin and g.user.team_id != team_id: flash("You don't have permission to edit that.") return redirect(url_for('index')) # Look up the team and create the form we need team = Team.query.get_or_404(team_id) form = EditTeamForm(obj=team) if form.validate_on_submit(): form.populate_obj(team) db.session.merge(team) db.session.commit() # Only update the icon if we need to if form.icon.data: # Store the filename we have for them team.icon_name = team_icons.save( form.icon.data, name='%d.' % team.id) db.session.merge(team) db.session.commit() return redirect(url_for('index')) return render_template('form.html', form=form)
def create_team(): if g.user.team is not None: flash("You are already a part of a team!") return redirect(url_for('index')) team = Team() form = TeamForm(obj=team) if form.validate_on_submit(): form.populate_obj(team) db.session.add(team) db.session.commit() # Store the filename we have for them team.icon_name = team_icons.save(form.icon.data, name='%d.' % team.id) db.session.merge(team) # Update the current user to be in this team g.user.team_id = team.id db.session.merge(g.user) db.session.commit() return redirect(url_for('index')) return render_template('create_team.html', form=form, title='Create Team')