X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/8e82784fa2fe21d9c3828adbf43178a39c7cdea6..116e12f0b6388f3f3402d4a28fcef524e2c14159:/migdal/views.py diff --git a/migdal/views.py b/migdal/views.py index 07eeb50..1ece4cc 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.settings import TYPES_DICT, TYPES_ON_MAIN, TYPE_SUBMIT +from migdal import app_settings +from haystack.views import SearchView def entry_list(request, type_db=None, category_slug=None): @@ -14,13 +16,13 @@ def entry_list(request, type_db=None, category_slug=None): templates = ["migdal/entry/entry_list.html"] if type_db: - if TYPES_ON_MAIN == (type_db,): + if app_settings.TYPES_ON_MAIN == (type_db,): return redirect('migdal_main') - entry_type = TYPES_DICT[type_db] + entry_type = app_settings.TYPES_DICT[type_db] templates = ["migdal/entry/%s/entry_list.html" % type_db] + templates - submit = type_db == TYPE_SUBMIT + submit = type_db == app_settings.TYPE_SUBMIT else: - submit = TYPES_ON_MAIN == (TYPE_SUBMIT,) + submit = app_settings.TYPES_ON_MAIN == (app_settings.TYPE_SUBMIT,) entry_type = None if category_slug: @@ -67,4 +69,21 @@ 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): + 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