X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/fdc3961121619b598c7782e857362fc4e6a14164..a84463e418ebe210f8c0ae2f466ad268d31e4c36:/migdal/views.py?ds=inline diff --git a/migdal/views.py b/migdal/views.py index 84cd6fe..1f769a9 100644 --- a/migdal/views.py +++ b/migdal/views.py @@ -2,8 +2,10 @@ # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from django.http import Http404 from django.shortcuts import get_object_or_404, render, redirect from django.utils.translation import get_language +from fnpdjango.utils.views import set_current_object from migdal import api from migdal.forms import get_submit_form from migdal.models import Category, Entry @@ -11,6 +13,14 @@ from migdal import app_settings from haystack.views import SearchView +def main(request): + if app_settings.MAIN_PAGE_ENTRY is not None: + main_entry = Entry.objects.get(**app_settings.MAIN_PAGE_ENTRY) + return entry(request, entry=main_entry) + else: + return entry_list(request) + + def entry_list(request, type_db=None, category_slug=None): lang = request.LANGUAGE_CODE templates = ["migdal/entry/entry_list.html"] @@ -30,6 +40,9 @@ def entry_list(request, type_db=None, category_slug=None): else: category = None + if category: + set_current_object(request, category) + promobox = 5 if entry_type is None and category is None else None object_list = api.entry_list(entry_type=entry_type, category=category, @@ -43,15 +56,17 @@ def entry_list(request, type_db=None, category_slug=None): }) -def entry(request, type_db, slug): - lang = request.LANGUAGE_CODE - args = {'type': type_db, 'slug_%s' % lang: slug} - if not request.user.has_perm('migdal.change_entry'): - args['published_%s' % lang] = True - entry = get_object_or_404(Entry, **args) +def entry(request, type_db=None, slug=None, entry=None): + if entry is None: + lang = request.LANGUAGE_CODE + args = {'type': type_db, 'slug_%s' % lang: slug} + entry = get_object_or_404(Entry, **args) + if not entry.published and not request.user.has_perm('migdal.change_entry'): + raise Http404 + set_current_object(request, entry, in_url=slug is not None) templates = ["migdal/entry/entry_detail.html"] - if type_db is not None: + if entry.type is not None: templates = ["migdal/entry/%s/entry_detail.html" % type_db] + templates return render(request, templates, {'entry': entry})