Example #1
0
def witness_match():
    try:
        content = get_request_json(witness_schema)
    except ValidationError as error:
        logging.error(error)
        return make_response(error, 400)

    try:
        content["season"], content["challenger"] = pop_challenge(content["winner"], content["loser"])
    except ValueError as error:
        logging.error(error)
        return make_response(error, 400)

    season = seasons.get_season(content["season"])
    winner = scores.get_score(username=content['winner'], season=season.id)
    loser = scores.get_score(username=content['loser'], season=season.id)
    witness = users.get_user(username=content['witness'])
    winner_wins = content['winner_wins']
    loser_wins = content['loser_wins']

    if winner is None:
        try:
            winner = create_score(content["winner"], season.id)
        except ValueError as err:
            logging.error("Error: Player score could not be generated: ", err)
            return make_response("The winner could not be added to current season", 500)
        except SQLAlchemyError as err:
            logging.error(err)
            return make_response("Something went wrong :(", 500)
    if loser is None:
        try:
            loser = create_score(content["loser"], season.id)
        except ValueError as err:
            logging.error("Error: Player score could not be generated: ", err)
            return make_response("The loser could not be added to current season", 500)
        except SQLAlchemyError as err:
            logging.error(err)
            return make_response("Something went wrong :(", 500)
    if winner is None or loser is None:
        logging.error("Error: Player not found. Winner: {0}, Loser: {1}"
                      .format(content['winner'], content['loser']))
        return make_response("Could not find the match contestants", 404)

    if winner.username == loser.username:
        return make_response("A match cannot be conducted by the same player", 400)

    if not witness.witness:
        return make_response("That user is not a valid witness", 400)

    try:
        validate_rounds(winner_wins, loser_wins, season.game.max_rounds, season.game.min_rounds)
    except ValueError as error:
        make_response(error, 400)

    try:
        create_match(winner, loser, witness, season, winner_wins, loser_wins, content["challenger"])
    except SQLAlchemyError as error:
        logging.error("Could not insert match into database: ", error)
        return make_response("Sorry, something went wrong!", 500)
    return make_response("Your match has been accepted!", 200)
Example #2
0
def new_match():
    try:
        content = get_request_json(challenge_schema)
    except ValidationError as error:
        logging.error(error)
        return make_response(error, 400)

    challenger = users.get_user(username=content["challenger"])
    challenged = users.get_user(username=content["challenged"])
    season = seasons.get_season(_id=content["season"])

    if not g.user.username == challenger.username:
        return make_response("You cannot issue a challenge for someone else", 403)

    if challenger.username == challenged.username:
        return make_response("You cannot challenge yourself!", 400)

    try:
        put_challenge(challenger.username, challenged.username, season.id)
    except ValueError as error:
        logging.error(error)
        return make_response("Hmm.. Seems like you're already challenging each other", 400)
    return make_response("You have challenged {0}".format(challenged.username), 200)
Example #3
0
def get_season_matches(_id):
    season = seasons.get_season(_id=_id)
    _matches = matches.get_match(season=season.id)
    return matches_schema.dumps(_matches)
Example #4
0
def get_season_scores(_id):
    season = seasons.get_season(_id=_id)
    _scores = scores.get_score(season=season.id)
    return seasons_schema.dumps(_scores)
Example #5
0
def get_season(_id):
    season = seasons.get_season(_id=_id)
    return season_schema.dumps(season)
Example #6
0
def get_seasons_active():
    _seasons = seasons.get_season(date=datetime.now())
    return seasons_schema.dumps(_seasons)
Example #7
0
def get_seasons():
    _seasons = seasons.get_season()
    return seasons_schema.dumps(_seasons)
Example #8
0
 def validate_season(self, value):
     if not seasons.get_season(value):
         raise ValidationError('That is not a valid season')
Example #9
0
def get_user_seasons(username):
    _seasons = seasons.get_season(username=username)
    return seasons_schema.dumps(_seasons)