Exemplo n.º 1
0
def new_team(request):
    if 'group' in request.GET:
        group = get_object_or_404(Group, pk=int(request.GET['group']))
        competition = group.competition_set.all()[0]
    if request.method == 'POST':
        form = NewTeamForm(request.POST)
        if form.is_valid():
            teams = form.cleaned_data['names']
            teams = teams.replace('\r', "")
            teams = teams.split('\n')
            
            for t in teams:
                team = Team(name=t)
                team.save()
                group.teams.add(team)
            
            group.save()

            msg = "Teams for group {0} has been created!".format(group.name)
            messages.success(request, msg)

            return redirect('soccer.views.group', str(group.id))
    else:
        form = NewTeamForm()
        c = {}
        c.update(csrf(request))
        c['form'] = form
        c['group'] = group
        c['competition'] = competition
        return c
Exemplo n.º 2
0
def create(shortname: str, fullname: str, liga: int, stadion: str,
           website: str, birthday: int):
    """Create a new team

    Args:
        shortname: nama pendek dari club
        fullname: nama panjang dari club
        liga: nama liga yang diikuti club
        stadion: nama stadion kandang club
        website: website official club
        birthday: tanggal lahir club

    Returns:
        Team Object
    """
    team = Team(shortname=shortname,
                fullname=fullname,
                liga=liga,
                birthday=birthday)
    team.stadion = stadion
    team.website = website

    db.session.add(team)
    db.session.flush()

    return team
Exemplo n.º 3
0
def team(id=None, p=None, limit=None, admin=None, **kwargs):
    db = DB_Session()
    query = db.query(Team)
    if web.ctx.method in ("POST", "PUT", "PATCH"):
        i = json.loads(web.data())
        player = None
        if i.has_key("player"):
            player = i.pop("player")
        if web.ctx.method in ("PUT", "PATCH"):
            team = query.get(int(id))
            for name, value in i.items():
                setattr(team, name, value)
        else:
            team = Team(**i)
            db.add(team)
            db.flush()
            db.refresh(team)
        if player is not None:
            team.teamplayer[:] = [TeamPlayer(**{"team_id": id, "player_id": p}) for p in player]
        db.commit()
        n = ResultWrapper(team, team=team.to_api(admin))
    else:
        if id:
            team = query.get(int(id))
            team = team.to_api(admin)
            n = ResultWrapper(team, team=team)
        else:
            if kwargs.has_key("nation"):
                nation = kwargs["nation"]
                team = query.filter(Team.owner_id == int(nation), Team.type == 1)
            if kwargs.has_key("club"):
                club = kwargs["club"]
                team = query.filter(Team.owner_id == int(club), Team.type == 2)
            if kwargs.has_key("event"):
                event = kwargs["event"]
                team = query.join(EventsTeams, Team.id == EventsTeams.team_id).filter(
                    EventsTeams.event_id == int(event)
                )
            team = paging(team, limit, p)
            n = ResultWrapper(team, team=[v.to_api(admin) for v in team], count=query.count())
    db.close()
    return n
Exemplo n.º 4
0
def new_team(request):
    if request.method == 'POST':
        form = NewTeamForm(request.POST)
        if form.is_valid():
            teams = form.cleaned_data['names']
            teams = teams.replace('\r', "")
            teams = teams.split('\n')

            for t in teams:
                team = Team(name=t)
                team.save()

            messages.success(request, "Teams have been created!")

            return redirect('/soccer/')
    else:
        form = NewTeamForm()
        c = {}
        c.update(csrf(request))
        c['form'] = form
        c['group'] = group
        c['competition'] = competition
        return c