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