Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wp
Browse files Browse the repository at this point in the history
egor-lukin committed Mar 26, 2021
1 parent 0a1b9ef commit 9e1eb3f
Showing 7 changed files with 64 additions and 9 deletions.
8 changes: 1 addition & 7 deletions lw/core/urls.py
Original file line number Diff line number Diff line change
@@ -11,17 +11,11 @@

urlpatterns = [
path('django-admin/', admin.site.urls),

path('admin/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),

path('search/', search_views.search, name='search'),

path('user/logout/', views.logout_view),

# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:
path('', include('lw.translations.urls')),
path('', include(wagtail_urls)),
]

5 changes: 4 additions & 1 deletion lw/home/jinja2/home/sidebar_content.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Поиск<br>
<form action="search/node" method="GET">
<input type="search" name="query" />
<input type="submit" value="search" />
</form>
ВК-виджет<br>
Ссылки
22 changes: 22 additions & 0 deletions lw/translations/jinja2/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.html" %}

{% block title %}Search{% endblock %}

{% block content %}
{% if search_results %}
<ul>
{% for result in search_results %}
<li>
<h4><a href="{{ result.specific.url }}">{{ result }}</a></h4>
{% if result.search_description %}
{{ result.search_description|safe }}
{% endif %}
</li>
{% endfor %}
</ul>
{% elif search_query %}
No results found
{% else %}
Please type something into the search box
{% endif %}
{% endblock %}
9 changes: 9 additions & 0 deletions lw/translations/models/book_page.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel

from wagtail.search import index
from django.utils import timezone

class BookPage(Page):
body = RichTextField(blank=True, null=True)

@@ -31,6 +34,12 @@ def children(self):
FieldPanel('readthesequences_link'),
]

search_fields = Page.search_fields + [
index.SearchField('title'),
index.SearchField('body'),
index.FilterField('date'),
]

def get_url_parts(self, *args, **kwargs):
(site_id, root_url, _) = super().get_url_parts(*args, **kwargs)
return (site_id, root_url, '/w/' + self.slug)
9 changes: 9 additions & 0 deletions lw/translations/models/translation_page.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@

from wagtailmedia.edit_handlers import MediaChooserPanel

from wagtail.search import index
from django.utils import timezone

class TranslationPage(Page):
body = RichTextField(blank=True)
author = models.CharField(max_length=100, blank=True, null=True)
@@ -37,6 +40,12 @@ class TranslationPage(Page):
MediaChooserPanel('audio'),
]

search_fields = Page.search_fields + [
index.SearchField('title'),
index.SearchField('body'),
index.FilterField('date'),
]

def get_url_parts(self, *args, **kwargs):
(site_id, root_url, _) = super().get_url_parts(*args, **kwargs)
return (site_id, root_url, '/w/' + self.slug)
6 changes: 6 additions & 0 deletions lw/translations/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('search/node', views.search, name='search'),
]
14 changes: 13 additions & 1 deletion lw/translations/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
from django.shortcuts import render
from django.http import HttpResponse
from wagtail.core.models import Page

# Create your views here.
def search(request):
search_query = request.GET.get('query', None)
if search_query:
search_results = Page.objects.live().search(search_query)
else:
search_results = Page.objects.none()

return render(request, 'search.html', {
'search_query': search_query,
'search_results': search_results,
})

0 comments on commit 9e1eb3f

Please sign in to comment.