-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotfoundpage.py
88 lines (65 loc) · 2.96 KB
/
notfoundpage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: UTF-8 -*-
# Copyright (C) 2010 Taverne Sylvain <[email protected]>
# Copyright (C) 2010-2011 Henry Obein <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import from the Standard Library
from types import GeneratorType
# Import from itools
from itools.gettext import MSG
from itools.uri import Reference
from itools.stl import stl, set_prefix
from itools.xml import XMLParser
# Import from ikaaro
from ikaaro.control_panel import ControlPanel
from ikaaro.folder_views import GoToSpecificDocument
from ikaaro.registry import register_resource_class
from ikaaro.webpage import WebPage
from ikaaro.website import NotFoundView as BaseNotFoundView
class NotFoundPage_View(BaseNotFoundView):
not_found_template = 'theme/404'
# Hide sidebar
display_sidebar = False
def get_template(self, resource, context):
site_root = resource.get_site_root()
template = site_root.get_resource(self.not_found_template, soft=True)
if template and not template.handler.is_empty():
# When 404 occurs context.resource is the last valid resource
# in the context.path. We need to compute prefix from context.path
# instead of context.resource
path = site_root.get_abspath().resolve2('.%s' % context.path)
prefix = path.get_pathto(template.get_abspath())
return set_prefix(template.handler.events, '%s/' % prefix)
# default
return BaseNotFoundView.get_template(self, resource, context)
def GET(self, resource, context):
# Get the namespace
namespace = self.get_namespace(resource, context)
if isinstance(namespace, Reference):
return namespace
# STL
template = self.get_template(resource, context)
if isinstance(template, (GeneratorType, XMLParser)):
return stl(events=template, namespace=namespace)
return stl(template, namespace)
class NotFoundPage(WebPage):
class_id = '404'
class_title = MSG(u'404 page')
class_views = WebPage.class_views + ['control_panel']
control_panel = GoToSpecificDocument(specific_document='../../',
specific_view='control_panel',
title=ControlPanel.title)
# Hide in browse_content
is_content = False
register_resource_class(NotFoundPage, format='application/xhtml+xml')