Initial commit
This commit is contained in:
0
env/lib/python3.10/site-packages/wagtail/project_template/search/__init__.py
vendored
Normal file
0
env/lib/python3.10/site-packages/wagtail/project_template/search/__init__.py
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/project_template/search/__pycache__/views.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/project_template/search/__pycache__/views.cpython-310.pyc
vendored
Normal file
Binary file not shown.
38
env/lib/python3.10/site-packages/wagtail/project_template/search/templates/search/search.html
vendored
Normal file
38
env/lib/python3.10/site-packages/wagtail/project_template/search/templates/search/search.html
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{% templatetag openblock %} extends "base.html" {% templatetag closeblock %}
|
||||
{% templatetag openblock %} load static wagtailcore_tags {% templatetag closeblock %}
|
||||
|
||||
{% templatetag openblock %} block body_class {% templatetag closeblock %}template-searchresults{% templatetag openblock %} endblock {% templatetag closeblock %}
|
||||
|
||||
{% templatetag openblock %} block title {% templatetag closeblock %}Search{% templatetag openblock %} endblock {% templatetag closeblock %}
|
||||
|
||||
{% templatetag openblock %} block content {% templatetag closeblock %}
|
||||
<h1>Search</h1>
|
||||
|
||||
<form action="{% templatetag openblock %} url 'search' {% templatetag closeblock %}" method="get">
|
||||
<input type="text" name="query"{% templatetag openblock %} if search_query {% templatetag closeblock %} value="{% templatetag openvariable %} search_query {% templatetag closevariable %}"{% templatetag openblock %} endif {% templatetag closeblock %}>
|
||||
<input type="submit" value="Search" class="button">
|
||||
</form>
|
||||
|
||||
{% templatetag openblock %} if search_results {% templatetag closeblock %}
|
||||
<ul>
|
||||
{% templatetag openblock %} for result in search_results {% templatetag closeblock %}
|
||||
<li>
|
||||
<h4><a href="{% templatetag openblock %} pageurl result {% templatetag closeblock %}">{% templatetag openvariable %} result {% templatetag closevariable %}</a></h4>
|
||||
{% templatetag openblock %} if result.search_description {% templatetag closeblock %}
|
||||
{% templatetag openvariable %} result.search_description {% templatetag closevariable %}
|
||||
{% templatetag openblock %} endif {% templatetag closeblock %}
|
||||
</li>
|
||||
{% templatetag openblock %} endfor {% templatetag closeblock %}
|
||||
</ul>
|
||||
|
||||
{% templatetag openblock %} if search_results.has_previous {% templatetag closeblock %}
|
||||
<a href="{% templatetag openblock %} url 'search' {% templatetag closeblock %}?query={% templatetag openvariable %} search_query|urlencode {% templatetag closevariable %}&page={% templatetag openvariable %} search_results.previous_page_number {% templatetag closevariable %}">Previous</a>
|
||||
{% templatetag openblock %} endif {% templatetag closeblock %}
|
||||
|
||||
{% templatetag openblock %} if search_results.has_next {% templatetag closeblock %}
|
||||
<a href="{% templatetag openblock %} url 'search' {% templatetag closeblock %}?query={% templatetag openvariable %} search_query|urlencode {% templatetag closevariable %}&page={% templatetag openvariable %} search_results.next_page_number {% templatetag closevariable %}">Next</a>
|
||||
{% templatetag openblock %} endif {% templatetag closeblock %}
|
||||
{% templatetag openblock %} elif search_query {% templatetag closeblock %}
|
||||
No results found
|
||||
{% templatetag openblock %} endif {% templatetag closeblock %}
|
||||
{% templatetag openblock %} endblock {% templatetag closeblock %}
|
||||
46
env/lib/python3.10/site-packages/wagtail/project_template/search/views.py
vendored
Normal file
46
env/lib/python3.10/site-packages/wagtail/project_template/search/views.py
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
|
||||
from django.template.response import TemplateResponse
|
||||
|
||||
from wagtail.models import Page
|
||||
|
||||
# To enable logging of search queries for use with the "Promoted search results" module
|
||||
# <https://docs.wagtail.org/en/stable/reference/contrib/searchpromotions.html>
|
||||
# uncomment the following line and the lines indicated in the search function
|
||||
# (after adding wagtail.contrib.search_promotions to INSTALLED_APPS):
|
||||
|
||||
# from wagtail.contrib.search_promotions.models import Query
|
||||
|
||||
|
||||
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)
|
||||
|
||||
# To log this query for use with the "Promoted search results" module:
|
||||
|
||||
# query = Query.get(search_query)
|
||||
# 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,
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user