From: Marcin Koziej Date: Tue, 28 Aug 2012 10:38:56 +0000 (+0200) Subject: Allow null fields in indexed objects X-Git-Url: https://git.mdrn.pl/prawokultury.git/commitdiff_plain/9f02a501d14c64933d1cea2107cf0bd5ff93d429?hp=3f6f55a25872c1d1465f7bdb59e8a766da9c51cc Allow null fields in indexed objects Show only published entries Translate /search url --- diff --git a/migdal/locale/pl/LC_MESSAGES/django.mo b/migdal/locale/pl/LC_MESSAGES/django.mo index c7885fb..83ff231 100644 Binary files a/migdal/locale/pl/LC_MESSAGES/django.mo and b/migdal/locale/pl/LC_MESSAGES/django.mo differ diff --git a/migdal/locale/pl/LC_MESSAGES/django.po b/migdal/locale/pl/LC_MESSAGES/django.po index 5338d10..4588ee9 100644 --- a/migdal/locale/pl/LC_MESSAGES/django.po +++ b/migdal/locale/pl/LC_MESSAGES/django.po @@ -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 \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 \n" "Language-Team: FNP \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" diff --git a/migdal/urls.py b/migdal/urls.py index 63832f4..c7db6f4 100644 --- a/migdal/urls.py +++ b/migdal/urls.py @@ -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[^/]*)/rss.xml$'), feeds.EntriesFeed(), name='migdal_category_feed'), + url(string_concat(r'^', _('search')), SearchPublishedView(), name='search'), # type-specific views *pats ) diff --git a/migdal/views.py b/migdal/views.py index befa950..594444d 100644 --- a/migdal/views.py +++ b/migdal/views.py @@ -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 diff --git a/prawokultury/templates/base.html b/prawokultury/templates/base.html index 3d36dcf..9977e37 100755 --- a/prawokultury/templates/base.html +++ b/prawokultury/templates/base.html @@ -36,7 +36,7 @@