예제 #1
0
파일: views.py 프로젝트: robbie/anthill
def search(request):
    context = { 'form': SearchForm() }

    if request.GET:
        form = SearchForm(request.GET)
        if form.is_valid():
            location = form.cleaned_data['location']
            skills = form.cleaned_data['skills']
            name = form.cleaned_data['name']
            position = form.cleaned_data['position']
            location_range = form.cleaned_data['location_range']

            users = Profile.objects.all().select_related().exclude(user__id=request.user.id)
            if skills:
                tags = [t.strip() for t in skills.split(',')]
                for tag in tags:
                    users = users.filter(skills__icontains=tag)
            if position:
                users = users.filter(role=position)
            if name:
                users = users.filter(user__first_name__icontains=name)
            if location:
                users = users.search_by_distance(location, location_range)
            context = { 'form': form, 'searched': True, 'search_results': users }

    return render_to_response('people/search.html', context,
                             context_instance=RequestContext(request))
예제 #2
0
def search(request):
    """
        Location-based search for users.

        Template: people/search.html

        Context:
            form           - ``anthill.people.forms.SearchForm`` instance
            searched       - flag indicating if search has taken place
            search_results - list of search results (may be empty)
    """
    context = {'form': SearchForm()}

    if request.GET:
        form = SearchForm(request.GET)
        if form.is_valid():
            location = form.cleaned_data['location']
            skills = form.cleaned_data['skills']
            name = form.cleaned_data['name']
            position = form.cleaned_data['position']
            location_range = form.cleaned_data['location_range']

            users = Profile.objects.all().select_related().exclude(
                user__id=request.user.id)
            if skills:
                tags = [t.strip() for t in skills.split(',')]
                for tag in tags:
                    users = users.filter(skills__icontains=tag)
            if position:
                users = users.filter(role=position)
            if name:
                users = users.filter(user__first_name__icontains=name)
            if location:
                users = users.search_by_distance(location, location_range)
            context = {'form': form, 'searched': True, 'search_results': users}

    return render_to_response('people/search.html',
                              context,
                              context_instance=RequestContext(request))
예제 #3
0
def search(request):
    """
        Location-based search for users.

        Template: people/search.html

        Context:
            form           - ``anthill.people.forms.SearchForm`` instance
            searched       - flag indicating if search has taken place
            search_results - list of search results (may be empty)
    """
    context = { 'form': SearchForm() }

    if request.GET:
        form = SearchForm(request.GET)
        if form.is_valid():
            location = form.cleaned_data['location']
            skills = form.cleaned_data['skills']
            name = form.cleaned_data['name']
            position = form.cleaned_data['position']
            location_range = form.cleaned_data['location_range']

            users = Profile.objects.all().select_related().exclude(user__id=request.user.id)
            if skills:
                tags = [t.strip() for t in skills.split(',')]
                for tag in tags:
                    users = users.filter(skills__icontains=tag)
            if position:
                users = users.filter(role=position)
            if name:
                users = users.filter(user__first_name__icontains=name)
            if location:
                users = users.search_by_distance(location, location_range)
            context = { 'form': form, 'searched': True, 'search_results': users }

    return render_to_response('people/search.html', context,
                             context_instance=RequestContext(request))