Skip to content
Snippets Groups Projects
Commit 3a8846de authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

wip - searching

parent 25aed6e7
No related branches found
No related tags found
2 merge requests!741Release,!740Add homepage article searching
...@@ -23,6 +23,7 @@ from wagtail.blocks import CharBlock, RichTextBlock ...@@ -23,6 +23,7 @@ from wagtail.blocks import CharBlock, RichTextBlock
from wagtail.contrib.routable_page.models import RoutablePageMixin, route from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from wagtail.fields import RichTextField, StreamField from wagtail.fields import RichTextField, StreamField
from wagtail.models import Page from wagtail.models import Page
from wagtail.search import index
from wagtailmetadata.models import MetadataPageMixin from wagtailmetadata.models import MetadataPageMixin
from elections2021.constants import REGION_CHOICES # pozor, import ze sousedního modulu from elections2021.constants import REGION_CHOICES # pozor, import ze sousedního modulu
...@@ -487,6 +488,23 @@ class MainArticlesPage( ...@@ -487,6 +488,23 @@ class MainArticlesPage(
} }
return JsonResponse(data=data, safe=False) return JsonResponse(data=data, safe=False)
@route(r"^search")
def search(self, request):
if request.method == "GET" and "q" in request.GET:
query = request.GET["q"]
results = MainArticlePage.objects.live().search(query)
return render(
"main/main_article_search.html",
{
"page": self,
"results": results,
}
)
else:
return HttpResponseRedirect(self.url)
def serve(self, request, *args, **kwargs): def serve(self, request, *args, **kwargs):
if request.META.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest": if request.META.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest":
if "months" in request.GET: if "months" in request.GET:
...@@ -552,6 +570,14 @@ class MainArticlePage( ...@@ -552,6 +570,14 @@ class MainArticlePage(
) )
tags = ClusterTaggableManager(through=MainArticleTag, blank=True) tags = ClusterTaggableManager(through=MainArticleTag, blank=True)
search_fields = Page.search_fields + [
index.SearchField("title"),
index.SearchField("author"),
index.SearchField("author_page"),
index.SearchField("perex"),
index.SearchField("content"),
]
### PANELS ### PANELS
content_panels = ArticleMixin.content_panels + [ content_panels = ArticleMixin.content_panels + [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment