本文整理汇总了Python中wagtail.wagtailsearch.models.Query类的典型用法代码示例。如果您正苦于以下问题:Python Query类的具体用法?Python Query怎么用?Python Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_reorder
def test_post_reorder(self):
# Check order before reordering
self.assertEqual(Query.get("Hello").editors_picks.all()[0], self.search_pick)
self.assertEqual(Query.get("Hello").editors_picks.all()[1], self.search_pick_2)
# Submit
post_data = {
'query_string': "Hello",
'editors_picks-TOTAL_FORMS': 2,
'editors_picks-INITIAL_FORMS': 2,
'editors_picks-MAX_NUM_FORMS': 1000,
'editors_picks-0-id': self.search_pick.id,
'editors_picks-0-DELETE': '',
'editors_picks-0-ORDER': 1, # Change
'editors_picks-0-page': 1,
'editors_picks-0-description': "Root page",
'editors_picks-1-id': self.search_pick_2.id,
'editors_picks-1-DELETE': '',
'editors_picks-1-ORDER': 0, # Change
'editors_picks-1-page': 2,
'editors_picks-1-description': "Homepage",
}
response = self.client.post(reverse('wagtailsearchpromotions:edit', args=(self.query.id, )), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse('wagtailsearchpromotions:index'))
# Check that the ordering has been saved correctly
self.assertEqual(SearchPromotion.objects.get(id=self.search_pick.id).sort_order, 1)
self.assertEqual(SearchPromotion.objects.get(id=self.search_pick_2.id).sort_order, 0)
# Check that the recommendations were reordered
self.assertEqual(Query.get("Hello").editors_picks.all()[0], self.search_pick_2)
self.assertEqual(Query.get("Hello").editors_picks.all()[1], self.search_pick)
示例2: get_articles
def get_articles(request, search_type, search_for):
"""
View will return search results based instant search
or clicking a category and name. Results will return
a paginated response.
"""
template_name = "home/caos_home_page_search.html"
unslug_search = search_for.replace('-', ' ')
if 'category' in search_type:
get_results = (CaosBlogPage.objects.live()
.search(unslug_search, fields=['category']))
query = Query.get(unslug_search)
query.add_hit()
elif 'author' in search_type:
get_results = (CaosBlogPage.objects.live()
.search(unslug_search, fields=['author']))
query = Query.get(unslug_search)
query.add_hit()
else:
get_results = CaosBlogPage.objects.none()
context = {
'search_results': get_results,
}
return render(request, template_name, context)
示例3: entries_search
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)
示例4: test_search_pick_create
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)
示例5: search
def search(request):
""" Simple Admin and Search Feature """
template_name = 'search/search.html'
search_query = request.GET.get('query', None)
page = request.GET.get('page', 1)
if search_query:
search_results = Page.objects.live().search(search_query)
query = Query.get(search_query)
query.add_hit()
else:
search_results = Page.objects.none()
paginator = (Paginator(search_results,
getattr(settings, 'MAX_PAGINATION_SEARCH', 10)))
try:
search_results = paginator.page(page)
except PageNotAnInteger:
search_results = paginator.page(1)
except EmptyPage:
search_results = paginator.page(paginator.num_pages)
context = {'search_query': search_query, 'search_results': search_results}
return render(request, template_name, context)
示例6: search
def search(request):
"""Search for 'query'."""
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})
示例7: search
def search(request):
search_query = request.GET.get('q', None)
page = request.GET.get('page', 1)
# Search
if search_query:
search_results = HomePage.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_results.html', {
'search_query': search_query,
'search_results': search_results,
'search_title': "Search for Adventure Capitalists: {0}".format(search_query)
})
示例8: search
def search(request):
# Search
search_query = request.GET.get('query', None)
if search_query:
search_results = Page.objects.live().search(search_query)
query = Query.get(search_query)
# Record hit
query.add_hit()
# Get search picks
search_picks = query.editors_picks.all()
else:
search_results = Page.objects.none()
search_picks = SearchPromotion.objects.none()
# Pagination
page = request.GET.get('page', 1)
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, 'swimtheme/search_results.html', {
'search_query': search_query,
'search_results': search_results,
'search_picks': search_picks,
})
示例9: add
def add(request):
if request.POST:
# Get query
query_form = search_forms.QueryForm(request.POST)
if query_form.is_valid():
query = Query.get(query_form['query_string'].value())
# Save search picks
searchpicks_formset = forms.SearchPromotionsFormSet(request.POST, instance=query)
if save_searchpicks(query, query, searchpicks_formset):
messages.success(request, _("Editor's picks for '{0}' created.").format(query), buttons=[
messages.button(reverse('wagtailsearchpromotions:edit', args=(query.id,)), _('Edit'))
])
return redirect('wagtailsearchpromotions:index')
else:
if len(searchpicks_formset.non_form_errors()):
# formset level error (e.g. no forms submitted)
messages.error(request, " ".join(error for error in searchpicks_formset.non_form_errors()))
else:
# specific errors will be displayed within form fields
messages.error(request, _("Recommendations have not been created due to errors"))
else:
searchpicks_formset = forms.SearchPromotionsFormSet()
else:
query_form = search_forms.QueryForm()
searchpicks_formset = forms.SearchPromotionsFormSet()
return render(request, 'wagtailsearchpromotions/add.html', {
'query_form': query_form,
'searchpicks_formset': searchpicks_formset,
})
示例10: search_content
def search_content(search_query):
# Search
search_results = Content.objects.live().exclude(url_path__startswith="/home/snippets/").search(search_query)
query = Query.get(search_query)
# Record hit
query.add_hit()
return search_results
示例11: setUp
def setUp(self):
self.login()
# Create an search pick to delete
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")
示例12: edit
def edit(request, query_id):
query = get_object_or_404(Query, id=query_id)
if request.POST:
# Get query
query_form = search_forms.QueryForm(request.POST)
# and the recommendations
searchpicks_formset = forms.SearchPromotionsFormSet(request.POST, instance=query)
if query_form.is_valid():
new_query = Query.get(query_form['query_string'].value())
# Save search picks
if save_searchpicks(query, new_query, searchpicks_formset):
messages.success(request, _("Editor's picks for '{0}' updated.").format(new_query), buttons=[
messages.button(reverse('wagtailsearchpromotions:edit', args=(query.id,)), _('Edit'))
])
return redirect('wagtailsearchpromotions:index')
else:
if len(searchpicks_formset.non_form_errors()):
messages.error(request, " ".join(error for error in searchpicks_formset.non_form_errors()))
# formset level error (e.g. no forms submitted)
else:
messages.error(request, _("Recommendations have not been saved due to errors"))
# specific errors will be displayed within form fields
else:
query_form = search_forms.QueryForm(initial=dict(query_string=query.query_string))
searchpicks_formset = forms.SearchPromotionsFormSet(instance=query)
return render(request, 'wagtailsearchpromotions/edit.html', {
'query_form': query_form,
'searchpicks_formset': searchpicks_formset,
'query': query,
})
示例13: loop_search
def loop_search(request):
search_query = request.GET.get('query', None)
page = request.GET.get('page', 1)
# Search
if search_query:
sandbox = IntranetHomePage.objects.get(title__contains='Sandbox')
search_results = Page.objects.live().not_descendant_of(sandbox).search(search_query)
query = Query.get(search_query)
# Record hit
query.add_hit()
# Get search picks
search_picks = query.editors_picks.all()
else:
search_results = Page.objects.none()
search_picks = SearchPromotion.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/loop_search.html', {
'search_query': search_query,
'search_results': search_results,
'search_picks': search_picks,
})
示例14: search
def search(request):
query_string = request.GET.get("q", "")
page = request.GET.get("p", 1)
# Search
if query_string != "":
search_results = models.Page.search_frontend(query_string)
# Get query object
query = Query.get(query_string)
# Add hit
query.add_hit()
# Pagination
paginator = Paginator(search_results, 10)
if paginator is not None:
try:
search_results = paginator.page(page)
except PageNotAnInteger:
search_results = paginator.page(1)
except EmptyPage:
search_results = paginator.page(paginator.num_pages)
else:
search_results = None
else:
query = None
search_results = None
# Render
if request.is_ajax():
template_name = getattr(settings, "WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX", "wagtailsearch/search_results.html")
else:
template_name = getattr(settings, "WAGTAILSEARCH_RESULTS_TEMPLATE", "wagtailsearch/search_results.html")
return render(request, template_name, dict(query_string=query_string, search_results=search_results, is_ajax=request.is_ajax(), query=query))
示例15: search
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,
})