author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Tue, 17 Feb 2009 20:39:09 +0100 | |
branch | tls-sprint |
changeset 688 | cddfbdee0eb3 |
parent 635 | 305da8d6aa2d |
child 691 | 35133d86970b |
permissions | -rw-r--r-- |
0 | 1 |
"""management and error screens |
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 |
||
12 |
from logilab.common.decorators import cached |
|
13 |
||
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
14 |
from cubicweb.selectors import (yes, one_line_rset, none_rset, |
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
15 |
match_user_groups, chainfirst, chainall) |
0 | 16 |
from cubicweb.common.utils import UStringIO |
17 |
from cubicweb.common.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
|
18 |
from cubicweb.common.uilib import html_traceback, rest_traceback |
0 | 19 |
from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, stdmsgs |
20 |
from cubicweb.web.widgets import StaticComboBoxWidget |
|
21 |
from cubicweb.web.form import FormMixIn |
|
22 |
||
23 |
_ = unicode |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
24 |
|
0 | 25 |
def begin_form(w, entity, redirectvid, redirectpath=None, msg=None): |
26 |
w(u'<form method="post" action="%s">\n' % entity.req.build_url('edit')) |
|
27 |
w(u'<fieldset>\n') |
|
28 |
w(u'<input type="hidden" name="__redirectvid" value="%s"/>\n' % redirectvid) |
|
29 |
w(u'<input type="hidden" name="__redirectpath" value="%s"/>\n' % ( |
|
30 |
html_escape(redirectpath or entity.rest_path()))) |
|
31 |
w(u'<input type="hidden" name="eid" value="%s"/>\n' % entity.eid) |
|
32 |
w(u'<input type="hidden" name="%s" value="%s"/>\n' % ( |
|
33 |
eid_param('__type', entity.eid), entity.e_schema)) |
|
34 |
if msg: |
|
35 |
w(u'<input type="hidden" name="__message" value="%s"/>\n' |
|
36 |
% html_escape(msg)) |
|
37 |
||
38 |
||
39 |
class SecurityManagementView(EntityView): |
|
40 |
"""display security information for a given entity""" |
|
41 |
id = 'security' |
|
42 |
title = _('security') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
43 |
|
0 | 44 |
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
|
45 |
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
|
46 |
self.req.add_css('cubicweb.acl.css') |
0 | 47 |
entity = self.entity(row, col) |
48 |
w = self.w |
|
49 |
_ = self.req._ |
|
50 |
w(u'<h1><span class="etype">%s</span> <a href="%s">%s</a></h1>' |
|
51 |
% (entity.dc_type().capitalize(), |
|
52 |
html_escape(entity.absolute_url()), |
|
53 |
html_escape(entity.dc_title()))) |
|
54 |
# first show permissions defined by the schema |
|
55 |
self.w('<h2>%s</h2>' % _('schema\'s permissions definitions')) |
|
56 |
self.schema_definition(entity) |
|
57 |
self.w('<h2>%s</h2>' % _('manage security')) |
|
58 |
# ownership information |
|
59 |
if self.schema.rschema('owned_by').has_perm(self.req, 'add', |
|
60 |
fromeid=entity.eid): |
|
61 |
self.owned_by_edit_form(entity) |
|
62 |
else: |
|
63 |
self.owned_by_information(entity) |
|
64 |
# epermissions |
|
65 |
if 'require_permission' in entity.e_schema.subject_relations(): |
|
66 |
w('<h3>%s</h3>' % _('permissions for this entity')) |
|
67 |
reqpermschema = self.schema.rschema('require_permission') |
|
68 |
self.require_permission_information(entity, reqpermschema) |
|
69 |
if reqpermschema.has_perm(self.req, 'add', fromeid=entity.eid): |
|
70 |
self.require_permission_edit_form(entity) |
|
71 |
||
72 |
def schema_definition(self, entity): |
|
73 |
w = self.w |
|
74 |
_ = self.req._ |
|
75 |
w(u'<table class="schemaInfo">') |
|
76 |
w(u'<tr><th>%s</th><th>%s</th><th>%s</th></tr>' % ( |
|
77 |
_("access type"), _('granted to groups'), _('rql expressions'))) |
|
78 |
for access_type in ('read', 'add', 'update', 'delete'): |
|
79 |
w(u'<tr>') |
|
80 |
w(u'<th>%s</th>' % self.req.__('%s_permission' % access_type)) |
|
81 |
groups = entity.e_schema.get_groups(access_type) |
|
82 |
l = [] |
|
83 |
for group in groups: |
|
84 |
l.append(u'<a href="%s">%s</a>' % ( |
|
85 |
self.build_url('egroup/%s' % group), _(group))) |
|
86 |
w(u'<td>%s</td>' % u', '.join(l)) |
|
87 |
rqlexprs = entity.e_schema.get_rqlexprs(access_type) |
|
88 |
w(u'<td>%s</td>' % u'<br/>'.join(expr.expression for expr in rqlexprs)) |
|
89 |
w(u'</tr>\n') |
|
90 |
w(u'</table>') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
91 |
|
0 | 92 |
def owned_by_edit_form(self, entity): |
93 |
self.w('<h3>%s</h3>' % self.req._('ownership')) |
|
94 |
begin_form(self.w, entity, 'security', msg= _('ownerships have been changed')) |
|
95 |
self.w(u'<table border="0">\n') |
|
96 |
self.w(u'<tr><td>\n') |
|
97 |
wdg = entity.get_widget('owned_by') |
|
98 |
self.w(wdg.edit_render(entity)) |
|
99 |
self.w(u'</td><td>\n') |
|
100 |
self.w(self.button_ok()) |
|
101 |
self.w(u'</td></tr>\n</table>\n') |
|
102 |
self.w(u'</fieldset></form>\n') |
|
103 |
||
104 |
def owned_by_information(self, entity): |
|
105 |
ownersrset = entity.related('owned_by') |
|
106 |
if ownersrset: |
|
107 |
self.w('<h3>%s</h3>' % self.req._('ownership')) |
|
108 |
self.w(u'<div class="ownerInfo">') |
|
109 |
self.w(self.req._('this entity is currently owned by') + ' ') |
|
110 |
self.wview('csv', entity.related('owned_by'), 'null') |
|
111 |
self.w(u'</div>') |
|
112 |
# else we don't know if this is because entity has no owner or becayse |
|
113 |
# user as no access to owner users entities |
|
114 |
||
115 |
def require_permission_information(self, entity, reqpermschema): |
|
116 |
if entity.require_permission: |
|
117 |
w = self.w |
|
118 |
_ = self.req._ |
|
119 |
if reqpermschema.has_perm(self.req, 'delete', fromeid=entity.eid): |
|
120 |
delurl = self.build_url('edit', __redirectvid='security', |
|
121 |
__redirectpath=entity.rest_path()) |
|
122 |
delurl = delurl.replace('%', '%%') |
|
123 |
# don't give __delete value to build_url else it will be urlquoted |
|
124 |
# and this will replace %s by %25s |
|
125 |
delurl += '&__delete=%s:require_permission:%%s' % entity.eid |
|
126 |
dellinktempl = u'[<a href="%s" title="%s">-</a>] ' % ( |
|
127 |
html_escape(delurl), _('delete this permission')) |
|
128 |
else: |
|
129 |
dellinktempl = None |
|
130 |
w(u'<table class="schemaInfo">') |
|
131 |
w(u'<tr><th>%s</th><th>%s</th></tr>' % (_("permission"), |
|
132 |
_('granted to groups'))) |
|
133 |
for eperm in entity.require_permission: |
|
134 |
w(u'<tr>') |
|
135 |
if dellinktempl: |
|
136 |
w(u'<td>%s%s</td>' % (dellinktempl % eperm.eid, |
|
137 |
eperm.view('oneline'))) |
|
138 |
else: |
|
139 |
w(u'<td>%s</td>' % eperm.view('oneline')) |
|
140 |
w(u'<td>%s</td>' % self.view('csv', eperm.related('require_group'), 'null')) |
|
141 |
w(u'</tr>\n') |
|
142 |
w(u'</table>') |
|
143 |
else: |
|
144 |
self.w(self.req._('no associated epermissions')) |
|
145 |
||
146 |
def require_permission_edit_form(self, entity): |
|
147 |
w = self.w |
|
148 |
_ = self.req._ |
|
149 |
newperm = self.vreg.etype_class('EPermission')(self.req, None) |
|
150 |
newperm.eid = self.req.varmaker.next() |
|
151 |
w(u'<p>%s</p>' % _('add a new permission')) |
|
152 |
begin_form(w, newperm, 'security', entity.rest_path()) |
|
153 |
w(u'<input type="hidden" name="%s" value="__cubicweb_internal_field__"/>' |
|
154 |
% eid_param('edito-require_permission', newperm.eid)) |
|
155 |
w(u'<input type="hidden" name="%s" value="%s"/>' |
|
156 |
% (eid_param('require_permission', newperm.eid), entity.eid)) |
|
157 |
w(u'<table border="0">\n') |
|
158 |
w(u'<tr><th>%s</th><th>%s</th><th>%s</th><th> </th></tr>\n' |
|
159 |
% (_("name"), _("label"), _('granted to groups'))) |
|
160 |
if getattr(entity, '__permissions__', None): |
|
161 |
wdg = StaticComboBoxWidget(self.vreg, self.schema['EPermission'], |
|
162 |
self.schema['name'], self.schema['String'], |
|
163 |
vocabfunc=lambda x: entity.__permissions__) |
|
164 |
else: |
|
165 |
wdg = newperm.get_widget('name') |
|
166 |
w(u'<tr><td>%s</td>\n' % wdg.edit_render(newperm)) |
|
167 |
wdg = newperm.get_widget('label') |
|
168 |
w(u'<td>%s</td>\n' % wdg.edit_render(newperm)) |
|
169 |
wdg = newperm.get_widget('require_group') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
170 |
w(u'<td>%s</td>\n' % wdg.edit_render(newperm)) |
0 | 171 |
w(u'<td>%s</td></tr>\n' % self.button_ok()) |
172 |
w(u'</table>') |
|
173 |
w(u'</fieldset></form>\n') |
|
174 |
||
175 |
def button_ok(self): |
|
176 |
return (u'<input class="validateButton" type="submit" name="submit" value="%s"/>' |
|
177 |
% self.req._(stdmsgs.BUTTON_OK)) |
|
178 |
||
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
179 |
|
0 | 180 |
class ErrorView(AnyRsetView): |
181 |
"""default view when no result has been found""" |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
174
diff
changeset
|
182 |
__selectors__ = (yes,) |
0 | 183 |
id = 'error' |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
184 |
|
0 | 185 |
def page_title(self): |
186 |
"""returns a title according to the result set - used for the |
|
187 |
title in the HTML header |
|
188 |
""" |
|
189 |
return self.req._('an error occured') |
|
190 |
||
191 |
def call(self): |
|
192 |
req = self.req.reset_headers() |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
193 |
_ = req._; w = self.w |
0 | 194 |
ex = req.data.get('ex')#_("unable to find exception information")) |
195 |
excinfo = req.data.get('excinfo') |
|
196 |
title = _('an error occured') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
197 |
w(u'<h2>%s</h2>' % title) |
0 | 198 |
if 'errmsg' in req.data: |
199 |
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
|
200 |
exclass = None |
0 | 201 |
else: |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
202 |
exclass = ex.__class__.__name__ |
0 | 203 |
ex = exc_message(ex, req.encoding) |
204 |
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
|
205 |
if exclass is None: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
206 |
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
|
207 |
% 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
|
208 |
else: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
209 |
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
|
210 |
% (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
|
211 |
w(u'<hr />') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
212 |
w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, '')) |
0 | 213 |
else: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
214 |
w(u'<div class="tb">%s</div>' % (html_escape(ex).replace("\n","<br />"))) |
0 | 215 |
# if excinfo is not None, it's probably not a bug |
216 |
if excinfo is None: |
|
217 |
return |
|
218 |
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
|
219 |
w(u"<div>") |
0 | 220 |
eversion = vcconf.get('cubicweb', _('no version information')) |
221 |
# 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
|
222 |
w(u"<b>CubicWeb version:</b> %s<br/>\n" % (eversion,)) |
0 | 223 |
for pkg in self.config.cubes(): |
224 |
pkgversion = vcconf.get(pkg, _('no version information')) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
225 |
w(u"<b>Package %s version:</b> %s<br/>\n" % (pkg, pkgversion)) |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
226 |
w(u"</div>") |
0 | 227 |
# creates a bug submission link if SUBMIT_URL is set |
228 |
submiturl = self.config['submit-url'] |
|
229 |
if submiturl: |
|
230 |
binfo = text_error_description(ex, excinfo, req, eversion, |
|
231 |
[(pkg, vcconf.get(pkg, _('no version information'))) |
|
232 |
for pkg in self.config.cubes()]) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
233 |
w(u'<form action="%s" method="post">\n' % html_escape(submiturl)) |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
234 |
w(u'<fieldset>\n') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
235 |
w(u'<textarea class="hidden" name="description">%s</textarea>' % html_escape(binfo)) |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
236 |
w(u'<input type="hidden" name="description_format" value="text/rest"/>') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
237 |
w(u'<input type="hidden" name="__bugreporting" value="1"/>') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
238 |
w(u'<input type="submit" value="%s"/>' % _('Submit bug report')) |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
239 |
w(u'</fieldset>\n') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
240 |
w(u'</form>\n') |
0 | 241 |
submitmail = self.config['submit-mail'] |
242 |
if submitmail: |
|
243 |
binfo = text_error_description(ex, excinfo, req, eversion, |
|
244 |
[(pkg, vcconf.get(pkg, _('no version information'))) |
|
245 |
for pkg in self.config.cubes()]) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
246 |
w(u'<form action="%s" method="post">\n' % req.build_url('reportbug')) |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
247 |
w(u'<fieldset>\n') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
248 |
w(u'<input type="hidden" name="description" value="%s"/>' % html_escape(binfo)) |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
249 |
w(u'<input type="hidden" name="__bugreporting" value="1"/>') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
250 |
w(u'<input type="submit" value="%s"/>' % _('Submit bug report by mail')) |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
251 |
w(u'</fieldset>\n') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
252 |
w(u'</form>\n') |
0 | 253 |
|
254 |
||
255 |
def exc_message(ex, encoding): |
|
256 |
try: |
|
257 |
return unicode(ex) |
|
258 |
except: |
|
259 |
try: |
|
260 |
return unicode(str(ex), encoding, 'replace') |
|
261 |
except: |
|
262 |
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
|
263 |
|
0 | 264 |
def text_error_description(ex, excinfo, req, eversion, cubes): |
265 |
binfo = rest_traceback(excinfo, html_escape(ex)) |
|
266 |
binfo += u'\n\n:URL: %s\n' % req.url() |
|
267 |
if not '__bugreporting' in req.form: |
|
268 |
binfo += u'\n:form params:\n' |
|
269 |
binfo += u'\n'.join(u' * %s = %s' % (k, v) for k, v in req.form.iteritems()) |
|
270 |
binfo += u'\n\n:CubicWeb version: %s\n' % (eversion,) |
|
271 |
for pkg, pkgversion in cubes: |
|
272 |
binfo += u":Package %s version: %s\n" % (pkg, pkgversion) |
|
273 |
binfo += '\n' |
|
274 |
return binfo |
|
275 |
||
276 |
# some string we want to be internationalizable for nicer display of eproperty |
|
277 |
# groups |
|
278 |
_('navigation') |
|
279 |
_('ui') |
|
280 |
_('actions') |
|
281 |
_('boxes') |
|
282 |
_('components') |
|
283 |
_('contentnavigation') |
|
284 |
||
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
285 |
|
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
286 |
def make_togglable_link(nodeid, label, cookiename): |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
287 |
"""builds a HTML link that switches the visibility & remembers it""" |
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
288 |
action = u"javascript: toggle_and_remember_visibility('%s', '%s')" % \ |
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
289 |
(nodeid, cookiename) |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
290 |
return u'<a href="%s">%s</a>' % (action, label) |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
291 |
|
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
292 |
def css_class(someclass): |
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
293 |
return someclass and 'class="%s"' % someclass or '' |
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
294 |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
295 |
class SystemEPropertiesForm(FormMixIn, StartupView): |
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
296 |
id = 'systemepropertiesform' |
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
297 |
__selectors__ = (none_rset, match_user_groups('managers'),) |
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
298 |
|
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
299 |
title = _('site configuration') |
0 | 300 |
controller = 'edit' |
301 |
category = 'startupview' |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
302 |
|
0 | 303 |
def linkable(self): |
304 |
return True |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
305 |
|
0 | 306 |
def url(self): |
307 |
"""return the url associated with this view. We can omit rql here""" |
|
308 |
return self.build_url('view', vid=self.id) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
309 |
|
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
310 |
def _cookie_name(self, somestr): |
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
311 |
return str('%s_property_%s' % (self.config.appid, somestr)) |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
312 |
|
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
313 |
def _group_status(self, group, default=u'hidden'): |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
314 |
cookies = self.req.get_cookie() |
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
315 |
cookiename = self._cookie_name(group) |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
316 |
cookie = cookies.get(cookiename) |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
317 |
if cookie is None: |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
318 |
cookies[cookiename] = default |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
319 |
self.req.set_cookie(cookies, cookiename, maxage=None) |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
320 |
status = default |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
321 |
else: |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
322 |
status = cookie.value |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
323 |
return status |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
324 |
|
0 | 325 |
def call(self, **kwargs): |
326 |
"""The default view representing the application's index""" |
|
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
327 |
self.req.add_js(('cubicweb.edition.js', 'cubicweb.preferences.js')) |
0 | 328 |
self.req.add_css('cubicweb.preferences.css') |
329 |
vreg = self.vreg |
|
330 |
values = self.defined_keys |
|
331 |
groupedopts = {} |
|
332 |
mainopts = {} |
|
333 |
# "self.id=='systemepropertiesform'" to skip site wide properties on |
|
334 |
# user's preference but not site's configuration |
|
335 |
for key in vreg.user_property_keys(self.id=='systemepropertiesform'): |
|
336 |
parts = key.split('.') |
|
337 |
if parts[0] in vreg: |
|
338 |
# appobject configuration |
|
339 |
reg, oid, propid = parts |
|
340 |
groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key) |
|
341 |
else: |
|
342 |
mainopts.setdefault(parts[0], []).append(key) |
|
343 |
# precompute form to consume error message |
|
344 |
for group, keys in mainopts.items(): |
|
345 |
mainopts[group] = self.form(keys, False) |
|
346 |
for group, objects in groupedopts.items(): |
|
347 |
for oid, keys in objects.items(): |
|
348 |
groupedopts[group][oid] = self.form(keys, True) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
349 |
|
0 | 350 |
w = self.w |
351 |
req = self.req |
|
352 |
_ = req._ |
|
353 |
w(u'<h1>%s</h1>\n' % _(self.title)) |
|
354 |
w(self.error_message()) |
|
355 |
for label, group, form in sorted((_(g), g, f) |
|
356 |
for g, f in mainopts.iteritems()): |
|
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
357 |
status = css_class(self._group_status(group)) #'hidden' (collapsed), or '' (open) ? |
0 | 358 |
w(u'<h2 class="propertiesform">%s</h2>\n' % |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
359 |
(make_togglable_link('fieldset_' + group, label, |
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
360 |
self._cookie_name(group)))) |
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
361 |
w(u'<div id="fieldset_%s" %s>' % (group, status)) |
0 | 362 |
w(u'<fieldset class="subentity">') |
363 |
w(form) |
|
364 |
w(u'</fieldset></div>') |
|
365 |
for label, group, objects in sorted((_(g), g, o) |
|
366 |
for g, o in groupedopts.iteritems()): |
|
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
367 |
status = css_class(self._group_status(group)) |
0 | 368 |
w(u'<h2 class="propertiesform">%s</h2>\n' % |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
369 |
(make_togglable_link('fieldset_' + group, label, |
607
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
370 |
self._cookie_name(group)))) |
47f2ee781d6d
[preferences] de-uglify a bit, remove useless parameter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
604
diff
changeset
|
371 |
w(u'<div id="fieldset_%s" %s>' % (group, status)) |
0 | 372 |
for label, oid, form in sorted((self.req.__('%s_%s' % (group, o)), o, f) |
373 |
for o, f in objects.iteritems()): |
|
374 |
w(u'<fieldset class="subentity">') |
|
375 |
w(u'<legend class="componentTitle">%s</legend>\n' % label) |
|
376 |
docmsgid = '%s_%s_description' % (group, oid) |
|
377 |
doc = _(docmsgid) |
|
378 |
if doc != docmsgid: |
|
379 |
w(u'<p class="description">%s</p>' % html_escape(doc)) |
|
380 |
w(form) |
|
381 |
w(u'</fieldset>') |
|
382 |
w(u'</div>') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
383 |
|
0 | 384 |
@property |
385 |
@cached |
|
386 |
def eprops_rset(self): |
|
387 |
return self.req.execute('Any P,K,V WHERE P is EProperty, P pkey K, P value V, NOT P for_user U') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
388 |
|
0 | 389 |
@property |
390 |
def defined_keys(self): |
|
391 |
values = {} |
|
392 |
for i, entity in enumerate(self.eprops_rset.entities()): |
|
393 |
values[entity.pkey] = i |
|
394 |
return values |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
395 |
|
0 | 396 |
def entity_for_key(self, key): |
397 |
values = self.defined_keys |
|
398 |
if key in values: |
|
399 |
entity = self.eprops_rset.get_entity(values[key], 0) |
|
400 |
else: |
|
401 |
entity = self.vreg.etype_class('EProperty')(self.req, None, None) |
|
402 |
entity.eid = self.req.varmaker.next() |
|
403 |
entity['value'] = self.vreg.property_value(key) |
|
404 |
return entity |
|
405 |
||
406 |
def form(self, keys, splitlabel=False): |
|
407 |
stream = UStringIO() |
|
408 |
w = stream.write |
|
409 |
w(u'<form action="%s" method="post">\n' % self.build_url()) |
|
410 |
w(u'<fieldset>\n') |
|
411 |
w(u'<input type="hidden" name="__errorurl" value="%s"/>\n' |
|
412 |
% html_escape(self.req.url())) |
|
413 |
w(u'<input type="hidden" name="__form_id" value="%s"/>\n' % self.id) |
|
414 |
path = self.req.relative_path() |
|
415 |
if '?' in path: |
|
416 |
path, params = path.split('?', 1) |
|
417 |
w(u'<input type="hidden" name="__redirectparams" value="%s"/>\n' |
|
418 |
% html_escape(params)) |
|
419 |
w(u'<input type="hidden" name="__redirectpath" value="%s"/>\n' % path) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
420 |
#w(u'<input type="hidden" name="__redirectrql" value=""/>\n') |
0 | 421 |
w(u'<input type="hidden" name="__message" value="%s"/>\n' |
422 |
% self.req._('changes applied')) |
|
423 |
w(u'<table><tr><td>\n') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
424 |
|
0 | 425 |
w(u'<table>\n') |
426 |
for key in keys: |
|
427 |
w(u'<tr>\n') |
|
428 |
self.form_row(w, key, splitlabel) |
|
429 |
w(u'</tr>\n') |
|
430 |
w(u'</table>\n') |
|
431 |
w(u'</td></tr><tr><td>\n') |
|
432 |
w(self.button_ok()) |
|
433 |
w(self.button_cancel()) |
|
434 |
w(u'</td></tr></table>\n') |
|
435 |
w(u'</fieldset>\n') |
|
436 |
w(u'</form>\n') |
|
437 |
return stream.getvalue() |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
438 |
|
0 | 439 |
def form_row(self, w, key, splitlabel): |
440 |
entity = self.entity_for_key(key) |
|
441 |
eid = entity.eid |
|
442 |
if splitlabel: |
|
443 |
w(u'<td class="label">%s</td>' % self.req._(key.split('.')[-1])) |
|
444 |
else: |
|
445 |
w(u'<td class="label">%s</td>' % self.req._(key)) |
|
446 |
wdg = self.vreg.property_value_widget(key, req=self.req) |
|
447 |
error = wdg.render_error(entity) |
|
448 |
w(u'<td class="%s">' % (error and 'error' or '')) |
|
449 |
w(error) |
|
450 |
self.form_row_hiddens(w, entity, key) |
|
451 |
w(wdg.edit_render(entity)) |
|
452 |
w(u'</td>\n') |
|
453 |
w(u'<td>%s</td>' % wdg.render_help(entity)) |
|
454 |
return entity |
|
455 |
||
456 |
def form_row_hiddens(self, w, entity, key): |
|
457 |
eid = entity.eid |
|
458 |
w(u'<input type="hidden" name="eid" value="%s"/>' % eid) |
|
459 |
w(u'<input type="hidden" name="%s" value="EProperty"/>' % eid_param('__type', eid)) |
|
460 |
w(u'<input type="hidden" name="%s" value="%s"/>' % (eid_param('pkey', eid), key)) |
|
461 |
w(u'<input type="hidden" name="%s" value="%s"/>' % (eid_param('edits-pkey', eid), '')) |
|
462 |
||
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
463 |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
464 |
|
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
465 |
def is_user_prefs(cls, req, rset, row, col): |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
466 |
return req.user.eid == rset[row or 0 ][col or 0] |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
467 |
|
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
468 |
class EPropertiesForm(SystemEPropertiesForm): |
0 | 469 |
id = 'epropertiesform' |
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
470 |
__selectors__ = ( |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
471 |
# we don't want guests to be able to come here |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
472 |
match_user_groups('users', 'managers'), |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
473 |
chainfirst(none_rset), |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
474 |
chainall(one_line_rset, is_user_prefs), |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
475 |
chainall(one_line_rset, match_user_groups('managers')) |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
476 |
) |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
477 |
|
688
cddfbdee0eb3
remove all accepts = ('Foo',) declaration and use __selectors__ = implements('Foo') instead
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
635
diff
changeset
|
478 |
__selectors__ = (implements('EUser',)) |
0 | 479 |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
480 |
title = _('preferences') |
0 | 481 |
|
482 |
@property |
|
483 |
def user(self): |
|
484 |
if self.rset is None: |
|
485 |
return self.req.user |
|
486 |
return self.rset.get_entity(self.row or 0, self.col or 0) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
487 |
|
0 | 488 |
@property |
489 |
@cached |
|
490 |
def eprops_rset(self): |
|
491 |
return self.req.execute('Any P,K,V WHERE P is EProperty, P pkey K, P value V,' |
|
492 |
'P for_user U, U eid %(x)s', {'x': self.user.eid}) |
|
493 |
||
494 |
def form_row_hiddens(self, w, entity, key): |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
607
diff
changeset
|
495 |
super(EPropertiesForm, self).form_row_hiddens(w, entity, key) |
0 | 496 |
# if user is in the managers group and the property is being created, |
497 |
# we have to set for_user explicitly |
|
498 |
if not entity.has_eid() and self.user.matching_groups('managers'): |
|
499 |
eid = entity.eid |
|
500 |
w(u'<input type="hidden" name="%s" value="%s"/>' |
|
501 |
% (eid_param('edits-for_user', eid), INTERNAL_FIELD_VALUE)) |
|
502 |
w(u'<input type="hidden" name="%s" value="%s"/>' |
|
503 |
% (eid_param('for_user', eid), self.user.eid)) |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
504 |
|
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
505 |
|
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
506 |
|
0 | 507 |
|
508 |
class ProcessInformationView(StartupView): |
|
509 |
id = 'info' |
|
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
510 |
__selectors__ = (none_rset, match_user_groups('managers'),) |
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
511 |
|
0 | 512 |
title = _('server information') |
513 |
||
514 |
def call(self, **kwargs): |
|
515 |
"""display server information""" |
|
516 |
vcconf = self.config.vc_config() |
|
517 |
req = self.req |
|
518 |
_ = req._ |
|
519 |
# display main information |
|
520 |
self.w(u'<h3>%s</h3>' % _('Application')) |
|
521 |
self.w(u'<table border="1">') |
|
522 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
523 |
'CubicWeb', vcconf.get('cubicweb', _('no version information')))) |
|
524 |
for pkg in self.config.cubes(): |
|
525 |
pkgversion = vcconf.get(pkg, _('no version information')) |
|
526 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
527 |
pkg, pkgversion)) |
|
528 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
529 |
_('home'), self.config.apphome)) |
|
530 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
531 |
_('base url'), req.base_url())) |
|
532 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
533 |
_('data directory url'), req.datadir_url)) |
|
534 |
self.w(u'</table>') |
|
535 |
self.w(u'<br/>') |
|
536 |
# environment and request and server information |
|
537 |
try: |
|
538 |
# need to remove our adapter and then modpython-apache wrapper... |
|
539 |
env = req._areq._req.subprocess_env |
|
540 |
except AttributeError: |
|
541 |
return |
|
542 |
self.w(u'<h3>%s</h3>' % _('Environment')) |
|
543 |
self.w(u'<table border="1">') |
|
544 |
for attr in env.keys(): |
|
545 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
546 |
% (attr, html_escape(env[attr]))) |
|
547 |
self.w(u'</table>') |
|
548 |
self.w(u'<h3>%s</h3>' % _('Request')) |
|
549 |
self.w(u'<table border="1">') |
|
550 |
for attr in ('filename', 'form', 'hostname', 'main', 'method', |
|
551 |
'path_info', 'protocol', |
|
552 |
'search_state', 'the_request', 'unparsed_uri', 'uri'): |
|
553 |
val = getattr(req, attr) |
|
554 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
555 |
% (attr, html_escape(val))) |
|
556 |
self.w(u'</table>') |
|
557 |
server = req.server |
|
558 |
self.w(u'<h3>%s</h3>' % _('Server')) |
|
559 |
self.w(u'<table border="1">') |
|
560 |
for attr in dir(server): |
|
561 |
val = getattr(server, attr) |
|
562 |
if attr.startswith('_') or callable(val): |
|
563 |
continue |
|
564 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
565 |
% (attr, html_escape(val))) |
|
566 |
self.w(u'</table>') |
|
567 |