Ejemplo n.º 1
0
    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]
Ejemplo n.º 2
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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
 def on_get(self, req, resp, id):
     match = Queries.getMatches(matchId=id)[0]
     match['points'] = Queries.getPoints(id)
     req.context['result'] = match
Ejemplo n.º 9
0
 def on_get(self, req, resp, id):
     req.context['result'] = Queries.getMatches(matchId=id)[0]