本文整理匯總了Python中wagtail.search.models.Query.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Query.get方法的具體用法?Python Query.get怎麽用?Python Query.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.search.models.Query
的用法示例。
在下文中一共展示了Query.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_get_search_promotions_template_tag
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_get_search_promotions_template_tag(self):
# Create a search pick to the root page
pick = SearchPromotion.objects.create(
query=Query.get("root page"),
page_id=1,
sort_order=0,
description="First search pick",
)
# Create another search pick against a different query
SearchPromotion.objects.create(
query=Query.get("root page again"),
page_id=1,
sort_order=0,
description="Second search pick",
)
# Check
search_picks = list(get_search_promotions("root page"))
self.assertEqual(search_picks, [pick])
示例2: test_results_are_ordered_alphabetically
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_results_are_ordered_alphabetically(self):
self.make_search_picks()
SearchPromotion.objects.create(
query=Query.get("aaargh snake"),
page_id=1,
sort_order=0,
description="ooh, it's a snake",
)
response = self.client.get(reverse('wagtailsearchpromotions:index'))
# Check response
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailsearchpromotions/index.html')
# "aargh snake" should be the first result alphabetically
self.assertEqual(response.context['queries'][0].query_string, "aaargh snake")
示例3: test_post
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_post(self):
# Submit
post_data = {
'query_string': "test",
'editors_picks-TOTAL_FORMS': 1,
'editors_picks-INITIAL_FORMS': 0,
'editors_picks-MAX_NUM_FORMS': 1000,
'editors_picks-0-DELETE': '',
'editors_picks-0-ORDER': 0,
'editors_picks-0-page': 1,
'editors_picks-0-description': "Hello",
}
response = self.client.post(reverse('wagtailsearchpromotions:add'), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse('wagtailsearchpromotions:index'))
# Check that the search pick was created
self.assertTrue(Query.get('test').editors_picks.filter(page_id=1).exists())
示例4: entries_search
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def entries_search(self, request, *args, **kwargs):
search_query = request.GET.get('q', None)
self.entries = self.get_entries()
if search_query:
self.entries = self.entries.search(search_query)
self.search_term = search_query
self.search_type = _('search')
Query.get(search_query).add_hit()
return Page.serve(self, request, *args, **kwargs)
示例5: search
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def search(request):
search_query = request.GET.get('query', None)
page = request.GET.get('page', 1)
# Search
if search_query:
search_results = Page.objects.live().search(search_query)
query = Query.get(search_query)
# Record hit
query.add_hit()
else:
search_results = Page.objects.none()
# Pagination
paginator = Paginator(search_results, 10)
try:
search_results = paginator.page(page)
except PageNotAnInteger:
search_results = paginator.page(1)
except EmptyPage:
search_results = paginator.page(paginator.num_pages)
return render(request, 'search/search.html', {
'search_query': search_query,
'search_results': search_results,
})
示例6: search
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def search(request):
search_query = request.GET.get('q', None)
page = request.GET.get('page', 1)
# Search
if search_query:
search_results = Page.objects.live().search(search_query)
query = Query.get(search_query)
# Record hit
query.add_hit()
else:
search_results = Page.objects.none()
# Pagination
paginator = Paginator(search_results, 10)
try:
search_results = paginator.page(page)
except PageNotAnInteger:
search_results = paginator.page(1)
except EmptyPage:
search_results = paginator.page(paginator.num_pages)
return render(request, 'search/search.html', {
'search_query': search_query,
'search_results': search_results,
})
示例7: search
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def search(request):
search_query = request.GET.get('query', None)
page = request.GET.get('page', 1)
# Search
if search_query:
search_results = Page.objects.live().search(search_query)
query = Query.get(search_query)
# Record hit
query.add_hit()
else:
search_results = Page.objects.none()
# Pagination
paginator = Paginator(search_results, 10)
try:
search_results = paginator.page(page)
except PageNotAnInteger:
search_results = paginator.page(1)
except EmptyPage:
search_results = paginator.page(paginator.num_pages)
return TemplateResponse(request, 'search/search.html', {
'search_query': search_query,
'search_results': search_results,
})
示例8: test_search_pick_create
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_search_pick_create(self):
# Create a search pick to the root page
SearchPromotion.objects.create(
query=Query.get("root page"),
page_id=1,
sort_order=0,
description="First search promotion",
)
# Check
self.assertEqual(Query.get("root page").editors_picks.count(), 1)
self.assertEqual(Query.get("root page").editors_picks.first().page_id, 1)
示例9: test_search_pick_ordering
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_search_pick_ordering(self):
# Add 3 search picks in a different order to their sort_order values
# They should be ordered by their sort order values and not their insertion order
SearchPromotion.objects.create(
query=Query.get("root page"),
page_id=1,
sort_order=0,
description="First search pick",
)
SearchPromotion.objects.create(
query=Query.get("root page"),
page_id=1,
sort_order=2,
description="Last search pick",
)
SearchPromotion.objects.create(
query=Query.get("root page"),
page_id=1,
sort_order=1,
description="Middle search pick",
)
# Check
self.assertEqual(Query.get("root page").editors_picks.count(), 3)
self.assertEqual(Query.get("root page").editors_picks.first().description, "First search pick")
self.assertEqual(Query.get("root page").editors_picks.last().description, "Last search pick")
示例10: test_simple
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_simple(self):
response = self.client.get(reverse('wagtailsearchpromotions:index'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailsearchpromotions/index.html')
示例11: make_search_picks
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def make_search_picks(self):
for i in range(50):
SearchPromotion.objects.create(
query=Query.get("query " + str(i)),
page_id=1,
sort_order=0,
description="First search pick",
)
示例12: test_pagination
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_pagination(self):
self.make_search_picks()
response = self.client.get(reverse('wagtailsearchpromotions:index'), {'p': 2})
# Check response
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailsearchpromotions/index.html')
# Check that we got the correct page
self.assertEqual(response.context['queries'].number, 2)
示例13: test_pagination_invalid
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_pagination_invalid(self):
self.make_search_picks()
response = self.client.get(reverse('wagtailsearchpromotions:index'), {'p': 'Hello World!'})
# Check response
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailsearchpromotions/index.html')
# Check that we got page one
self.assertEqual(response.context['queries'].number, 1)
示例14: test_pagination_out_of_range
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def test_pagination_out_of_range(self):
self.make_search_picks()
response = self.client.get(reverse('wagtailsearchpromotions:index'), {'p': 99999})
# Check response
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailsearchpromotions/index.html')
# Check that we got the last page
self.assertEqual(response.context['queries'].number, response.context['queries'].paginator.num_pages)
示例15: setUp
# 需要導入模塊: from wagtail.search.models import Query [as 別名]
# 或者: from wagtail.search.models.Query import get [as 別名]
def setUp(self):
self.login()
# Create an search pick to edit
self.query = Query.get("Hello")
self.search_pick = self.query.editors_picks.create(page_id=1, description="Root page")
self.search_pick_2 = self.query.editors_picks.create(page_id=2, description="Homepage")