コード例 #1
0
def rotation_cards_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of cards that are potentially rotating in.
    Input:
        {
            'page': <int>,
            'pageSize': <int>,
            'q': <str>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>
        }
    Output:
        {
            'page': <int>,
            'objects': [<entry>],
            'total': <int>
        }
    """
    _, _, cs = rotation.read_rotation_files()
    q = request.args.get('q', '').lower()
    search_results = None
    try:
        search_results = [c.name for c in card_search.search(q)] if q else None
    except card_search.InvalidSearchException:
        pass
    if search_results is not None:
        cs = [c for c in cs if c.name in search_results]
    if not session.get('admin', False):
        cs = [c for c in cs if c.status != 'Undecided']
    total = len(cs)
    # Now add interestingness to the cards, which only decksite knows not magic.rotation.
    playability = card.playability()
    for c in cs:
        c.interestingness = rotation.interesting(playability, c)
    rotation.rotation_sort(cs, request.args.get('sortBy'),
                           request.args.get('sortOrder'))
    page_size = int(request.args.get('pageSize', DEFAULT_LIVE_TABLE_PAGE_SIZE))
    page = int(request.args.get('page', 0))
    start = page * page_size
    end = start + page_size
    cs = cs[start:end]
    prepare_cards(cs)
    r = {'page': page, 'total': total, 'objects': cs}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp
コード例 #2
0
def complex_search(query):
    if query == '':
        return []
    return search.search(query)
コード例 #3
0
def complex_search(query):
    if query == '':
        return []
    print('Searching for {query}'.format(query=query))
    return search.search(query)
コード例 #4
0
    def search_button(self, instance):
        search_term = self.search_term.text

        search(search_term)
コード例 #5
0
def card_search_where(q: str) -> str:
    try:
        cs = search.search(q)
        return 'TRUE' if len(cs) == 0 else 'name IN (' + ', '.join(sqlescape(c.name) for c in cs) + ')'
    except search.InvalidSearchException:
        return 'TRUE'  # Do not apply malformed queries. Future improvement: ignore invalid parts and match the valid parts.