Allow null fields in indexed objects
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Tue, 28 Aug 2012 10:38:56 +0000 (12:38 +0200)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Tue, 28 Aug 2012 10:38:56 +0000 (12:38 +0200)
Show only published entries
Translate /search url

migdal/locale/pl/LC_MESSAGES/django.mo
migdal/locale/pl/LC_MESSAGES/django.po
migdal/urls.py
migdal/views.py
prawokultury/templates/base.html
prawokultury/urls.py

index c7885fb..83ff231 100644 (file)
Binary files a/migdal/locale/pl/LC_MESSAGES/django.mo and b/migdal/locale/pl/LC_MESSAGES/django.mo differ
index 5338d10..4588ee9 100644 (file)
@@ -7,9 +7,9 @@ msgid ""
 msgstr ""
 "Project-Id-Version: django-migdal 0.1\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-08-28 12:10+0200\n"
-"PO-Revision-Date: 2012-08-28 12:14+0100\n"
-"Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
+"POT-Creation-Date: 2012-08-28 12:37+0200\n"
+"PO-Revision-Date: 2012-08-28 12:38+0100\n"
+"Last-Translator: Marcin Koziej <marcin@lolownia.org>\n"
 "Language-Team: FNP <fundacja@nowoczesnapolska.org.pl>\n"
 "Language: Polish\n"
 "MIME-Version: 1.0\n"
@@ -72,8 +72,8 @@ msgid "category"
 msgstr "kategoria"
 
 #: models.py:19
-#: urls.py:40
-#: urls.py:42
+#: urls.py:41
+#: urls.py:43
 msgid "categories"
 msgstr "kategorie"
 
@@ -142,15 +142,19 @@ msgstr "opublikowane"
 msgid "file"
 msgstr "plik"
 
-#: urls.py:37
 #: urls.py:38
+#: urls.py:39
 msgid "submit"
 msgstr "wyslij"
 
-#: urls.py:38
+#: urls.py:39
 msgid "thanks"
 msgstr "dzieki"
 
+#: urls.py:45
+msgid "search"
+msgstr "szukaj"
+
 #: templates/comments/migdal/entry/preview.html:19
 msgid "Please correct the error below"
 msgid_plural "Please correct the errors below"
index 63832f4..c7db6f4 100644 (file)
@@ -6,6 +6,7 @@ from django.conf.urls import patterns, include, url, handler404
 from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import string_concat
 from migdal import feeds, app_settings
+from migdal.views import SearchPublishedView
 from migdal.helpers import i18n_patterns
 
 pats = []
@@ -41,6 +42,7 @@ urlpatterns += i18n_patterns('',
         'migdal.views.entry_list', name='migdal_category'),
     url(string_concat(r'^', _('categories'), r'/(?P<category_slug>[^/]*)/rss.xml$'),
         feeds.EntriesFeed(), name='migdal_category_feed'),
+    url(string_concat(r'^', _('search')), SearchPublishedView(), name='search'),
     # type-specific views
     *pats
 )
index befa950..594444d 100644 (file)
@@ -3,10 +3,12 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from django.shortcuts import get_object_or_404, render, redirect
+from django.utils.translation import get_language
 from migdal import api
 from migdal.forms import get_submit_form
 from migdal.models import Category, Entry
 from migdal import app_settings
+from haystack.views import SearchView
 
 
 def entry_list(request, type_db=None, category_slug=None):
@@ -67,4 +69,22 @@ def submit(request):
         })
 
 def submit_thanks(request):
-    return render(request, "migdal/entry/submit_thanks.html")
\ No newline at end of file
+    return render(request, "migdal/entry/submit_thanks.html")
+
+
+class SearchPublishedView(SearchView):
+    def __init__(self, *args, **kwargs):
+        super(SearchPublishedView, self).__init__(*args, **kwargs)
+
+    def get_results(self):
+        results = super(SearchPublishedView, self).get_results()
+        lang_code = get_language()
+        def is_published(entity):
+            print "is published? %s, %s" % (entity.published_pl, entity.published_en) 
+            if isinstance(entity, Entry):
+                return getattr(entity, "published_%s" % lang_code) == True
+            else:
+                return True
+        results = filter(lambda r: is_published(r.object), results)
+        print results
+        return results
index 3d36dcf..9977e37 100755 (executable)
@@ -36,7 +36,7 @@
 
         <div id="menu-bar">
         <div class="bar-right">
-            <form id="search-form" method="GET" action="/search/"><input name="q" /><button>
+            <form id="search-form" method="GET" action="{% url 'search' %}"><input name="q" /><button>
                 <img src="{% static "img/search.png" %}" alt="{% trans "Search" %}" />
             </button></form>
         </div>
index 1a2faa8..4db309c 100644 (file)
@@ -19,7 +19,6 @@ urlpatterns = patterns('',
     url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
             'document_root': settings.MEDIA_ROOT,
         }),
-    url(r'^search/', include('haystack.urls')),
 ) + i18n_patterns('',
     url(string_concat(r'^', _('events'), r'/'), include('events.urls')),
     url(r'^comments/', include('django_comments_xtd.urls')),