Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
3a8846de
Commit
3a8846de
authored
2 years ago
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
wip - searching
parent
25aed6e7
No related branches found
No related tags found
2 merge requests
!741
Release
,
!740
Add homepage article searching
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main/models.py
+26
-0
26 additions, 0 deletions
main/models.py
with
26 additions
and
0 deletions
main/models.py
+
26
−
0
View file @
3a8846de
...
...
@@ -23,6 +23,7 @@ from wagtail.blocks import CharBlock, RichTextBlock
from
wagtail.contrib.routable_page.models
import
RoutablePageMixin
,
route
from
wagtail.fields
import
RichTextField
,
StreamField
from
wagtail.models
import
Page
from
wagtail.search
import
index
from
wagtailmetadata.models
import
MetadataPageMixin
from
elections2021.constants
import
REGION_CHOICES
# pozor, import ze sousedního modulu
...
...
@@ -487,6 +488,23 @@ class MainArticlesPage(
}
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
):
if
request
.
META
.
get
(
"
HTTP_X_REQUESTED_WITH
"
)
==
"
XMLHttpRequest
"
:
if
"
months
"
in
request
.
GET
:
...
...
@@ -552,6 +570,14 @@ class MainArticlePage(
)
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
content_panels
=
ArticleMixin
.
content_panels
+
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment