예제 #1
0
def search_advanced_view(request, tag_id=None):

    if request.method == 'POST':
        form = AdvancedSearchForm(request.POST)
        if form.is_valid():
            urlparams = request.POST.copy()
            # delete these from params as not required
            del urlparams['csrfmiddlewaretoken']
            del urlparams['submit']
            return HttpResponseRedirect(reverse('orb_search_advanced_results') + "?" + urlparams.urlencode())
    else:
        form = AdvancedSearchForm()

    return render(request, 'orb/search_advanced.html', {'form': form})
예제 #2
0
def search_advanced_view(request, tag_id=None):

    if request.method == 'POST':
        form = AdvancedSearchForm(request.POST)
        if form.is_valid():
            urlparams = request.POST.copy()
            # delete these from params as not required
            del urlparams['csrfmiddlewaretoken']
            del urlparams['submit']
            return HttpResponseRedirect(reverse('orb_search_advanced_results') + "?" + urlparams.urlencode())
    else:
        form = AdvancedSearchForm()

    return render(request, 'orb/search_advanced.html', {'form': form})
예제 #3
0
def search_advanced_results_view(request):

    form = AdvancedSearchForm(request.GET)

    if form.is_valid():
        q = form.cleaned_data.get('q')

        results, filter_tags = form.search()
        if q:
            search_results = SearchQuerySet().filter(
                content=q).models(Resource).values_list('pk', flat=True)
            results = results.filter(pk__in=search_results)

        paginator = Paginator(results, settings.ORB_PAGINATOR_DEFAULT)
        try:
            page = int(request.GET.get('page', 1))
        except ValueError:
            page = 1

        try:
            resources = paginator.page(page)
        except (EmptyPage, InvalidPage):
            resources = paginator.page(paginator.num_pages)

        search.send(sender=results,
                    query=q,
                    no_results=results.count(),
                    request=request,
                    type=SearchTracker.SEARCH_ADV,
                    page=page)
        license_tags = form.cleaned_data['license']
    else:
        filter_tags = Tag.objects.filter(pk=None)
        license_tags = []
        resources = Resource.objects.filter(pk=None)
        paginator = Paginator(resources, settings.ORB_PAGINATOR_DEFAULT)

    return render(
        request, 'orb/search_advanced_results.html', {
            'filter_tags': filter_tags,
            'license_tags': license_tags,
            'q': form.cleaned_data.get('q'),
            'page': resources,
            'total_results': paginator.count,
        })
예제 #4
0
def search_advanced_results_view(request):

    form = AdvancedSearchForm(request.GET)

    if form.is_valid():
        q = form.cleaned_data.get('q')

        results, filter_tags = form.search()
        if q:
            search_results = SearchQuerySet().filter(content=q).models(Resource).values_list('pk', flat=True)
            results = results.filter(pk__in=search_results)

        paginator = Paginator(results, settings.ORB_PAGINATOR_DEFAULT)
        try:
            page = int(request.GET.get('page', 1))
        except ValueError:
            page = 1

        try:
            resources = paginator.page(page)
        except (EmptyPage, InvalidPage):
            resources = paginator.page(paginator.num_pages)

        search.send(sender=results, query=q, no_results=results.count(),
                    request=request, type=SearchTracker.SEARCH_ADV, page=page)
        license_tags = form.cleaned_data['license']
    else:
        filter_tags = Tag.objects.filter(pk=None)
        license_tags = []
        resources = Resource.objects.filter(pk=None)
        paginator = Paginator(resources, settings.ORB_PAGINATOR_DEFAULT)

    return render(request, 'orb/search_advanced_results.html', {
        'filter_tags': filter_tags,
        'license_tags': license_tags,
        'q': form.cleaned_data.get('q'),
        'page': resources,
        'total_results': paginator.count,
    })