def update_deck(deck_id): if current_user(): deck = Deck.query.get(deck_id) if deck is None: abort(404) if locked(deck): raise InvalidUsage('Deck is locked!', status_code=403) coach = Coach.query.options(raiseload(Coach.cards),raiseload(Coach.packs)).filter_by(disc_id=current_user()['id']).one_or_none() if deck.tournament_signup.coach!=coach: raise InvalidUsage("Unauthorized access!", status_code=403) received_deck = request.get_json()['deck'] deck = DeckService.update(deck,received_deck) result = deck_schema.dump(deck) return jsonify(result.data) else: raise InvalidUsage('You are not authenticated!', status_code=401)
def commit_deck(deck_id): if not current_user(): raise InvalidUsage('You are not authenticated', status_code=401) deck = Deck.query.get(deck_id) if deck is None: abort(404) if locked(deck): raise InvalidUsage("Deck is locked!", status_code=403) coach = Coach.query.options(raiseload(Coach.cards),raiseload(Coach.packs)).filter_by(disc_id=current_user()['id']).one_or_none() if deck.tournament_signup.coach!=coach: raise InvalidUsage("Unauthorized access!!!!", status_code=403) try: deck = DeckService.commit(deck) except (DeckError) as e: raise InvalidUsage(str(e), status_code=403) result = deck_schema.dump(deck) return jsonify(result.data)
def get_deck(deck_id): if not current_user(): raise InvalidUsage('You are not authenticated', status_code=401) deck = Deck.query.get(deck_id) if deck is None: abort(404) coach = Coach.query.options(raiseload(Coach.cards),raiseload(Coach.packs)).filter_by(disc_id=current_user()['id']).one_or_none() if not deck.commited and not (coach.id==deck.tournament_signup.coach.id or coach.short_name()=="TomasT"): raise InvalidUsage("Deck not commited, only owner can display it!", status_code=403) # is committed if deck.tournament_signup.tournament.phase=="deck_building" and not (coach.id==deck.tournament_signup.coach.id or coach.short_name()==deck.tournament_signup.tournament.admin or coach.short_name()=="TomasT"): raise InvalidUsage("Only owner and admin can see display commited deck in the Deck Building phase!", status_code=403) starter_cards = CoachService.get_starter_cards(deck.tournament_signup.coach) result = deck_schema.dump(deck) result2 = cards_schema.dump(starter_cards) return jsonify({'deck':result.data, 'starter_cards':result2.data})
def deck_response(deck): """Turns deck into JSON response""" result = deck_schema.dump(deck) return jsonify(result.data)