author | sylvain.thenault@logilab.fr |
Thu, 23 Apr 2009 18:09:56 +0200 | |
branch | tls-sprint |
changeset 1458 | 3a3ad51a591e |
parent 1453 | a9841184be7c |
child 1477 | b056a49c16dc |
permissions | -rw-r--r-- |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
1 |
"""security management and error screens |
0 | 2 |
|
3 |
||
4 |
:organization: Logilab |
|
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
from logilab.mtconverter import html_escape |
|
11 |
||
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
12 |
from cubicweb.selectors import yes, none_rset, match_user_groups |
836 | 13 |
from cubicweb.view import AnyRsetView, StartupView, EntityView |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
14 |
from cubicweb.common.uilib import html_traceback, rest_traceback |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
15 |
from cubicweb.web import formwidgets |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
16 |
from cubicweb.web.form import FieldsForm, EntityFieldsForm |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
17 |
from cubicweb.web.formfields import guess_field |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
18 |
from cubicweb.web.formrenderers import HTableFormRenderer |
0 | 19 |
|
20 |
_ = unicode |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
21 |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
22 |
SUBMIT_MSGID = _('Submit bug report') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
23 |
MAIL_SUBMIT_MSGID = _('Submit bug report by mail') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
24 |
|
0 | 25 |
|
26 |
class SecurityManagementView(EntityView): |
|
27 |
"""display security information for a given entity""" |
|
28 |
id = 'security' |
|
29 |
title = _('security') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
30 |
|
0 | 31 |
def cell_call(self, row, col): |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
32 |
self.req.add_js('cubicweb.edition.js') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
33 |
self.req.add_css('cubicweb.acl.css') |
0 | 34 |
entity = self.entity(row, col) |
35 |
w = self.w |
|
36 |
_ = self.req._ |
|
37 |
w(u'<h1><span class="etype">%s</span> <a href="%s">%s</a></h1>' |
|
38 |
% (entity.dc_type().capitalize(), |
|
39 |
html_escape(entity.absolute_url()), |
|
40 |
html_escape(entity.dc_title()))) |
|
41 |
# first show permissions defined by the schema |
|
42 |
self.w('<h2>%s</h2>' % _('schema\'s permissions definitions')) |
|
43 |
self.schema_definition(entity) |
|
44 |
self.w('<h2>%s</h2>' % _('manage security')) |
|
45 |
# ownership information |
|
46 |
if self.schema.rschema('owned_by').has_perm(self.req, 'add', |
|
47 |
fromeid=entity.eid): |
|
48 |
self.owned_by_edit_form(entity) |
|
49 |
else: |
|
50 |
self.owned_by_information(entity) |
|
51 |
# epermissions |
|
52 |
if 'require_permission' in entity.e_schema.subject_relations(): |
|
53 |
w('<h3>%s</h3>' % _('permissions for this entity')) |
|
54 |
reqpermschema = self.schema.rschema('require_permission') |
|
55 |
self.require_permission_information(entity, reqpermschema) |
|
56 |
if reqpermschema.has_perm(self.req, 'add', fromeid=entity.eid): |
|
57 |
self.require_permission_edit_form(entity) |
|
58 |
||
59 |
def schema_definition(self, entity): |
|
60 |
w = self.w |
|
61 |
_ = self.req._ |
|
62 |
w(u'<table class="schemaInfo">') |
|
63 |
w(u'<tr><th>%s</th><th>%s</th><th>%s</th></tr>' % ( |
|
64 |
_("access type"), _('granted to groups'), _('rql expressions'))) |
|
65 |
for access_type in ('read', 'add', 'update', 'delete'): |
|
66 |
w(u'<tr>') |
|
67 |
w(u'<th>%s</th>' % self.req.__('%s_permission' % access_type)) |
|
68 |
groups = entity.e_schema.get_groups(access_type) |
|
69 |
l = [] |
|
70 |
for group in groups: |
|
71 |
l.append(u'<a href="%s">%s</a>' % ( |
|
72 |
self.build_url('egroup/%s' % group), _(group))) |
|
73 |
w(u'<td>%s</td>' % u', '.join(l)) |
|
74 |
rqlexprs = entity.e_schema.get_rqlexprs(access_type) |
|
75 |
w(u'<td>%s</td>' % u'<br/>'.join(expr.expression for expr in rqlexprs)) |
|
76 |
w(u'</tr>\n') |
|
77 |
w(u'</table>') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
78 |
|
0 | 79 |
def owned_by_edit_form(self, entity): |
80 |
self.w('<h3>%s</h3>' % self.req._('ownership')) |
|
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
81 |
msg = self.req._('ownerships have been changed') |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
82 |
form = EntityFieldsForm(self.req, None, entity=entity, submitmsg=msg, |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
83 |
form_buttons=[formwidgets.SubmitButton()], |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
84 |
__redirectvid='security', |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
85 |
__redirectpath=entity.rest_path()) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
86 |
field = guess_field(entity.e_schema, self.schema.rschema('owned_by')) |
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
87 |
form.append_field(field) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
88 |
self.w(form.form_render()) |
0 | 89 |
|
90 |
def owned_by_information(self, entity): |
|
91 |
ownersrset = entity.related('owned_by') |
|
92 |
if ownersrset: |
|
93 |
self.w('<h3>%s</h3>' % self.req._('ownership')) |
|
94 |
self.w(u'<div class="ownerInfo">') |
|
95 |
self.w(self.req._('this entity is currently owned by') + ' ') |
|
96 |
self.wview('csv', entity.related('owned_by'), 'null') |
|
97 |
self.w(u'</div>') |
|
98 |
# else we don't know if this is because entity has no owner or becayse |
|
99 |
# user as no access to owner users entities |
|
100 |
||
101 |
def require_permission_information(self, entity, reqpermschema): |
|
102 |
if entity.require_permission: |
|
103 |
w = self.w |
|
104 |
_ = self.req._ |
|
105 |
if reqpermschema.has_perm(self.req, 'delete', fromeid=entity.eid): |
|
106 |
delurl = self.build_url('edit', __redirectvid='security', |
|
107 |
__redirectpath=entity.rest_path()) |
|
108 |
delurl = delurl.replace('%', '%%') |
|
109 |
# don't give __delete value to build_url else it will be urlquoted |
|
110 |
# and this will replace %s by %25s |
|
111 |
delurl += '&__delete=%s:require_permission:%%s' % entity.eid |
|
112 |
dellinktempl = u'[<a href="%s" title="%s">-</a>] ' % ( |
|
113 |
html_escape(delurl), _('delete this permission')) |
|
114 |
else: |
|
115 |
dellinktempl = None |
|
116 |
w(u'<table class="schemaInfo">') |
|
117 |
w(u'<tr><th>%s</th><th>%s</th></tr>' % (_("permission"), |
|
118 |
_('granted to groups'))) |
|
119 |
for eperm in entity.require_permission: |
|
120 |
w(u'<tr>') |
|
121 |
if dellinktempl: |
|
122 |
w(u'<td>%s%s</td>' % (dellinktempl % eperm.eid, |
|
123 |
eperm.view('oneline'))) |
|
124 |
else: |
|
125 |
w(u'<td>%s</td>' % eperm.view('oneline')) |
|
126 |
w(u'<td>%s</td>' % self.view('csv', eperm.related('require_group'), 'null')) |
|
127 |
w(u'</tr>\n') |
|
128 |
w(u'</table>') |
|
129 |
else: |
|
130 |
self.w(self.req._('no associated epermissions')) |
|
131 |
||
132 |
def require_permission_edit_form(self, entity): |
|
133 |
w = self.w |
|
134 |
_ = self.req._ |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1388
diff
changeset
|
135 |
newperm = self.vreg.etype_class('CWPermission')(self.req, None) |
0 | 136 |
newperm.eid = self.req.varmaker.next() |
137 |
w(u'<p>%s</p>' % _('add a new permission')) |
|
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
138 |
form = EntityFieldsForm(self.req, None, entity=newperm, |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
139 |
form_buttons=[formwidgets.SubmitButton()], |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
140 |
__redirectvid='security', |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
141 |
__redirectpath=entity.rest_path()) |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
142 |
form.form_add_hidden('require_permission', entity.eid, role='object', eidparam=True) |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
143 |
permnames = getattr(entity, '__permissions__', None) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
144 |
cwpermschema = newperm.e_schema |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
145 |
if permnames is not None: |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
146 |
field = guess_field(cwpermschema, self.schema.rschema('name'), |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
147 |
widget=formwidgets.Select, choices=permnames) |
0 | 148 |
else: |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
149 |
field = guess_field(cwpermschema, self.schema.rschema('name')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
150 |
form.append_field(field) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
151 |
field = guess_field(cwpermschema, self.schema.rschema('label')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
152 |
form.append_field(field) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
153 |
field = guess_field(cwpermschema, self.schema.rschema('require_group')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
154 |
form.append_field(field) |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
155 |
self.w(form.form_render(renderer=HTableFormRenderer())) |
0 | 156 |
|
157 |
||
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
158 |
|
0 | 159 |
class ErrorView(AnyRsetView): |
160 |
"""default view when no result has been found""" |
|
731
ac4a94e50b60
some more s/__selectors__/__select__ but still more to come
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
691
diff
changeset
|
161 |
__select__ = yes() |
0 | 162 |
id = 'error' |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
163 |
|
0 | 164 |
def page_title(self): |
165 |
"""returns a title according to the result set - used for the |
|
166 |
title in the HTML header |
|
167 |
""" |
|
168 |
return self.req._('an error occured') |
|
169 |
||
170 |
def call(self): |
|
171 |
req = self.req.reset_headers() |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
172 |
w = self.w |
0 | 173 |
ex = req.data.get('ex')#_("unable to find exception information")) |
174 |
excinfo = req.data.get('excinfo') |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
175 |
title = self.req._('an error occured') |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
176 |
w(u'<h2>%s</h2>' % title) |
0 | 177 |
if 'errmsg' in req.data: |
178 |
ex = req.data['errmsg'] |
|
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
179 |
exclass = None |
0 | 180 |
else: |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
181 |
exclass = ex.__class__.__name__ |
0 | 182 |
ex = exc_message(ex, req.encoding) |
183 |
if excinfo is not None and self.config['print-traceback']: |
|
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
184 |
if exclass is None: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
185 |
w(u'<div class="tb">%s</div>' |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
186 |
% html_escape(ex).replace("\n","<br />")) |
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
187 |
else: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
188 |
w(u'<div class="tb">%s: %s</div>' |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
189 |
% (exclass, html_escape(ex).replace("\n","<br />"))) |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
190 |
w(u'<hr />') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
191 |
w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, '')) |
0 | 192 |
else: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
193 |
w(u'<div class="tb">%s</div>' % (html_escape(ex).replace("\n","<br />"))) |
0 | 194 |
# if excinfo is not None, it's probably not a bug |
195 |
if excinfo is None: |
|
196 |
return |
|
197 |
vcconf = self.config.vc_config() |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
198 |
w(u"<div>") |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
199 |
eversion = vcconf.get('cubicweb', self.req._('no version information')) |
0 | 200 |
# NOTE: tuple wrapping needed since eversion is itself a tuple |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
201 |
w(u"<b>CubicWeb version:</b> %s<br/>\n" % (eversion,)) |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
202 |
cversions = [] |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
203 |
for cube in self.config.cubes(): |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
204 |
cubeversion = vcconf.get(cube, self.req._('no version information')) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
205 |
w(u"<b>Package %s version:</b> %s<br/>\n" % (cube, cubeversion)) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
206 |
cversions.append((cube, cubeversion)) |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
207 |
w(u"</div>") |
0 | 208 |
# creates a bug submission link if SUBMIT_URL is set |
209 |
submiturl = self.config['submit-url'] |
|
210 |
submitmail = self.config['submit-mail'] |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
211 |
if submiturl or submitmail: |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
212 |
form = FieldsForm(self.req, set_error_url=False) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
213 |
binfo = text_error_description(ex, excinfo, req, eversion, cversions) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
214 |
form.form_add_hidden('description', binfo) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
215 |
form.form_add_hidden('__bugreporting', '1') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
216 |
if submitmail: |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
217 |
form.form_buttons = [formwidgets.SubmitButton(MAIL_SUBMIT_MSGID)] |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
218 |
form.action = req.build_url('reportbug') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
219 |
w(form.form_render()) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
220 |
if submiturl: |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
221 |
form.form_add_hidden('description_format', 'text/rest') |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
222 |
form.form_buttons = [formwidgets.SubmitButton(SUBMIT_MSGID)] |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
223 |
form.action = submiturl |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
224 |
w(form.form_render()) |
0 | 225 |
|
226 |
||
227 |
def exc_message(ex, encoding): |
|
228 |
try: |
|
229 |
return unicode(ex) |
|
230 |
except: |
|
231 |
try: |
|
232 |
return unicode(str(ex), encoding, 'replace') |
|
233 |
except: |
|
234 |
return unicode(repr(ex), encoding, 'replace') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
235 |
|
0 | 236 |
def text_error_description(ex, excinfo, req, eversion, cubes): |
237 |
binfo = rest_traceback(excinfo, html_escape(ex)) |
|
238 |
binfo += u'\n\n:URL: %s\n' % req.url() |
|
239 |
if not '__bugreporting' in req.form: |
|
240 |
binfo += u'\n:form params:\n' |
|
241 |
binfo += u'\n'.join(u' * %s = %s' % (k, v) for k, v in req.form.iteritems()) |
|
242 |
binfo += u'\n\n:CubicWeb version: %s\n' % (eversion,) |
|
243 |
for pkg, pkgversion in cubes: |
|
244 |
binfo += u":Package %s version: %s\n" % (pkg, pkgversion) |
|
245 |
binfo += '\n' |
|
246 |
return binfo |
|
247 |
||
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
248 |
|
0 | 249 |
class ProcessInformationView(StartupView): |
250 |
id = 'info' |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
731
diff
changeset
|
251 |
__select__ = none_rset() & match_user_groups('managers') |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
252 |
|
0 | 253 |
title = _('server information') |
254 |
||
255 |
def call(self, **kwargs): |
|
256 |
"""display server information""" |
|
257 |
vcconf = self.config.vc_config() |
|
258 |
req = self.req |
|
259 |
_ = req._ |
|
260 |
# display main information |
|
261 |
self.w(u'<h3>%s</h3>' % _('Application')) |
|
262 |
self.w(u'<table border="1">') |
|
263 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
264 |
'CubicWeb', vcconf.get('cubicweb', _('no version information')))) |
|
265 |
for pkg in self.config.cubes(): |
|
266 |
pkgversion = vcconf.get(pkg, _('no version information')) |
|
267 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
268 |
pkg, pkgversion)) |
|
269 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
270 |
_('home'), self.config.apphome)) |
|
271 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
272 |
_('base url'), req.base_url())) |
|
273 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
274 |
_('data directory url'), req.datadir_url)) |
|
275 |
self.w(u'</table>') |
|
276 |
self.w(u'<br/>') |
|
277 |
# environment and request and server information |
|
278 |
try: |
|
279 |
# need to remove our adapter and then modpython-apache wrapper... |
|
280 |
env = req._areq._req.subprocess_env |
|
281 |
except AttributeError: |
|
282 |
return |
|
283 |
self.w(u'<h3>%s</h3>' % _('Environment')) |
|
284 |
self.w(u'<table border="1">') |
|
285 |
for attr in env.keys(): |
|
286 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
287 |
% (attr, html_escape(env[attr]))) |
|
288 |
self.w(u'</table>') |
|
289 |
self.w(u'<h3>%s</h3>' % _('Request')) |
|
290 |
self.w(u'<table border="1">') |
|
291 |
for attr in ('filename', 'form', 'hostname', 'main', 'method', |
|
292 |
'path_info', 'protocol', |
|
293 |
'search_state', 'the_request', 'unparsed_uri', 'uri'): |
|
294 |
val = getattr(req, attr) |
|
295 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
296 |
% (attr, html_escape(val))) |
|
297 |
self.w(u'</table>') |
|
298 |
server = req.server |
|
299 |
self.w(u'<h3>%s</h3>' % _('Server')) |
|
300 |
self.w(u'<table border="1">') |
|
301 |
for attr in dir(server): |
|
302 |
val = getattr(server, attr) |
|
303 |
if attr.startswith('_') or callable(val): |
|
304 |
continue |
|
305 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
306 |
% (attr, html_escape(val))) |
|
307 |
self.w(u'</table>') |
|
308 |