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 promobox = 5 if entry_type is None and category is None else None
33 object_list = api.entry_list(entry_type=entry_type, category=category,
36 return render(request, templates, {
37 'object_list': object_list,
39 'entry_type': entry_type,
44 def entry(request, type_db, slug):
45 lang = request.LANGUAGE_CODE
46 args = {'type': type_db, 'slug_%s' % lang: slug, 'published_%s' % lang: True}
47 # TODO: preview for admins
48 entry = get_object_or_404(Entry, **args)
50 templates = ["migdal/entry/entry_detail.html"]
51 if type_db is not None:
52 templates = ["migdal/entry/%s/entry_detail.html" % type_db] + templates
53 return render(request, templates, {'entry': entry})
57 if request.method == 'POST':
58 submit_form = get_submit_form(request.POST)
59 if submit_form.is_valid():
61 return redirect('migdal_submit_thanks')
63 submit_form = get_submit_form()
65 return render(request, 'migdal/entry/submit.html', {
66 'submit_form': submit_form,
69 def submit_thanks(request):
70 return render(request, "migdal/entry/submit_thanks.html")