From b83a0501abc71b3f5f5e4273b1b35a2bd462d8d7 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Mon, 10 Aug 2020 08:20:40 +0200 Subject: [PATCH] Added 404 to information cms system --- information/views.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/information/views.py b/information/views.py index bab2a73d..d5abf121 100755 --- a/information/views.py +++ b/information/views.py @@ -17,6 +17,8 @@ # from django.shortcuts import render +from django.core.exceptions import ObjectDoesNotExist +from django.http import Http404 from information.models import InformationLocale, Information from django.core.urlresolvers import reverse @@ -32,22 +34,26 @@ def index(request): return render(request, 'information/index.html', context) def detail(request, information_id): - information_locale = InformationLocale.get_information_locale_with_fallback(information_id, request.LANGUAGE_CODE) - # Is there a parent? - #parent_information = information_locale.information.parent_information - # We get all the children too - #children_locales = [] - #for child in information_locale.information.children.all(): - # children_locales.append(InformationLocale.get_information_locale_with_fallback(child.pk)) - - context = { - 'information_locale' : information_locale, - #'parent_information' : parent_information, - #'children_locales':children_locales, - 'breadcrumb': get_breadcrumb(information_locale.information, request.LANGUAGE_CODE), - 'menu_html': get_menu_html(None, information_id, request.LANGUAGE_CODE) - } - return render(request, 'information/detail.html', context) + try: + information_locale = InformationLocale.get_information_locale_with_fallback(information_id, request.LANGUAGE_CODE) + # Is there a parent? + #parent_information = information_locale.information.parent_information + # We get all the children too + #children_locales = [] + #for child in information_locale.information.children.all(): + # children_locales.append(InformationLocale.get_information_locale_with_fallback(child.pk)) + + context = { + 'information_locale' : information_locale, + #'parent_information' : parent_information, + #'children_locales':children_locales, + 'breadcrumb': get_breadcrumb(information_locale.information, request.LANGUAGE_CODE), + 'menu_html': get_menu_html(None, information_id, request.LANGUAGE_CODE) + } + return render(request, 'information/detail.html', context) + except ObjectDoesNotExist: + raise Http404("No information page found with id=%s" % information_id) + def get_breadcrumb(information, language): active_id= information.pk -- GitLab