Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
async def resign(tournament_id, coach, ctx, admin=False):
    """routine to resign a coach to tournament"""
    if admin:
        tourn = Tournament.query.filter_by(
            tournament_id=tournament_id).one_or_none()
    else:
        tourn = Tournament.query.filter_by(
            status="OPEN", tournament_id=tournament_id).one_or_none()

    if not tourn:
        raise ValueError("Incorrect **tournament_id** specified")

    if TournamentService.unregister(tourn, coach, admin):
        await ctx.send(f"Resignation succeeded!!!")

        coaches = [
            discord.utils.get(ctx.guild.members, id=str(signup.coach.disc_id))
            for signup in TournamentService.update_signups(tourn)
        ]
        msg = [coach.mention for coach in coaches if coach]
        msg.append(
            f"Your signup to {tourn.name} has been updated from RESERVE to ACTIVE"
        )

        if len(msg) > 1:
            tourn_channel = discord.utils.get(ctx.bot.get_all_channels(),
                                              name='tournament-notice-board')
            if tourn_channel:
                await tourn_channel.send("\n".join(msg))
            else:
                await ctx.send("\n".join(msg))
    return True
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)