示例#1
0
文件: views.py 项目: alexsclim/Felist
def createteam():
    conn = mysql.connection
    cur = conn.cursor()
    query_service = QueryService(cur)
    form = CreateTeamForm(request.form)

    if request.method == 'POST':
        if form.validate() == False:
            error = "Validation failed"
            return render_template('new_team.html', form=form, error=error)
        team_name = form.name.data
        practice_cost = form.practice_cost.data
        city = form.city.data
        province = form.province.data
        username = session['username']

        last_id = query_service.get_last_team_id()
        team_id = last_id + 1

        try:
            query_service.create_team(conn, team_id, team_name, practice_cost,
                                      username, city, province)
            flash("Team Created!")
        except Exception as e:
            flash("There was an error creating your team.")
            return redirect(url_for('createteam'))

        return redirect(url_for('dashboard'))

    elif request.method == 'GET':
        return render_template('new_team.html', form=form)
示例#2
0
def teams_create(request, competition = None):
	"""
	Create the team in the competition
	"""
	c = getAuthValues(request, {})
	if c["auth_name"] != "auth_team_white":
		return HttpResponseRedirect("/")
	c["action"] = "create"
	c["form"] = CreateTeamForm()
	c["comp_obj"] = Competition.objects.get(compurl = competition)
	c.update(csrf(request))
	if request.method != "POST":
		# Get a list of the services
		c["service_configs_list"] = buildTeamServiceConfigForms(c["comp_obj"].compid)
		return render_to_response('CompConfig/teams_create-edit.html', c)
	form_dict = request.POST.copy()
	form_dict["compid"] = c["comp_obj"].compid
	form_dict["score_configs"] = buildTeamServiceConfigDict(c["comp_obj"].compid, form_dict)
	# Clean network address
	if form_dict['networkaddr'][-1] == ".":
		form_dict['networkaddr'] = form_dict['networkaddr'][:-1]
	if form_dict['networkaddr'][0] == ".":
		form_dict['networkaddr'] = form_dict['networkaddr'][1:]
	team = CreateTeamForm(form_dict)
	if not team.is_valid():
		return render_to_response('CompConfig/teams_create-edit.html', c)
	team.save()
	return HttpResponseRedirect("/admin/competitions/%s/teams/" % competition)
示例#3
0
def create_team():
    if g.user.team:
        return redirect(url_for('team', team_id=g.user.team.id))
    form = CreateTeamForm()
    if form.validate_on_submit():
        new_team = Team(form.name.data, form.description.data)
        g.user.team = new_team
        db.session.add(new_team)
        db.session.add(g.user)
        db.session.commit()
        flash('Team created successfully.', category='success')
        return redirect(url_for('team', team_id=g.user.team.id))
    return render_template('create_team.html', form=form)
示例#4
0
def teams_edit(request, competition=None, teamid=None):
    """
	Edit the team in the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["action"] = "edit"
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c.update(csrf(request))
    if request.method != "POST":
        team_obj = Team.objects.filter(compid=c["comp_obj"].compid,
                                       teamid=int(teamid))
        c["teamid"] = team_obj[0].teamid
        c["form"] = CreateTeamForm(initial=team_obj.values()[0])
        c["service_configs_list"] = buildTeamServiceConfigForms(
            c["comp_obj"].compid, team_obj[0].score_configs)
        return render_to_response('CompConfig/teams_create-edit.html', c)
    form_dict = request.POST.copy().dict()
    form_dict.pop('csrfmiddlewaretoken', None)
    form_dict["compid"] = c["comp_obj"].compid
    form_dict["score_configs"] = buildTeamServiceConfigDict(
        c["comp_obj"].compid, form_dict)
    # Clean network address
    if form_dict['networkaddr'][-1] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][:-1]
    if form_dict['networkaddr'][0] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][1:]
    team_obj = Team.objects.filter(compid=c["comp_obj"].compid,
                                   teamid=int(teamid))
    team_obj.update(**form_dict)
    return HttpResponseRedirect('/admin/competitions/%s/teams/' % competition)
示例#5
0
def teams_create(request, competition=None):
    """
	Create the team in the competition
	"""
    c = getAuthValues(request, {})
    if c["auth_name"] != "auth_team_white":
        return HttpResponseRedirect("/")
    c["action"] = "create"
    c["form"] = CreateTeamForm()
    c["comp_obj"] = Competition.objects.get(compurl=competition)
    c.update(csrf(request))
    if request.method != "POST":
        # Get a list of the services
        c["service_configs_list"] = buildTeamServiceConfigForms(
            c["comp_obj"].compid)
        return render_to_response('CompConfig/teams_create-edit.html', c)
    form_dict = request.POST.copy()
    form_dict["compid"] = c["comp_obj"].compid
    form_dict["score_configs"] = buildTeamServiceConfigDict(
        c["comp_obj"].compid, form_dict)
    # Clean network address
    if form_dict['networkaddr'][-1] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][:-1]
    if form_dict['networkaddr'][0] == ".":
        form_dict['networkaddr'] = form_dict['networkaddr'][1:]
    team = CreateTeamForm(form_dict)
    if not team.is_valid():
        return render_to_response('CompConfig/teams_create-edit.html', c)
    team.save()
    return HttpResponseRedirect("/admin/competitions/%s/teams/" % competition)
示例#6
0
def create_team():
    """
    A user creates a new team and sets some team parameters
    The suer by default becomes the team leader
    """

    from forms import CreateTeamForm
    form = CreateTeamForm()

    player_memberships = Membership.query.filter_by(user_id=g.user.id).all()
    if len(player_memberships) == 3:
        flash('You are in three teams already. Chill.', "warning")
        return redirect(url_for('user_page', steam_id=g.user.steam_id))

    from consts import TIME_ZONES_DICT

    if form.validate_on_submit():
        team = Team()
        team.name = form.team_name.data
        team.skill_level = form.team_skill_level.data
        team.time_zone = form.team_time_zone.data
        team.week_days = form.read_scrim_days()
        team.type = form.team_type.data
        db.session.add(team)
        db.session.commit()

        membership = Membership()
        membership.team_id = team.id
        membership.user_id = g.user.id
        membership.role = "Captain"
        db.session.add(membership)
        db.session.commit()

        return redirect(url_for('user_page', steam_id=g.user.steam_id))
    else:
        return render_template('create_team.html', create_team_form=form)
示例#7
0
def user_page(steam_id):
    """
    Return the user page, containing a list of tuples of Team and Membership,
    for instance, [(TeamA,"Captain"),(TeamB,"Coach")].
    """
    from forms import CreateTeamForm
    from consts import TIME_ZONES_DICT
    create_team_form = CreateTeamForm()
    try:
        user = User.query.filter_by(steam_id=steam_id).one()
    except NoResultFound:
        flash("User not found", "danger")
        return redirect(url_for('index'))

    team_roles = []
    user_memberships = Membership.query.filter_by(user_id=user.id).all()
    for mem in user_memberships:
        team = Team.query.filter_by(id=mem.team_id).one()
        team_roles.append((team, mem.role))

    single_scrims = SingleScrim.query.filter_by(leader_id=user.id).all()

    return render_template('user.html', user=user, team_roles=team_roles,create_team_form=create_team_form,tz=TIME_ZONES_DICT,single_scrims=single_scrims)