Exemplo n.º 1
0
 def merge_stops(self, request, queryset):
     base_stop = BaseStop(common_name=queryset[0].common_name, common_city=queryset[1].common_name)
     base_stop.save()
     for obj in queryset:
         obj.parent = base_stop
         obj.save()
     self.message_user(request, "%s added as logical parent stop" % base_stop)
Exemplo n.º 2
0
def search(request, term=None):
    form = search_term = result_list = results = None
    if request.POST:
        form = SearchForm(request.POST)
        if form.is_valid():
            search_term = form.cleaned_data['terms']
    if term is not None:
        # Note, we might need to do some cleanup here
        search_term = term
    if search_term is not None:
        # Get results
        result_list = BaseStop.search(search_term)

        paginator = Paginator(result_list, 25)
        page = request.GET.get('page', 1)
        try:
            results = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            results = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            results = paginator.page(paginator.num_pages)
    if form is None:
        form = SearchForm()

    return render(request, 'stops/results.html', {
        'results': results,
        'term': search_term,
        'form': form
    })