1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.shortcuts import get_object_or_404, render
7 from migdal.models import Category, Entry
8 from migdal.settings import TYPES_DICT
11 def entry_list(request, type_db=None, category_slug=None):
12 lang = request.LANGUAGE_CODE
13 templates = ["migdal/entry/entry_list.html"]
16 category = get_object_or_404(Category, **{'slug_%s' % lang: category_slug})
20 entry_type = TYPES_DICT[type_db]
21 # TODO: if it's the only on main, redirect to main
22 templates = ["migdal/entry/%s/entry_list.html" % type_db] + templates
26 object_list = api.entry_list(entry_type=entry_type, category=category)
28 return render(request, templates, {
29 'object_list': object_list,
31 'entry_type': entry_type,
35 def entry(request, type_db, slug):
36 lang = request.LANGUAGE_CODE
37 args = {'type': type_db, 'slug_%s' % lang: slug, 'published_%s' % lang: True}
38 # TODO: preview for admins
39 entry = get_object_or_404(Entry, **args)
41 templates = ["migdal/entry/entry_detail.html"]
42 if type_db is not None:
43 templates = ["migdal/entry/%s/entry_detail.html" % type_db] + templates
44 return render(request, templates, {'entry': entry})