示例#1
0
def player_search():
    query = request.args.get('q')

    retval = {}

    if query:
        page = request.args.get('p')

        try:
            page = max(int(page), 0) if page else 0
        except:
            page = 0

        page_size = 20

        results = libplayer.filter_players(query, page_size=page_size, page=page)

        retval.update({
            'query': query,
            'results': results,
            'page': page,
            'page_size': page_size
        })

    return render_template('search.html', **retval)
示例#2
0
def contact_query():
    query = request.args.get('query')

    contacts = []

    if query:
        players = libplayer.filter_players(query, page_size=10)

        contacts = [{
            'player_id': player.id,
            'username': player.username,
            'nickname': player.nickname,
            'displayname_html': player.displayname_html
        } for player in players]

        users = User.query.filter(
            User.username.ilike('%%%s%%' % query)
        ).order_by(
            User.username.desc()
        )

        for user in users:
            contacts.insert(0, {
                'user_id': user.id,
                'username': user.username,
                'nickname': None,
                'displayname_html': user.username
            })

    return jsonify({
        'err': 0,
        'contacts': contacts
    })
示例#3
0
def player_search():
    query = request.args.get('q')

    retval = {}

    if query:
        page = request.args.get('p')

        try:
            page = max(int(page), 0) if page else 0
        except:
            page = 0

        page_size = 20

        results = libplayer.filter_players(query,
                                           page_size=page_size,
                                           page=page)

        retval.update({
            'query': query,
            'results': results,
            'page': page,
            'page_size': page_size
        })

    return render_template('search.html', **retval)
示例#4
0
def contact_query():
    query = request.args.get('query')

    contacts = []

    if query:
        players = libplayer.filter_players(query, page_size=10)

        contacts = [{
            'player_id': player.id,
            'username': player.username,
            'nickname': player.nickname,
            'displayname_html': player.displayname_html
        } for player in players]

        users = User.query.filter(User.username.ilike(
            '%%%s%%' % query)).order_by(User.username.desc())

        for user in users:
            contacts.insert(
                0, {
                    'user_id': user.id,
                    'username': user.username,
                    'nickname': None,
                    'displayname_html': user.username
                })

    return jsonify({'err': 0, 'contacts': contacts})