当前位置: 首页>>代码示例>>Python>>正文


Python EmptySearchQuerySet.count方法代码示例

本文整理汇总了Python中haystack.query.EmptySearchQuerySet.count方法的典型用法代码示例。如果您正苦于以下问题:Python EmptySearchQuerySet.count方法的具体用法?Python EmptySearchQuerySet.count怎么用?Python EmptySearchQuerySet.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在haystack.query.EmptySearchQuerySet的用法示例。


在下文中一共展示了EmptySearchQuerySet.count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EmptySearchQuerySetTestCase

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import count [as 别名]
class EmptySearchQuerySetTestCase(TestCase):
    def setUp(self):
        super(EmptySearchQuerySetTestCase, self).setUp()
        self.esqs = EmptySearchQuerySet()
    
    def test_get_count(self):
        self.assertEqual(self.esqs.count(), 0)
        self.assertEqual(len(self.esqs.all()), 0)
    
    def test_filter(self):
        sqs = self.esqs.filter(content='foo')
        self.assert_(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)
    
    def test_exclude(self):
        sqs = self.esqs.exclude(content='foo')
        self.assert_(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)
    
    def test_slice(self):
        sqs = self.esqs.filter(content='foo')
        self.assert_(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)
        self.assertEqual(sqs[:10], [])
        
        try:
            sqs[4]
            self.fail()
        except IndexError:
            pass
开发者ID:flebel,项目名称:django-haystack,代码行数:32,代码来源:query.py

示例2: EmptySearchQuerySetTestCase

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import count [as 别名]
class EmptySearchQuerySetTestCase(TestCase):
    def setUp(self):
        super(EmptySearchQuerySetTestCase, self).setUp()
        self.esqs = EmptySearchQuerySet()
    
    def test_get_count(self):
        self.assertEqual(self.esqs.count(), 0)
        self.assertEqual(len(self.esqs.all()), 0)
    
    def test_filter(self):
        sqs = self.esqs.filter(content='foo')
        self.assert_(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)
    
    def test_exclude(self):
        sqs = self.esqs.exclude(content='foo')
        self.assert_(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)
开发者ID:collin,项目名称:django-haystack,代码行数:20,代码来源:query.py

示例3: EmptySearchQuerySetTestCase

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import count [as 别名]
class EmptySearchQuerySetTestCase(TestCase):
    def setUp(self):
        super(EmptySearchQuerySetTestCase, self).setUp()
        self.esqs = EmptySearchQuerySet()

    def test_get_count(self):
        self.assertEqual(self.esqs.count(), 0)
        self.assertEqual(len(self.esqs.all()), 0)

    def test_filter(self):
        sqs = self.esqs.filter(content="foo")
        self.assertTrue(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)

    def test_exclude(self):
        sqs = self.esqs.exclude(content="foo")
        self.assertTrue(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)

    def test_slice(self):
        sqs = self.esqs.filter(content="foo")
        self.assertTrue(isinstance(sqs, EmptySearchQuerySet))
        self.assertEqual(len(sqs), 0)
        self.assertEqual(sqs[:10], [])

        try:
            sqs[4]
            self.fail()
        except IndexError:
            pass

    def test_dictionary_lookup(self):
        """
        Ensure doing a dictionary lookup raises a TypeError so
        EmptySearchQuerySets can be used in templates.
        """
        self.assertRaises(TypeError, lambda: self.esqs["count"])
开发者ID:antonyr,项目名称:django-haystack,代码行数:39,代码来源:test_query.py

