From 9f02a501d14c64933d1cea2107cf0bd5ff93d429 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Tue, 28 Aug 2012 12:38:56 +0200 Subject: [PATCH 1/1] Allow null fields in indexed objects Show only published entries Translate /search url --- migdal/locale/pl/LC_MESSAGES/django.mo | Bin 4197 -> 4208 bytes migdal/locale/pl/LC_MESSAGES/django.po | 18 +++++++++++------- migdal/urls.py | 2 ++ migdal/views.py | 22 +++++++++++++++++++++- prawokultury/templates/base.html | 2 +- prawokultury/urls.py | 1 - 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/migdal/locale/pl/LC_MESSAGES/django.mo b/migdal/locale/pl/LC_MESSAGES/django.mo index c7885fba001669fe8f20062eec0ba07589a38cca..83ff231d4a3281c27bfaeaa1f13ab858c8dc549c 100644 GIT binary patch delta 1122 zcmZA0T}TvB6u|MbIlH!-rfDKX>9$ZH_Tjdcx|(DJMrBb6flx50qb1V%zWm=94zK@SxK^^inH6qJP$$ins%6#b8$r-qsN-E-&8opbKp{T|Imhd-A% zBf`yd>llE$_3<R4u32!5vccP@;U(>^?{{i6Ie3AeF delta 1092 zcmY+?Ur19?9KiA4++1#!Gc6>k97x$;-JEl>{!kgzLng@ZE#jhq=+f90K?I8=gr16< z4?=$^f)KKY#DX3QN+{|fA4-g31?fXj=!-!?(D&zlFJ11vpYuEC+_T^BoGpbH!udj# zZ&bM2csBBU_K0-i4KFXQIiJXL{D?Pkth6{U;TH)Kr?3o9;wtPzrpg)Qmb2ysTuVHR z`*9QlB6)dFLq90kgm0(|E#o@;i>tAU&I+u<6gFZEhp`f$;Cg(Gg+{%1(e^3vir7QeH2 z*8GGaeqX-Q;FcxxH)=v9><_nu%nhgu*Q3tgVQ~yKv82TZEIxwE9A^j4GTu&>x3QMR zqxcl_jL8og>MztvWleDh%FJri@y)15unqe$VdHmEznefk<0;exUtu-Qpzi3r#f#WQ z?5$w`lQgbzU1 zM|aO0*ZtQI9@3#__}B(s;7SD+&!8^&0d=7-7B8SywrKvb{!;#t+8;tKpcctp8c+*s zwefwstmCNJX?CL~b^^81O+0aT${X_}-0$8VPn+A}tMjzFr+qcs8CtoTd2iuqDTe>O zb$4Qu6TT6jyC*PG5{uh-xyByta1RCRC!2!he)nKy(?324b)x_P 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 @@