コード例 #1
0
def decks_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of decks.
    Input:
        {
            'archetypeId': <int?>,
            'cardName': <str?>,
            'competitionId': <int?>,
            'personId': <int?>,
            'deckType': <'league'|'tournament'|'all'>,
            'page': <int>,
            'pageSize': <int>,
            'personId': <int?>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>,
            'seasonId': <int|'all'>
        }
    Output:
        {
            'page': <int>,
            'pages': <int>,
            'decks': [<deck>]
        }
    """
    if not request.args.get('sortBy') and request.args.get('competitionId'):
        sort_by = 'top8'
        sort_order = 'ASC'
    elif not request.args.get('sortBy'):
        sort_by = 'date'
        sort_order = 'DESC'
    else:
        sort_by = str(request.args.get('sortBy'))
        sort_order = str(request.args.get('sortOrder'))
    assert sort_order in ['ASC', 'DESC']
    order_by = query.decks_order_by(sort_by, sort_order)
    page_size = int(request.args.get('pageSize', 20))
    page = int(request.args.get('page', 0))
    start = page * page_size
    limit = f'LIMIT {start}, {page_size}'
    # Don't restrict by season if we're loading something with a date by its id.
    season_id = 'all' if request.args.get(
        'competitionId') else rotation.season_id(
            str(request.args.get('seasonId')), None)
    where = query.decks_where(request.args, session.get('person_id'))
    total = deck.load_decks_count(where=where, season_id=season_id)
    pages = max(ceil(total / page_size) - 1, 0)  # 0-indexed
    ds = deck.load_decks(where=where,
                         order_by=order_by,
                         limit=limit,
                         season_id=season_id)
    prepare_decks(ds)
    r = {'page': page, 'pages': pages, 'decks': ds}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp
コード例 #2
0
def test_season_id() -> None:
    assert rotation.season_id(1) == 1
    found = False
    try:
        rotation.season_id(999)
    except DoesNotExistException:
        found = True
    assert found
    found = False
    try:
        assert rotation.season_id('ISD')
    except DoesNotExistException:
        found = True
    assert found
    assert rotation.season_id('HOU') == 5
    assert rotation.season_id('hou') == 5
    assert rotation.season_id('ALL') == 'all'
    assert rotation.season_id('all') == 'all'
コード例 #3
0
def pull_season_id(_endpoint, values):
    v = values.pop('season_id')
    g.season_id = rotation.season_id(v)
コード例 #4
0
def pull_season_id(_endpoint: str, values: Dict[str, Any]) -> None:
    v = values.pop('season_id')
    g.season_id = rotation.season_id(v)