From: Aleksander Łukasz Date: Wed, 4 Sep 2013 11:35:03 +0000 (+0200) Subject: Forum search X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/1e0e7cfcbfdf5b88839397b1a9a52f3433bff2cf Forum search --- diff --git a/edumed/locale/pl/LC_MESSAGES/django.mo b/edumed/locale/pl/LC_MESSAGES/django.mo index bd15844..6c2cbcf 100644 Binary files a/edumed/locale/pl/LC_MESSAGES/django.mo and b/edumed/locale/pl/LC_MESSAGES/django.mo differ diff --git a/edumed/locale/pl/LC_MESSAGES/django.po b/edumed/locale/pl/LC_MESSAGES/django.po index ffd5d7b..86361c7 100644 --- a/edumed/locale/pl/LC_MESSAGES/django.po +++ b/edumed/locale/pl/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-11-19 15:57+0100\n" +"POT-Creation-Date: 2013-09-04 13:32+0200\n" "PO-Revision-Date: 2012-11-19 15:58+0100\n" "Last-Translator: Radek Czajka \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