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, redirect
7 from migdal.forms import get_submit_form
8 from migdal.models import Category, Entry
9 from migdal.settings import TYPES_DICT, TYPES_ON_MAIN, TYPE_SUBMIT
12 def entry_list(request, type_db=None, category_slug=None):
13 lang = request.LANGUAGE_CODE
14 templates = ["migdal/entry/entry_list.html"]
17 if TYPES_ON_MAIN == (type_db,):
18 return redirect('migdal_main')
19 entry_type = TYPES_DICT[type_db]
20 templates = ["migdal/entry/%s/entry_list.html" % type_db] + templates
21 submit = type_db == TYPE_SUBMIT
23 submit = TYPES_ON_MAIN == (TYPE_SUBMIT,)
27 category = get_object_or_404(Category, **{'slug_%s' % lang: category_slug})
31 object_list = api.entry_list(entry_type=entry_type, category=category)
33 return render(request, templates, {
34 'object_list': object_list,
36 'entry_type': entry_type,
41 def entry(request, type_db, slug):
42 lang = request.LANGUAGE_CODE
43 args = {'type': type_db, 'slug_%s' % lang: slug, 'published_%s' % lang: True}
44 # TODO: preview for admins
45 entry = get_object_or_404(Entry, **args)
47 templates = ["migdal/entry/entry_detail.html"]
48 if type_db is not None:
49 templates = ["migdal/entry/%s/entry_detail.html" % type_db] + templates
50 return render(request, templates, {'entry': entry})
54 if request.method == 'POST':
55 submit_form = get_submit_form(request.POST)
56 if submit_form.is_valid():
58 return redirect('migdal_submit_thanks')
60 submit_form = get_submit_form()
62 return render(request, 'migdal/entry/submit.html', {
63 'submit_form': submit_form,
66 def submit_thanks(request):
67 return render(request, "migdal/entry/submit_thanks.html")