Exemple #1
0
def global_search_suggest_view(request):
    q = request.GET.get("q")
    if not q:
        return HttpResponse("")

    results = SearchQuerySet()

    # Wildcard the words in the search term
    q_words = q.strip().split(" ")
    for word in q_words:
        if not word:
            # Skip blank words (extra spaces, etc)
            continue
        results = results.filter(content=word.lower() + "*")

    suggest = []
    for result in results[0:20]:
        suggest.append(result.object.render_search_result())
    return HttpResponse("\n".join(suggest))
Exemple #2
0
def select_person_view(request):
    q = request.GET.get("q")
    if not q:
        return HttpResponse("")
    q_words = q.strip().split(" ")
    results = SearchQuerySet()
    for word in q_words:
        if not word:
            # Skip blank words (extra spaces, etc)
            continue
        results = results.filter(content=word.lower() + "*")
    results = results.models(Supporter, Voter)

    people = []
    supporters = []
    voters = []
    for result in results:
        if len(people) == 20:
            break

        if result.object.__class__ == Voter:
            # If the voter has a contact profile linked to a supporter, use the supporter
            if result.object.contact_profile:
                try:
                    supporter = result.object.contact_profile.supporter
                    if supporter in supporters:
                        continue
                    supporters.append(supporter)
                    people.append(supporter)
                    continue
                except Supporter.DoesNotExist:
                    pass
            voters.append(result.object)

        elif result.object.__class__ == Supporter:
            supporters.append(result.object)

        people.append(result.object)

    return render_to_response("core/select_person.html", {"supporters": supporters, "voters": voters})