示例4: basic_search

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import count [as 别名]
def basic_search(request, template='search/search.html', load_all=True, form_class=ModelSearchForm, searchqueryset=None, context_class=RequestContext, extra_context=None, results_per_page=None, sort_by=[]):
    """
    A more traditional view that also demonstrate an alternative
    way to use Haystack.

    Useful as an example of for basing heavily custom views off of.

    Also has the benefit of thread-safety, which the ``SearchView`` class may
    not be.

    Template:: ``search/search.html``
    Context::
        * form
          An instance of the ``form_class``. (default: ``ModelSearchForm``)
        * page
          The current page of search results.
        * paginator
          A paginator instance for the results.
        * query
          The query received by the form.
    """
    query = ''
    results = EmptySearchQuerySet()

    try:
        del request.session['selected_facets']
    except:
        pass
    if request.GET.get('q'):
        form = form_class(request.GET, searchqueryset=searchqueryset, load_all=load_all)

        if form.is_valid():
            query = form.cleaned_data['q']
            results = form.search()
    else:
        form = form_class(searchqueryset=searchqueryset, load_all=load_all)
        results = SearchQuerySet().all()

    selected_facets = request.GET.getlist('selected_facets')
    selected_date_facets = request.GET.getlist('selected_date_facets')
    selected_facets = FacetSet(facet_string_list=selected_facets,
            date_facet_string_list=selected_date_facets)

    request.session['selected_facets'] = selected_facets
    results = selected_facets.narrow(results)

    if not sort_by == ['tmp']:
        results = results.order_by(*sort_by)
    results = results.order_by('-score')
    if not template:
        return results
    count = results.count()
    paginator = Paginator(results, results_per_page or RESULTS_PER_PAGE)

    try:
        page = paginator.page(int(request.GET.get('page', 1)))
    except InvalidPage:
        raise Http404("No such page of results!")

    context = {
        'form': form,
        'page': page,
        'paginator': paginator,
        'query': query,
        'suggestion': None,
        'count': count,
    }

    if getattr(settings, 'HAYSTACK_INCLUDE_SPELLING', False):
        context['suggestion'] = form.get_suggestion()

    if extra_context:
        context.update(extra_context)

    return render_to_response(template, context, context_instance=context_class(request))
开发者ID:shaunokeefe,项目名称:gigs,代码行数:77,代码来源:views.py

示例5: search

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import count [as 别名]
def search(request, template='search/search.html', load_all=True, 
        form_class=ModelSearchForm, searchqueryset=None,
        extra_context=None, 
        results_per_page=None):
    """
    """
    context = RequestContext(request)
    query = ''
    results = EmptySearchQuerySet()

    if request.GET.get('q'):
        form = form_class(request.GET, searchqueryset=searchqueryset, load_all=load_all)

        if form.is_valid():
            query = form.cleaned_data['q']
            results = form.search()
            context.update({'last_search': query})
            # if return no result, try it again with autocomplete search word
            if results.count() == 0:
                results = SearchQuerySet().autocomplete(enfname=request.GET.get('q', ''))
    else:
        form = form_class(searchqueryset=searchqueryset, load_all=load_all)

    selected_facets_list = []
    if request.GET.getlist('selected_facets'):
        for facet in request.GET.getlist('selected_facets'):
            if ":" not in facet:
                continue
            field, value = facet.split(":", 1)
            results = results.narrow(u'%s:"%s"' % (field, value))
            # 生成页面的facet
            selected_facets_list.append(('&selected_facets='+facet, value)) 
     
    selected_facets_context = list({
        'name': i[1], 
        'rm_selected_facet': ''.join(list(j[0] for j in selected_facets_list if j!=i))} 
        for i in selected_facets_list)

    context.update({'selected_facets_context': selected_facets_context})
    def facet_field_to_selector(sqs, name, context_name):

        try:
            fields = sqs.facet(name).facet_counts()['fields'][name]
            return {'name': context_name,
                'exact_name': name,
                'options': list({'context': i} for i in fields)}
        except:
            pass
        return None

    selectors = []
    # 找出品牌的facet
    selectors.append(facet_field_to_selector(results, 'brand', '品牌'))
    
    # 找出品类的facet
    selectors.append(facet_field_to_selector(results, 'categ', '品类'))
    context.update({'selectors': selectors})
    
    rm_invalid_result = []
    for r in results:
        try:
            tmp = r._get_object()
            if tmp:
                rm_invalid_result.append(tmp)
        except:
            pass
    paginator = HXPaginator(rm_invalid_result, results_per_page or 40)
    page = int(request.GET.get('page', 1))
    try:
        templates = paginator.page(page)
    except PageNotAnInteger:
        page = 1
    except EmptyPage:
        page = paginator.num_pages

    context.update({
        'form': form,
        'templates': templates,
        'paginator': paginator,
        'query': query,
        'suggestion': None,
    })

    if results.query.backend.include_spelling:
        context['suggestion'] = form.get_suggestion()
    if extra_context:
        context.update(extra_context)

    return TemplateResponse(request, template, context)
开发者ID:haitunzzz,项目名称:Django-Project,代码行数:91,代码来源:views.py


注:本文中的haystack.query.EmptySearchQuerySet.count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。