From 1e0e7cfcbfdf5b88839397b1a9a52f3433bff2cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 4 Sep 2013 13:35:03 +0200 Subject: [PATCH 1/1] Forum search --- edumed/locale/pl/LC_MESSAGES/django.mo | Bin 677 -> 722 bytes edumed/locale/pl/LC_MESSAGES/django.po | 6 ++- edumed/static/css/forum.css | 3 ++ edumed/static/css/forum.scss | 9 ++++ edumed/templates/base_forum.html | 2 + forum/search_indexes.py | 9 ++++ forum/templates/forum/search_results.html | 41 ++++++++++++++++++ .../search/indexes/pybb/post_text.txt | 1 + forum/urls.py | 16 ++++++- 9 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 forum/search_indexes.py create mode 100644 forum/templates/forum/search_results.html create mode 100644 forum/templates/search/indexes/pybb/post_text.txt diff --git a/edumed/locale/pl/LC_MESSAGES/django.mo b/edumed/locale/pl/LC_MESSAGES/django.mo index bd158445e84edb351902de677fca2161ccd473a2..6c2cbcf1d884c1b5003d7cc06b24e0b990f62e78 100644 GIT binary patch delta 175 zcmZ3=dWp6Eo)F7a1|VPoVi_Q|0b*7ljsap2C;(y}AT9)AJ|M0GVjUpv1>%E@3=F$~ zG(Qm6FflNQ0_h$gtq-IZ0coH#7%&4#AQx;0gIj)4X|6(XYGP4x21CHaq#gldT?0#9 l0}};9V=H4LZ3Cl?|B@K_s!FpHvlQ|Y71BWJC&w|l0{}y?96\n" "Language-Team: LANGUAGE \n" @@ -26,3 +26,7 @@ msgstr "Strona nie znaleziona" msgid "The page you were looking for doesn't exist." msgstr "Strona której szukasz nie została znaleziona." +#: templates/base_forum.html:7 +msgid "Forum search" +msgstr "Szukaj na forum" + diff --git a/edumed/static/css/forum.css b/edumed/static/css/forum.css index d77a8b3..1c0b056 100644 --- a/edumed/static/css/forum.css +++ b/edumed/static/css/forum.css @@ -6,9 +6,12 @@ ul.breadcrumb { display: inline; } .forum-body { + position: relative; /* --- Unread --- */ /* --- Moderation --- */ /* --- Mini pagination --- */ } + .forum-body .search-result em { + background-color: yellow; } .forum-body .pagination ul { margin: 0; padding: 0; diff --git a/edumed/static/css/forum.scss b/edumed/static/css/forum.scss index 8cf6717..e1a3d58 100755 --- a/edumed/static/css/forum.scss +++ b/edumed/static/css/forum.scss @@ -13,6 +13,15 @@ ul.breadcrumb { .forum-body { + + position: relative; + + .search-result { + em { + background-color: yellow; + } + } + .pagination { ul { margin: 0; diff --git a/edumed/templates/base_forum.html b/edumed/templates/base_forum.html index 5948131..587a1e8 100755 --- a/edumed/templates/base_forum.html +++ b/edumed/templates/base_forum.html @@ -1,8 +1,10 @@ {% extends "base.html" %} +{% load i18n %} {% block body %}
{% block breadcrumb %}{% endblock %} + {% trans 'Forum search' %} {% block content %}{% endblock %}
{% endblock %} diff --git a/forum/search_indexes.py b/forum/search_indexes.py new file mode 100644 index 0000000..5add363 --- /dev/null +++ b/forum/search_indexes.py @@ -0,0 +1,9 @@ +from haystack import indexes +from pybb.models import Post + + +class PostIndex(indexes.SearchIndex, indexes.Indexable): + text = indexes.CharField(document=True, use_template=True) + + def get_model(self): + return Post diff --git a/forum/templates/forum/search_results.html b/forum/templates/forum/search_results.html new file mode 100644 index 0000000..b656a40 --- /dev/null +++ b/forum/templates/forum/search_results.html @@ -0,0 +1,41 @@ +{% extends 'pybb/base.html' %} +{% load i18n %} + + +{% block content %} + +

{% trans 'Search' %}

+
+ {{form.q}} + +   + + + + +
+ + {% if query %} +
+ {% for result in page.object_list %} +

+ Temat: {{ result.object.topic.name }}
+ {% autoescape off %} + {% for snippet in result.highlighted.text %} + {{snippet}}{% if not forloop.last %} ... {% endif %} + {% endfor %} + {% endautoescape %} +

+ {% empty %} +

Brak wyników.

+ {% endfor %} + + {% if page.has_previous or page.has_next %} +
+ {% if page.has_previous %}{% endif %}« Poprzednie{% if page.has_previous %}{% endif %} + | + {% if page.has_next %}{% endif %}Następne »{% if page.has_next %}{% endif %} +
+ {% endif %} + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/forum/templates/search/indexes/pybb/post_text.txt b/forum/templates/search/indexes/pybb/post_text.txt new file mode 100644 index 0000000..c51be26 --- /dev/null +++ b/forum/templates/search/indexes/pybb/post_text.txt @@ -0,0 +1 @@ +{{object.body_text}} \ No newline at end of file diff --git a/forum/urls.py b/forum/urls.py index a0135fb..309e9a7 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -1,4 +1,8 @@ from django.conf.urls import patterns, include, url +from haystack.query import SearchQuerySet +from haystack.views import SearchView, search_view_factory +from haystack.forms import SearchForm +from pybb.models import Post from .views import AddPostView, EditPostView @@ -6,4 +10,14 @@ from .views import AddPostView, EditPostView urlpatterns = patterns('', url(r'^forum/(?P\d+)/topic/add/$', AddPostView.as_view()), url(r'^post/(?P\d+)/edit/$', EditPostView.as_view()), -) \ No newline at end of file +) + +PostsSearchQuerySet = SearchQuerySet().models(Post).highlight() + +urlpatterns += patterns('haystack.views', + url(r'^szukaj/$', search_view_factory( + view_class = SearchView, + template = 'forum/search_results.html', + searchqueryset = PostsSearchQuerySet, + form_class = SearchForm + ), name='forum_search')) \ No newline at end of file -- 2.20.1