def new_match(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 = NewMatchForm(request.POST) if form.is_valid(): teamA = form.cleaned_data['teamA'] teamB = form.cleaned_data['teamB'] referee = form.cleaned_data['referee'] match = Match(teamA=teamA, teamB=teamB, referee=referee) match.save() group.matches.add(match) msg = "The match between {1} and {2} in group {0} has been created!"\ .format(group.name, teamA, teamB) messages.success(request, msg) return redirect('soccer.views.group', str(group.id)) else: form = NewMatchForm() c = {} c.update(csrf(request)) c['form'] = form c['group'] = group return c
def matches_generate_listing(request): group = get_object_or_404(Group, pk=request.POST['group_id']) teams = list(group.teams.all()) matches = [] schedule = round_robin(teams) for round in schedule: for teams in round: match = Match(teamA=teams[0], teamB=teams[1], referee=request.user) match.save() group.matches.add(match) matches.append(match) return {'matches': matches, 'group': group}
def matches(id=None, p=None, limit=None, admin=None, **kwargs): db = DB_Session() query = db.query(Match) if web.ctx.method in ("POST", "PUT", "PATCH"): i = json.loads(web.data()) if web.ctx.method in ("PUT", "PATCH"): match = query.get(int(id)) for name, value in i.items(): setattr(match, name, value) else: match = Match(**i) db.add(match) db.flush() db.refresh(match) db.commit() n = ResultWrapper(match, match=match.to_api(admin)) else: if id: match = query.get(int(id)) match = match.to_api(admin) n = ResultWrapper(match, matches=match) else: format = "%Y-%m-%d %H:%M:%S" if kwargs.has_key("event"): event = kwargs["event"] if kwargs.has_key("fixtures"): query = query.join(Round, Match.round_id == Round.id).filter( Round.event_id == event, Match.play_at > datetime.datetime.utcnow() ) else: query = ( query.join(Round, Match.round_id == Round.id) .filter( Round.event_id == event, Match.play_at < datetime.datetime.utcnow(), Match.score1 != None ) .order_by("-play_at") ) if kwargs.has_key("start"): query = query.filter(Match.play_at > datetime.datetime.strptime(kwargs["start"], format)) if kwargs.has_key("end"): query = query.filter(Match.play_at < datetime.datetime.strptime(kwargs["end"], format)) if kwargs.has_key("team"): team = kwargs["team"] query = query.filter( or_(Match.team1_id == team, Match.team2_id == team), Match.play_at > datetime.datetime.utcnow() ) match = paging(query, limit, p) n = ResultWrapper(match, matches=[v.to_api(admin) for v in match], count=query.count()) db.close() return n
def saveMatch(request, fixtureId): match = Match() # create an instance match.fixture_id = fixtureId # store fixture id match.user = request.user # store user match.save() # save match # Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. return HttpResponseRedirect(reverse('soccer:myaccount'))