diff --git a/information/views.py b/information/views.py index bab2a73dc3d2fd817110f6f4e174b767478f0e4c..d5abf1212713f245f9aed58b88e77fec0cec3a97 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