Forum search
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 4 Sep 2013 11:35:03 +0000 (13:35 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 4 Sep 2013 11:35:03 +0000 (13:35 +0200)
edumed/locale/pl/LC_MESSAGES/django.mo
edumed/locale/pl/LC_MESSAGES/django.po
edumed/static/css/forum.css
edumed/static/css/forum.scss
edumed/templates/base_forum.html
forum/search_indexes.py [new file with mode: 0644]
forum/templates/forum/search_results.html [new file with mode: 0644]
forum/templates/search/indexes/pybb/post_text.txt [new file with mode: 0644]
forum/urls.py

index bd15844..6c2cbcf 100644 (file)
Binary files a/edumed/locale/pl/LC_MESSAGES/django.mo and b/edumed/locale/pl/LC_MESSAGES/django.mo differ
index ffd5d7b..86361c7 100644 (file)
@@ -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 <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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"
+
index d77a8b3..1c0b056 100644 (file)
@@ -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;
index 8cf6717..e1a3d58 100755 (executable)
@@ -13,6 +13,15 @@ ul.breadcrumb {
 
 
 .forum-body {
+
+    position: relative;
+
+    .search-result {
+        em {
+            background-color: yellow;
+        }
+    }
+
     .pagination {
         ul {
             margin: 0;
index 5948131..587a1e8 100755 (executable)
@@ -1,8 +1,10 @@
 {% extends "base.html" %}
+{% load i18n %}
 
 {% block body %}
 <div class="forum-body">
     {% block breadcrumb %}{% endblock %}
+    <a href="{% url 'forum_search' %}" style="position: absolute; top: 0; right: 5px;">{% trans 'Forum search' %}</a>
     {% block content %}{% endblock %}
 </div>
 {% endblock %}
diff --git a/forum/search_indexes.py b/forum/search_indexes.py
new file mode 100644 (file)
index 0000000..5add363
--- /dev/null
@@ -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 (file)
index 0000000..b656a40
--- /dev/null
@@ -0,0 +1,41 @@
+{% extends 'pybb/base.html' %}
+{% load i18n %}
+
+
+{% block content %}
+    
+        <h1>{% trans 'Search' %}</h1>
+        <form method="get">
+            {{form.q}}
+            <tr>
+                <td>&nbsp;</td>
+                <td>
+                    <input type="submit" value="{% trans 'Search' %}">
+                </td>
+            </tr>
+        </form>
+
+    {% if query %}
+        <hr/>
+        {% for result in page.object_list %}
+            <p class="search-result">
+                <strong>Temat:</strong> <a href="{{ result.object.get_absolute_url }}">{{ result.object.topic.name }}</a><br/>
+                {% autoescape off %}
+                {% for snippet in result.highlighted.text %}
+                    {{snippet}}{% if not forloop.last %} <strong>...</strong> {% endif %}
+                {% endfor %}
+                {% endautoescape %}
+            </p>
+        {% empty %}
+            <p>Brak wyników.</p>
+        {% endfor %}
+
+        {% if page.has_previous or page.has_next %}
+            <div>
+                {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Poprzednie{% if page.has_previous %}</a>{% endif %}
+                |
+                {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Następne &raquo;{% if page.has_next %}</a>{% endif %}
+            </div>
+        {% 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 (file)
index 0000000..c51be26
--- /dev/null
@@ -0,0 +1 @@
+{{object.body_text}}
\ No newline at end of file
index a0135fb..309e9a7 100644 (file)
@@ -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<forum_id>\d+)/topic/add/$', AddPostView.as_view()),
     url(r'^post/(?P<pk>\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