예제 #1
0
def search(request):
    """
        Display search form/results for events (using distance-based search).

        Template: events/search.html

        Context:
            form           - ``anthill.events.forms.SearchForm``
            event_list     - events in the near future
            searched       - True/False based on if a search was done
            search_results - list of results (may be empty)
    """
    upcoming_events = Event.objects.future().select_related()[0:5]
    if request.GET:
        form = SearchForm(request.GET)
        form.is_valid()
        name = form.cleaned_data['name']
        location = form.cleaned_data['location']
        location_range = form.cleaned_data['location_range']

        # only events that haven't happened
        events = Event.objects.future().select_related()
        if name:
            events = events.filter(title__icontains=name)
        if location:
            events = events.search_by_distance(location, location_range)
        context = {'form': form, 'searched': True, 'search_results': events,
                   'event_list': upcoming_events}
    else:
        context = {'form': SearchForm(), 'event_list': upcoming_events}

    return render_to_response('events/search.html', context,
                              context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: robbie/anthill
def search(request):
    upcoming_events = Event.objects.future().select_related()[0:5]
    if request.GET:
        form = SearchForm(request.GET)
        form.is_valid()
        name = form.cleaned_data['name']
        location = form.cleaned_data['location']
        location_range = form.cleaned_data['location_range']

        # only events that haven't happened
        events = Event.objects.future().select_related()
        if name:
            events = events.filter(title__icontains=name)
        if location:
            events = events.search_by_distance(location, location_range)
        context = {'form': form, 'searched': True, 'search_results': events,
                   'event_list': upcoming_events}
    else:
        context = {'form': SearchForm(), 'event_list': upcoming_events}

    return render_to_response('events/search.html', context,
                              context_instance=RequestContext(request))
예제 #3
0
def search(request):
    """
        Display search form/results for events (using distance-based search).

        Template: events/search.html

        Context:
            form           - ``anthill.events.forms.SearchForm``
            event_list     - events in the near future
            searched       - True/False based on if a search was done
            search_results - list of results (may be empty)
    """
    upcoming_events = Event.objects.future().select_related()[0:5]
    if request.GET:
        form = SearchForm(request.GET)
        form.is_valid()
        name = form.cleaned_data['name']
        location = form.cleaned_data['location']
        location_range = form.cleaned_data['location_range']

        # only events that haven't happened
        events = Event.objects.future().select_related()
        if name:
            events = events.filter(title__icontains=name)
        if location:
            events = events.search_by_distance(location, location_range)
        context = {
            'form': form,
            'searched': True,
            'search_results': events,
            'event_list': upcoming_events
        }
    else:
        context = {'form': SearchForm(), 'event_list': upcoming_events}

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