Beispiel #1
0
def tournament_close(tournament_id):
    if current_user():
        try:
            tourn = Tournament.query.get(tournament_id)
            coach = Coach.query.options(raiseload(Coach.cards),raiseload(Coach.packs)).filter_by(disc_id=current_user()['id']).one_or_none()
            if not coach:
                raise InvalidUsage("Coach not found", status_code=403)    
            if not coach.web_admin:
                raise InvalidUsage("Coach does not have webadmin role", status_code=403)    
            #prizes
            for prize in request.get_json():
                tmp_coach = Coach.query.options(raiseload(Coach.cards),raiseload(Coach.packs)).get(prize['coach'])
                reason = prize['reason']+" by "+coach.short_name()
                TransactionService.process(tmp_coach,int(prize['amount'])*-1,reason)

            for coach in tourn.coaches:
                TournamentService.unregister(tourn,coach,admin=True,refund=False)
            tourn.phase="deck_building"
            db.session.commit()

            result = tournament_schema.dump(tourn)
            return jsonify(result.data)
        except (RegistrationError,TransactionError) as e:
            raise InvalidUsage(str(e), status_code=403)
    else:
        raise InvalidUsage('You are not authenticated', status_code=401)
Beispiel #2
0
def tournament_sign(tournament_id, **kwargs):
    """Sign coach into tournament"""
    try:
        coach = kwargs['coach']

        tourn = Tournament.query.get(tournament_id)
        TournamentService.register(tourn, coach)
        result = tournament_schema.dump(tourn)
        return jsonify(result.data)
    except RegistrationError as exc:
        raise InvalidUsage(str(exc), status_code=403)
Beispiel #3
0
def tournament_start(tournament_id):
    """Set tournament phase"""
    try:
        tourn = Tournament.query.get(tournament_id)
        TournamentService.kick_off(tourn)

        result = tournament_schema.dump(tourn)
        return jsonify(result.data)
    except (RegistrationError, TransactionError, TypeError,
            TournamentError) as exc:
        raise InvalidUsage(str(exc), status_code=403)
Beispiel #4
0
def tournament_set_phase(tournament_id):
    """Set tournament phase"""
    try:
        tourn = Tournament.query.get(tournament_id)
        phase = request.get_json()['phase']
        TournamentService.set_phase(tourn, phase)
        db.session.commit()

        result = tournament_schema.dump(tourn)
        return jsonify(result.data)
    except (RegistrationError, TransactionError, TypeError) as exc:
        raise InvalidUsage(str(exc), status_code=403)
Beispiel #5
0
def tournament_resign(tournament_id):
    if current_user():
        try:
            tourn = Tournament.query.get(tournament_id)
            coach = Coach.query.filter_by(disc_id=current_user()['id']).one_or_none()
            if not coach:
                raise InvalidUsage("Coach not found", status_code=403)    
            TournamentService.unregister(tourn,coach)
            result = tournament_schema.dump(tourn)
            return jsonify(result.data)
        except RegistrationError as e:
            raise InvalidUsage(str(e), status_code=403)
    else:
        raise InvalidUsage('You are not authenticated', status_code=401)
Beispiel #6
0
def tournament_resign(tournament_id, **kwargs):
    """resign from tournament"""
    try:
        coach = kwargs['coach']

        tourn = Tournament.query.get(tournament_id)
        TournamentService.unregister(tourn, coach)
        signups = TournamentService.update_signups(tourn)
        if signups:
            coaches = [signup.coach for signup in signups]
            msg = (", ").join([f"<@{coach.disc_id}>" for coach in coaches])
            Notificator("bank").notify(
                f"{msg}: Your signup to {tourn.name} has been updated from RESERVE to ACTIVE"
            )

        result = tournament_schema.dump(tourn)
        return jsonify(result.data)
    except RegistrationError as exc:
        raise InvalidUsage(str(exc), status_code=403)
Beispiel #7
0
def tournament_resign(tournament_id):
    if current_user():
        try:
            tourn = Tournament.query.get(tournament_id)
            coach = Coach.query.options(raiseload(Coach.cards),raiseload(Coach.packs)).filter_by(disc_id=current_user()['id']).one_or_none()
            if not coach:
                raise InvalidUsage("Coach not found", status_code=403)    
            
            TournamentService.unregister(tourn,coach)
            signups = TournamentService.update_signups(tourn)
            if len(signups)>0:
                coaches = [signup.coach for signup in signups]
                msg = (", ").join([f"<@{coach.disc_id}>" for coach in coaches])           
                NotificationService.notify(f"{msg}: Your signup to {tourn.name} has been updated from RESERVE to ACTIVE")

            result = tournament_schema.dump(tourn)
            return jsonify(result.data)
        except RegistrationError as e:
            raise InvalidUsage(str(e), status_code=403)
    else:
        raise InvalidUsage('You are not authenticated', status_code=401)
Beispiel #8
0
def tournament_set_phase(tournament_id):
    if current_user():
        try:
            tourn = Tournament.query.get(tournament_id)
            coach = Coach.query.options(raiseload(Coach.cards),raiseload(Coach.packs)).filter_by(disc_id=current_user()['id']).one_or_none()
            if not coach:
                raise InvalidUsage("Coach not found", status_code=403)    
            if not coach.short_name()==tourn.admin:
                raise InvalidUsage("You are not admin for this tournament!", status_code=403)    
            phase = request.get_json()['phase']
            if phase not in ["deck_building","locked","special_play","inducement"]:
                raise InvalidUsage(f"Incorrect phase - {phase}", status_code=403)  
            tourn.phase=phase
            db.session.commit()

            result = tournament_schema.dump(tourn)
            return jsonify(result.data)
        except (RegistrationError,TransactionError) as e:
            raise InvalidUsage(str(e), status_code=403)
    else:
        raise InvalidUsage('You are not authenticated', status_code=401)
Beispiel #9
0
def tournament_close(tournament_id):
    """Close tournaments and award prizes"""
    try:
        tourn = Tournament.query.get(tournament_id)
        coach = current_coach()
        #prizes
        for prize in request.get_json():
            tmp_coach = Coach.query.options(raiseload(Coach.cards),
                                            raiseload(Coach.packs)).get(
                                                prize['coach'])

            reason = prize['reason'] + " by " + coach.short_name()
            TransactionService.process(tmp_coach,
                                       int(prize['amount']) * -1, reason)

        TournamentService.close_tournament(tourn)

        result = tournament_schema.dump(tourn)
        return jsonify(result.data)
    except (RegistrationError, TransactionError) as exc:
        raise InvalidUsage(str(exc), status_code=403)
Beispiel #10
0
def get_tournament(tournament_id):
    tourn = Tournament.query.get(tournament_id)
    result = tournament_schema.dump(tourn)
    return jsonify(result.data)
Beispiel #11
0
def get_tournament(tournament_id):
    """returns tournamnet as json"""
    tourn = Tournament.query.get(tournament_id)
    result = tournament_schema.dump(tourn)
    return jsonify(result.data)