def on_post(self, req, resp, id): match = m.Match.get(id=id) Privilege.checkOrganizer(req.context['user'], match.tournamentId) data = req.context['data'] assistPlayerId = data.get('assistPlayerId') scorePlayerId = data.get('scorePlayerId') callahan = data.get('callahan', False) homePoint = bool(data['homePoint']) tournament = m.Tournament.get(id=match.tournamentId) if not tournament.ready: raise ValueError("Tournament isn't ready") if not match.active: raise ValueError("Match isn't active") teamId = match.homeTeamId if homePoint else match.awayTeamId self.checkPlayers(match.tournamentId, teamId, assistPlayerId, scorePlayerId, callahan) with m.db.transaction(): if not callahan: if assistPlayerId: self.updatePlayerStatistic(match.tournamentId, assistPlayerId, match.id, 'A') if scorePlayerId: self.updatePlayerStatistic(match.tournamentId, scorePlayerId, match.id, 'S') order, homeScore, awayScore = Queries.getLastPoint(match.id) order += 1 if homePoint: homeScore += 1 else: awayScore += 1 m.Point.insert( homePoint=homePoint, matchId=match.id, order=order, assistPlayerId=assistPlayerId if not callahan else None, scorePlayerId=scorePlayerId if not callahan else None, homeScore=homeScore, awayScore=awayScore, callahan=callahan).execute() self.updateMatchScore(match.id, homePoint) point = Queries.getPoints(matchId=match.id, order=order)[0] req.context['result'] = point resp.status = falcon.HTTP_201
def on_put(self, req, resp, id): match = m.Match.get(id=id) Privilege.checkOrganizer(req.context['user'], match.tournamentId) data = req.context['data'] tournament = m.Tournament.get(id=match.tournamentId) activated = False if not match.active and data.get('active'): if not tournament.ready: raise ValueError("Tournament is not ready yet") self.activeMatch(id) activated = True # after active, because it rewrites score super(Match, self).on_put(req, resp, id, [ 'homeScore', 'awayScore', 'fieldId', 'startTime', 'endTime', 'description' ]) if 'homeScore' in data and 'awayScore' in data: pass # TODO: pri zmene skore smazat vsechny doposud odehrane body terminated = False if (match.active or activated) and not match.terminated and data.get('terminated'): self.terminateMatch(id) terminated = True if activated or terminated: resp.status = falcon.HTTP_200 req.context['result'] = Queries.getMatches(matchId=id)[0]
def on_get(self, req, resp, id): Privilege.checkOrganizer(req.context['user'], int(id)) tournament = m.Tournament.get(id=id) matches = Queries.getMatches(tournamentId=id) missingSpirits = [] for match in matches: if match['terminated'] != True: continue if match['homeTeam']['spirit'] is None: missingSpirits.append({ 'teamId': match['homeTeam']['id'], 'teamName': match['awayTeam']['name'], 'matchId': match['id'], 'ide': match['ide'] }) if match['awayTeam']['spirit'] is None: missingSpirits.append({ 'teamId': match['homeTeam']['id'], 'teamName': match['homeTeam']['name'], 'matchId': match['id'], 'ide': match['ide'] }) collection = {'count': len(missingSpirits), 'items': missingSpirits} req.context['result'] = collection
def on_get(self, req, resp, id): teams = Queries.getTeams(id) collection = { 'count' : len(teams), 'items' : teams } req.context['result'] = collection
def on_get(self, req, resp): clubs = Queries.getClubs() collection = { 'count' : len(clubs), 'items' : clubs } req.context['result'] = collection
def on_get(self, req, resp, id): players = Queries.getPlayers( id, req.params.get('teamId'), req.params.get('limit') ) collection = { 'count': len(players), 'items': players } req.context['result'] = collection
def on_get(self, req, resp, id): matches = Queries.getMatches(id, req.params.get('matchId'), req.params.get('fieldId'), req.params.get('date'), req.get_param_as_bool('active'), req.get_param_as_bool('terminated'), req.params.get('groupIde')) collection = {'count': len(matches), 'items': matches} req.context['result'] = collection
def checkPlayers(self, tournamentId, teamId, assistPlayerId, scorePlayerId, callahan): if not callahan and assistPlayerId: if assistPlayerId == scorePlayerId: raise ValueError( "Assisting player and scoring player is the one") # assisting player hisTeamId = Queries.getPlayersTeamId(tournamentId, assistPlayerId) if hisTeamId != teamId: raise ValueError("Team %s hasn't player %s" % (teamId, assistPlayerId)) if scorePlayerId is not None: # scoring player hisTeamId = Queries.getPlayersTeamId(tournamentId, scorePlayerId) if hisTeamId != teamId: raise ValueError("Team %s hasn't player %s" % (teamId, scorePlayerId)) return True
def on_get(self, req, resp): tournaments = Queries.getTournaments( req.params.get('country'), req.params.get('divisionId'), req.get_param_as_bool('active'), req.get_param_as_bool('terminated'), req.params.get('userId'), ) collection = {'count': len(tournaments), 'items': tournaments} req.context['result'] = collection
def on_get(self, req, resp): tournaments = Queries.getTournaments( req.params.get('country'), req.params.get('divisionId'), req.get_param_as_bool('active'), req.get_param_as_bool('terminated'), req.params.get('userId'), ) collection = { 'count': len(tournaments), 'items': tournaments } req.context['result'] = collection
def on_delete(self, req, resp, id): match = m.Match.get(id=id) Privilege.checkOrganizer(req.context['user'], match.tournamentId) # TODO: unite this two queries order, homeScore, awayScore = Queries.getLastPoint(match.id) point = Queries.getPoints(match.id, order)[0] assistPlayerId = point['assistPlayer']['id'] scorePlayerId = point['scorePlayer']['id'] with m.db.transaction(): # delete from match table self.updateMatchScore(match.id, point['homePoint'], (-1)) # delete players statistics if assistPlayerId: self.updatePlayerStatistic(match.tournamentId, assistPlayerId, match.id, 'A', (-1)) if scorePlayerId: self.updatePlayerStatistic(match.tournamentId, scorePlayerId, match.id, 'S', (-1)) # delete point m.Point.delete().where(m.Point.matchId == match.id, m.Point.order == order).execute()
def on_get(self, req, resp, id): matches = Queries.getMatches( id, req.params.get('matchId'), req.params.get('fieldId'), req.params.get('date'), req.get_param_as_bool('active'), req.get_param_as_bool('terminated'), req.params.get('groupIde') ) collection = { 'count': len(matches), 'items': matches } req.context['result'] = collection
def terminateTournament(self, id): '''terminate tournament''' tournament = m.Tournament.get(id=id) standings = m.Standing.select().where(m.Standing.tournamentId==tournament.id) for standing in standings: if standing.teamId is None: raise falcon.HTTPBadRequest( "Tournanent can't be terminated", "All standings aren't known. Probably some matches are still active." ) matches = Queries.getMatches(tournamentId=tournament.id) for match in matches: if match['homeTeam']['spirit'] is None or match['awayTeam']['spirit'] is None: raise falcon.HTTPBadRequest( "Tournanent can't be terminated", ("Spirit from match %s is still missing" % match['ide']) ) tournament.terminated = True tournament.save()
def terminateTournament(self, id): '''terminate tournament''' tournament = m.Tournament.get(id=id) standings = m.Standing.select().where( m.Standing.tournamentId == tournament.id) for standing in standings: if standing.teamId is None: raise falcon.HTTPBadRequest( "Tournanent can't be terminated", "All standings aren't known. Probably some matches are still active." ) matches = Queries.getMatches(tournamentId=tournament.id) for match in matches: if match['homeTeam']['spirit'] is None or match['awayTeam'][ 'spirit'] is None: raise falcon.HTTPBadRequest( "Tournanent can't be terminated", ("Spirit from match %s is still missing" % match['ide'])) tournament.terminated = True tournament.save()
def on_get(self, req, resp, id): loggedUser = req.context['user'] match = Queries.getMatches(matchId=id)[0] Privilege.checkOrganizer(loggedUser, m.Match.get(id=id).tournamentId) homeSpirit = None awaySpirit = None try: homeSpirit = model_to_dict( m.Spirit.get(matchId=id, teamId=match['homeTeam']['id'])) del homeSpirit['matchId'], homeSpirit['teamId'], homeSpirit[ 'givingTeamId'] # if spirit is not club's team = m.Team.get(id=match['homeTeam']['id']) if loggedUser.role == "club" and not loggedUser.clubId == team.clubId: homeSpirit = None except m.Spirit.DoesNotExist: pass finally: match['homeTeam']['spirit'] = homeSpirit try: awaySpirit = model_to_dict( m.Spirit.get(matchId=id, teamId=match['awayTeam']['id'])) del awaySpirit['matchId'], awaySpirit['teamId'], awaySpirit[ 'givingTeamId'] # if spirit is not club's team = m.Team.get(id=match['awayTeam']['id']) if loggedUser.role == "club" and not loggedUser.clubId == team.clubId: homeSpirit = None except m.Spirit.DoesNotExist: pass finally: match['awayTeam']['spirit'] = awaySpirit req.context['result'] = match
def on_get(self, req, resp, id): req.context['result'] = Queries.getClubs(id)[0]
def on_get(self, req, resp, id): teams = Queries.getTeams(id) collection = {'count': len(teams), 'items': teams} req.context['result'] = collection
def on_get(self, req, resp, id): match = Queries.getMatches(matchId=id)[0] match['points'] = Queries.getPoints(id) req.context['result'] = match
def on_get(self, req, resp, id): players = Queries.getPlayers(id, req.params.get('teamId'), req.params.get('limit')) collection = {'count': len(players), 'items': players} req.context['result'] = collection
def on_get(self, req, resp): clubs = Queries.getClubs() collection = {'count': len(clubs), 'items': clubs} req.context['result'] = collection
def on_put(self, req, resp, id): Privilege.checkClub(req.context['user'], int(id)) super(Club, self).on_put(req, resp, id, ['shortcut', 'city', 'country']) req.context['result'] = Queries.getClubs(id)[0]
def on_get(self, req, resp, id): req.context['result'] = Queries.getMatches(matchId=id)[0]