Exemple #1
0
def search(request):
    base = base_ctx(request=request)

    query = get_param(request, 'q', '')
    results = tools_search(query)
    if results is None:
        return redirect('/')

    players, teams, events = results

    # {{{ Redirect if only one hit
    if players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect('/players/%i-%s/' %
                        (players.first().id, urlfilter(players.first().tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect('/teams/%i-%s/' %
                        (teams.first().id, urlfilter(teams.first().name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect(
            '/results/events/%i-%s/' %
            (events.first().id, urlfilter(events.first().fullname)))
    # }}}

    base.update({
        'results': zip_longest(players, teams, events, fillvalue=None),
        'players': players,
        'teams': teams,
        'events': events,
        'query': query,
    })

    return render_to_response('search.djhtml', base)
Exemple #2
0
def search(request):
    base = base_ctx(request=request)

    query = get_param(request, 'q', '')
    results = tools_search(query)
    if results is None:
        return redirect('/')

    players, teams, events = results

    # {{{ Redirect if only one hit
    if   players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect('/players/%i-%s/' % (players.first().id, urlfilter(players.first().tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect('/teams/%i-%s/' % (teams.first().id, urlfilter(teams.first().name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect('/results/events/%i-%s/' % (events.first().id, urlfilter(events.first().fullname)))
    # }}}

    base.update({
        'players':  players,
        'teams':    teams,
        'events':   events,
        'query':    query,
    })

    base.update({'title': _('Search results')})

    return render_to_response('search.html', base)
Exemple #3
0
def search(request):
    base = base_ctx(request=request)

    query = get_param(request, "q", "")
    results = tools_search(query)
    if results is None:
        return redirect("/")

    players, teams, events = results

    # {{{ Redirect if only one hit
    if players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect("/players/%i-%s/" % (players.first().id, urlfilter(players.first().tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect("/teams/%i-%s/" % (teams.first().id, urlfilter(teams.first().name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect("/results/events/%i-%s/" % (events.first().id, urlfilter(events.first().fullname)))
    # }}}

    base.update(
        {
            "results": zip_longest(players, teams, events, fillvalue=None),
            "players": players,
            "teams": teams,
            "events": events,
            "query": query,
        }
    )

    return render_to_response("search.djhtml", base)
Exemple #4
0
def auto_complete_search(request):
    query = get_param(request, 'q', '')
    search_for = get_param(request, 'search_for', 'players,teams,events')
    search_for = search_for.split(',')

    results = tools_search(query, search_for, strict=True)

    data = {}
    if results is None:
        return JsonResponse(data)

    players, teams, events = results

    if players is not None:
        players = players.extra(select=EXTRA_NULL_SELECT)\
                         .order_by("-null_curr", "-current_rating__rating")

        num = 5 if teams is not None or events is not None else 10
        data['players'] = [{
            "id": p.id,
            "tag": p.tag,
            "race": p.race,
            "country": p.country,
            "aliases": [a.name for a in p.alias_set.all()],
            "teams": [
                (t.group.name, t.group.shortname)
                for t in p.groupmembership_set.filter(
                        current=True,
                        group__is_team=True
                )]
        } for p in players[:num]]

    if teams is not None:
        teams = teams.order_by('name')

        num = 5 if players is not None or events is not None else 10
        data['teams'] = [{
            "id": t.id,
            "name": t.name
            } for t in teams[:num]]

    if events is not None:
        events = events.order_by("fullname")

        num = 5 if players is not None or teams is not None else 10
        data['events'] = [{
            "id": e.id,
            "fullname": e.fullname
            } for e in events[:num]]

    return JsonResponse(data)
Exemple #5
0
def auto_complete_search(request):
    query = get_param(request, 'q', '')
    search_for = get_param(request, 'search_for', 'players,teams,events')
    search_for = search_for.split(',')

    results = tools_search(query, search_for, strict=True)

    data = {}
    if results is None:
        return JsonResponse(data)

    players, teams, events = results

    if players is not None:
        players = players.extra(select=EXTRA_NULL_SELECT)\
                         .order_by("-null_curr", "-current_rating__rating")

        num = 5 if teams is not None or events is not None else 10
        data['players'] = [{
            "id":
            p.id,
            "tag":
            p.tag,
            "race":
            p.race,
            "country":
            p.country,
            "aliases": [a.name for a in p.alias_set.all()],
            "teams":
            [(t.group.name, t.group.shortname)
             for t in p.groupmembership_set.filter(current=True,
                                                   group__is_team=True)]
        } for p in players[:num]]

    if teams is not None:
        teams = teams.order_by('name')

        num = 5 if players is not None or events is not None else 10
        data['teams'] = [{"id": t.id, "name": t.name} for t in teams[:num]]

    if events is not None:
        events = events.order_by("fullname")

        num = 5 if players is not None or teams is not None else 10
        data['events'] = [{
            "id": e.id,
            "fullname": e.fullname
        } for e in events[:num]]

    return JsonResponse(data)