-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroot.py
93 lines (70 loc) · 2.83 KB
/
root.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
89
90
91
92
93
# -*- coding: UTF-8 -*-
# Copyright (C) 2010 Sylvain Taverne <[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 standard library
import traceback
# Import from itools
from itools.core import merge_dicts
from itools.datatypes import Email, MultiLinesTokens
from itools.gettext import MSG
from itools.stl import stl
# Import from ikaaro
from ikaaro.database import ReadOnlyDatabase
from ikaaro.forms import MultilineWidget
from ikaaro.messages import MSG_CHANGES_SAVED
from ikaaro.resource_views import DBResource_Edit
from ikaaro.root import Root as BaseRoot
# Import from shop
from utils import get_skin_template
class ShopRoot_Edit(DBResource_Edit):
access = 'is_admin'
schema = {'administrators': MultiLinesTokens(mandatory=True)}
widgets = [MultilineWidget('administrators', title=MSG(u"Administrators"))]
def action(self, resource, context, form):
values = [x.strip() for x in form['administrators']]
resource.set_property('administrators', values)
context.message = MSG_CHANGES_SAVED
return
internal_error_body = MSG(u"""
**Website**
{uri}
**Error**
{error}
**Headers**
{headers}
""")
class Root(BaseRoot):
class_id = 'iKaaro'
edit = ShopRoot_Edit()
@classmethod
def get_metadata_schema(cls):
# XXX Administrator must be a role
return merge_dicts(BaseRoot.get_metadata_schema(),
administrators=Email(multiple=True))
def internal_server_error(self, context):
# We send an email to administrators
for email in self.get_property('administrators'):
subject = MSG(u'Internal server error').gettext()
headers = u'\n'.join([u'%s => %s' % (x, y)
for x, y in context.get_headers()])
text = internal_error_body.gettext(uri=context.uri,
error=traceback.format_exc(), headers=headers)
self.send_email(email, subject, text=text)
# We show a prerry error page
database = context.database
namespace = {'traceback': '',
'read_only': type(database) is ReadOnlyDatabase}
handler = get_skin_template(context, 'internal_server_error.xml')
return stl(handler, namespace, mode='html')