X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/44090c986d9a16f6913047c25319c446bb9308ad..891a1e056e6066b28e000df16d69b21946338a57:/migdal/views.py diff --git a/migdal/views.py b/migdal/views.py index d705d34..42a2a39 100644 --- a/migdal/views.py +++ b/migdal/views.py @@ -2,33 +2,39 @@ # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.shortcuts import get_object_or_404, render +from django.shortcuts import get_object_or_404, render, redirect from migdal import api +from migdal.forms import get_submit_form from migdal.models import Category, Entry -from migdal.settings import TYPES_DICT +from migdal.settings import TYPES_DICT, TYPES_ON_MAIN, TYPE_SUBMIT def entry_list(request, type_db=None, category_slug=None): lang = request.LANGUAGE_CODE templates = ["migdal/entry/entry_list.html"] - if category_slug: - category = get_object_or_404(Category, **{'slug_%s' % lang: category_slug}) - else: - category = None if type_db: + if TYPES_ON_MAIN == (type_db,): + return redirect('migdal_main') entry_type = TYPES_DICT[type_db] - # TODO: if it's the only on main, redirect to main templates = ["migdal/entry/%s/entry_list.html" % type_db] + templates + submit = type_db == TYPE_SUBMIT else: + submit = TYPES_ON_MAIN == (TYPE_SUBMIT,) entry_type = None + if category_slug: + category = get_object_or_404(Category, **{'slug_%s' % lang: category_slug}) + else: + category = None + object_list = api.entry_list(entry_type=entry_type, category=category) return render(request, templates, { 'object_list': object_list, 'category': category, 'entry_type': entry_type, + 'submit': submit, }) @@ -42,3 +48,20 @@ def entry(request, type_db, slug): if type_db is not None: templates = ["migdal/entry/%s/entry_detail.html" % type_db] + templates return render(request, templates, {'entry': entry}) + + +def submit(request): + if request.method == 'POST': + submit_form = get_submit_form(request.POST) + if submit_form.is_valid(): + submit_form.save() + return redirect('migdal_submit_thanks') + else: + submit_form = get_submit_form() + + return render(request, 'migdal/entry/submit.html', { + 'submit_form': submit_form, + }) + +def submit_thanks(request): + return render(request, "migdal/entry/submit_thanks.html") \ No newline at end of file