Initial commit

This commit is contained in:
2024-08-27 20:33:44 +02:00
commit 1f1832267d
14794 changed files with 1599592 additions and 0 deletions

View 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 %}&amp;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 %}&amp;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 %}

View 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,
},
)