def add_team(event_id): event = Event.query.get(event_id) teamform = TeamForm() if event.teams.count() >= event.max_team: flash('Sorry, no more space available.') return redirect(url_for('event', event_id = event_id)) elif teamform.validate_on_submit(): user = g.user team = Team(user_id = user.id, event_id = event_id, name = request.form.get('teamname')) sqldb.session.add(team) sqldb.session.commit() members = request.form.getlist('member') for m in members: if m!="": member = Member(team_id = team.id, member_name = m) sqldb.session.add(member) sqldb.session.commit() return redirect(url_for('event', event_id = event_id)) return render_template("team.html", team = None, form = teamform, n = event.max_member_per_team)
def edit_team(team_id): team = Team.query.get(team_id) user = g.user teamform = TeamForm() if user.id != team.user_id: flash('Only the team creator can update the team information.') elif teamform.validate_on_submit(): team.name = request.form.get('teamname') for m in team.members: sqldb.session.delete(m) members = request.form.getlist('member') for m in members: if m!="": member = Member(team_id = team.id, member_name = m) sqldb.session.add(member) sqldb.session.commit() return redirect(url_for('team', team_id = team_id)) return render_template("team.html", team = team, form = teamform, n = team.event.max_member_per_team)
def edit_team(team_id): """Editing a teams id and photo""" if not g.user: flash("Access unauthorized.", "danger") return redirect('/') user = g.user team = Team.query.get(team_id) form = TeamForm(obj=team) if form.validate_on_submit(): try: team.name = form.name.data team.team_image = form.team_image.data or Team.team_image.default.arg db.session.commit() except IntegrityError: db.session.rollback() form.team_name.errors = ["Team name already exists"] return render_template('users/createTeam.html', form=form) return redirect(f'/users/{user.username}') return render_template('users/editTeam.html', form=form, team=team)
def create_new_team(): """We're gonna show a form and handle the business of folks who already registered,""" if not g.user: flash("Access unauthorized.", "danger") return redirect('/') user = g.user form = TeamForm() if form.validate_on_submit(): try: team = Team(name=form.name.data, team_image=form.team_image.data or Team.team_image.default.arg, user_id=user.username) db.session.add(team) db.session.commit() except IntegrityError: db.session.rollback() form.team_name.errors = ["Team name already exists"] return render_template('users/createTeam.html', form=form) return redirect(f'/users/{user.username}') return render_template('users/createTeam.html', form=form)
def add(): form = TeamForm() if request.method == 'POST' and form.validate_on_submit(): team = Team() form.populate_obj(team) db.session.add(team) db.session.commit() return redirect(url_for(".index")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("teams/team_form.html", form=form, id=None)
def team_setting(team_id): team = Team.query.get(team_id) if not current_user.in_team(team_id): abort(404) form = TeamForm(user=current_user, team_id=team.id, name=team.name) if form.validate_on_submit(): if form.team.status == 0: return redirect(url_for('team_show', team_id=form.team.id)) else: flash(u'团队已删除') return redirect(url_for('team_index')) return render_template('team/form.html', form=form, team=team)
def edit_team(team_id=None): model = get_object_or_404(Team, Team.id == team_id) if g.user not in model.members and not g.user.is_admin(): return redirect(url_for('index')) form = TeamForm(obj=model) if form.validate_on_submit(): form.populate_obj(model) db.session.add(model) db.session.commit() flash('Team updated', category='success') return redirect(url_for('team', team_id=model.id)) return render_template('edit_team.html', team=model, form=form)
def edit(team_id): team = Team.query.get(team_id) form = TeamForm(obj=team) del form.number if request.method == 'POST' and form.validate_on_submit(): form.populate_obj(team) db.session.commit() return redirect(url_for(".index")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("teams/team_form.html", form=form, number=team.number, id=team.id)
def create_team(): team_form = TeamForm() team_form.course_id.choices = course_choices() team_form.project_id.choices = all_project_choices() if team_form.validate_on_submit(): rowcount = db.create_team({ 'name': team_form.name.data, 'course_id': team_form.course_id.data, 'project_id': team_form.project_id.data }) if rowcount == 1: flash('Team {} created'.format(team_form.name.data)) return redirect(url_for('all_teams')) return render_template('teams/add.html', form=team_form)
def edit_team(team_id): if not current_user.is_admin and not current_user.team_id == team_id: abort(403) team = Team.query.get_or_404(team_id) form = TeamForm() if form.validate_on_submit(): team.name = form.name.data team.first_teammate_name = form.first_teammate_name.data team.second_teammate_name = form.second_teammate_name.data db.session.commit() flash('!פרטי הצוות עודכנו בהצלחה', 'success') return redirect(url_for('view_team', team_id=team.id)) elif request.method == 'GET': form.name.data = team.name form.first_teammate_name.data = team.first_teammate_name form.second_teammate_name.data = team.second_teammate_name return render_template('/edit_team.html', form=form, team_id=team_id)
def new(): form = TeamForm() if request.method == 'POST': if form.validate_on_submit(): name = request.form['name'] email = request.form['email'] mate_email = request.form['mate_email'] password = hashlib.md5( request.form['password'].encode('utf-8')).hexdigest() my_team = Team.query.filter_by(name=name).first() if not my_team: if request.form['password'] == request.form['password2']: my_team = Team(request.form['name'], request.form['email'], request.form['mate_email'], request.form['password']) db.session.add(my_team) try: db.session.commit() # Envio de email msg = Message("Hello", sender="*****@*****.**", recipients=[my_team.email]) link_token = f'http://localhost:5000/activate/{my_team.token}' msg.html = render_template('emails/access.html', link_token=link_token) mail.send(msg) # Informamos al usuario flash('Confirmar email en su bandeja de entrada', 'success') except: db.session.rollback() flash('Disculpe, ha ocurrido un error', 'danger') return redirect(url_for('new')) else: flash('Las contraseñas no coinciden', 'danger') else: flash('El email ya está registrado', 'danger') else: todos_errores = form.errors.items() for campo, errores in todos_errores: for error in errores: flash(error, 'danger') return render_template('items/new.html', form=form)
def new_team(): formpage = TeamForm() if formpage.validate_on_submit(): sport = formpage.sport.data team = Teams( name=formpage.name.data, description=formpage.description.data, members=current_user.name + ' Cel: ' + current_user.phone + ' ', players_number=formpage.players_number.data, vacant=formpage.players_number.data - 1, sport=formpage.sport.data, begginer=current_user, ) db.session.add(team) db.session.commit() flash('Your new team has been created!', 'success') return redirect(url_for(sport)) return render_template('new_team.html', title='Create New Team', formpage=formpage)
def teamname(): #Determinant for current season max_teams = 0 teams = None team_count = 0 current_season = model.session.query(model.SeasonCycle).\ order_by(model.SeasonCycle.id.desc()).first() print current_season.id if current_season is not None: # created teams by cycle.id teams = model.session.query(model.Team).\ filter(model.Team.seasoncycle == current_season.id).\ all() team_count = len(teams) # number of teams based on season cycle max_teams = current_season.num_of_teams #Create Team Names form = TeamForm() if form.validate_on_submit(): new_team = model.session.\ add(model.Team(teamname= form.teamname.data, seasoncycle= current_season.id)) model.session.commit() return redirect('team_names') return render_template('team_names.html', title='Teamname', form=form, max_teams=max_teams, teams=teams, team_count=team_count, current_season=current_season)
def teamname(): #Determinant for current season max_teams = 0 teams = None team_count = 0 current_season = model.session.query(model.SeasonCycle).\ order_by(model.SeasonCycle.id.desc()).first() print current_season.id if current_season is not None: # created teams by cycle.id teams = model.session.query(model.Team).\ filter(model.Team.seasoncycle == current_season.id).\ all() team_count= len(teams) # number of teams based on season cycle max_teams = current_season.num_of_teams #Create Team Names form = TeamForm() if form.validate_on_submit(): new_team = model.session.\ add(model.Team(teamname= form.teamname.data, seasoncycle= current_season.id)) model.session.commit() return redirect('team_names') return render_template('team_names.html', title='Teamname', form=form, max_teams=max_teams, teams= teams, team_count= team_count, current_season=current_season)
def team_create(): form = TeamForm(user=current_user) if form.validate_on_submit(): return redirect(url_for('team_show', team_id=form.team.id)) return render_template('team/form.html', form=form)