-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Merlin Buczek
committed
Jun 4, 2019
1 parent
70bf6ea
commit 01b51b9
Showing
8 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.shortcuts import render | ||
|
||
from wagtail.core.models import Page | ||
from django.core.paginator import Paginator | ||
from wagtail.search.models import Query | ||
|
||
|
||
def search(request): | ||
search_query = request.GET.get('query', None) | ||
if search_query: | ||
search_results = Page.objects.live().search(search_query) | ||
|
||
# Log the query so Wagtail can suggest promoted results | ||
Query.get(search_query).add_hit() | ||
else: | ||
search_results = Page.objects.none() | ||
|
||
paginator = Paginator(search_results, 8) | ||
|
||
page = request.GET.get('page') | ||
search_results = paginator.get_page(page) | ||
|
||
return render(request, 'base/search_results.html', { | ||
'paginator': paginator, | ||
'search_query': search_query, | ||
'search_results': search_results, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{% extends "base.html" %} | ||
{% load wagtailcore_tags wagtailsearchpromotions_tags %} | ||
|
||
{% block title %}Search{% endblock %} | ||
|
||
{% block content %} | ||
<div class="section"> | ||
|
||
<h2 class="title is-2">Search: {{ search_query }}</h2> | ||
|
||
{% get_search_promotions search_query as search_promotions %} | ||
{% firstof search_results.number '1' as current %} | ||
|
||
{% if search_promotions and current|add:0 == 1 %} | ||
{% for search_promotion in search_promotions %} | ||
<div class="card is-important"> | ||
<div class="card-content"> | ||
{% if result.specific.category %} | ||
<a href="{% pageurl search_promotion.page.specific.category %}" class="category-label">{{ search_promotion.page.specific.category }}</a> | ||
{% endif %} | ||
<a href="{% pageurl search_promotion.page %}" class="title is-4">{{ search_promotion.page.title }}</a> | ||
{% if search_promotion.description %} | ||
<div class="content"> | ||
|
||
{{ search_promotion.description }} | ||
</div> | ||
|
||
{% endif %} | ||
</div> | ||
</div> | ||
{% endfor %} | ||
<br> | ||
{% endif %} | ||
|
||
{% for result in search_results %} | ||
<div class="card"> | ||
<div class="card-content"> | ||
<nav class="breadcrumb card-head"> | ||
<ul> | ||
{% for ancestor in result.get_ancestors|slice:"2:" %} | ||
<li><a href="{% pageurl ancestor %}">{{ ancestor }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
</nav> | ||
<a href="{% pageurl result %}" class="title is-4">{{ result.title }}</a> | ||
{% if result.search_description %} | ||
<div class="content"> | ||
|
||
{{ result.search_description|safe }} | ||
</div> | ||
|
||
{% endif %} | ||
</div> | ||
</div> | ||
{% endfor %} | ||
|
||
{% if not search_promotion and not search_results %} | ||
{% if search_query %} | ||
<p>No results found</p> | ||
{% else %} | ||
<p>Please type something into the search box</p> | ||
{% endif %} | ||
{% endif %} | ||
|
||
</div> | ||
|
||
<div class="section"> | ||
{% include 'base/components/pagination.html' with items=search_results %} | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters