author | sylvain.thenault@logilab.fr |
Thu, 30 Apr 2009 00:39:09 +0200 | |
branch | tls-sprint |
changeset 1550 | 8260e857822b |
parent 1544 | d8fb60c56d69 |
child 1631 | 8370be19afd7 |
permissions | -rw-r--r-- |
0 | 1 |
"""Set of HTML startup views. A startup view is global, e.g. doesn't |
2 |
apply to a result set. |
|
3 |
||
4 |
:organization: Logilab |
|
513
907c18c01c60
while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents:
505
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 |
||
1132 | 10 |
from logilab.common.textutils import unormalize |
0 | 11 |
from logilab.mtconverter import html_escape |
12 |
||
1523 | 13 |
from cubicweb.common.uilib import ureport_as_html, ajax_replace_url |
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
14 |
from cubicweb.view import StartupView |
1535 | 15 |
from cubicweb.selectors import match_user_groups |
0 | 16 |
from cubicweb.web.httpcache import EtagHTTPCacheManager |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
17 |
from cubicweb.web.views.management import SecurityViewMixIn |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
18 |
from copy import deepcopy |
0 | 19 |
_ = unicode |
20 |
||
21 |
||
22 |
class ManageView(StartupView): |
|
23 |
id = 'manage' |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
24 |
title = _('manage') |
0 | 25 |
http_cache_manager = EtagHTTPCacheManager |
26 |
||
27 |
def display_folders(self): |
|
28 |
return False |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
29 |
|
0 | 30 |
def call(self, **kwargs): |
31 |
"""The default view representing the application's management""" |
|
853
4f6cd02bd71f
Use specific css files directly in views code
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
513
diff
changeset
|
32 |
self.req.add_css('cubicweb.manageview.css') |
0 | 33 |
self.w(u'<div>\n') |
34 |
if not self.display_folders(): |
|
35 |
self._main_index() |
|
36 |
else: |
|
37 |
self.w(u'<table><tr>\n') |
|
38 |
self.w(u'<td style="width:40%">') |
|
39 |
self._main_index() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
40 |
self.w(u'</td><td style="width:60%">') |
0 | 41 |
self.folders() |
42 |
self.w(u'</td>') |
|
43 |
self.w(u'</tr></table>\n') |
|
44 |
self.w(u'</div>\n') |
|
45 |
||
46 |
def _main_index(self): |
|
47 |
req = self.req |
|
48 |
manager = req.user.matching_groups('managers') |
|
49 |
if not manager and 'Card' in self.schema: |
|
50 |
rset = self.req.execute('Card X WHERE X wikiid "index"') |
|
51 |
else: |
|
52 |
rset = None |
|
53 |
if rset: |
|
54 |
self.wview('inlined', rset, row=0) |
|
55 |
else: |
|
56 |
self.entities() |
|
57 |
self.w(u'<div class="hr"> </div>') |
|
58 |
self.startup_views() |
|
59 |
if manager and 'Card' in self.schema: |
|
60 |
self.w(u'<div class="hr"> </div>') |
|
61 |
if rset: |
|
62 |
href = rset.get_entity(0, 0).absolute_url(vid='edition') |
|
63 |
label = self.req._('edit the index page') |
|
64 |
else: |
|
65 |
href = req.build_url('view', vid='creation', etype='Card', wikiid='index') |
|
66 |
label = self.req._('create an index page') |
|
67 |
self.w(u'<br/><a href="%s">%s</a>\n' % (html_escape(href), label)) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
68 |
|
0 | 69 |
def folders(self): |
70 |
self.w(u'<h4>%s</h4>\n' % self.req._('Browse by category')) |
|
71 |
self.vreg.select_view('tree', self.req, None).dispatch(w=self.w) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
72 |
|
0 | 73 |
def startup_views(self): |
74 |
self.w(u'<h4>%s</h4>\n' % self.req._('Startup views')) |
|
75 |
self.startupviews_table() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
76 |
|
0 | 77 |
def startupviews_table(self): |
78 |
for v in self.vreg.possible_views(self.req, None): |
|
79 |
if v.category != 'startupview' or v.id in ('index', 'tree', 'manage'): |
|
80 |
continue |
|
81 |
self.w('<p><a href="%s">%s</a></p>' % ( |
|
82 |
html_escape(v.url()), html_escape(self.req._(v.title).capitalize()))) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
83 |
|
0 | 84 |
def entities(self): |
85 |
schema = self.schema |
|
86 |
self.w(u'<h4>%s</h4>\n' % self.req._('The repository holds the following entities')) |
|
87 |
manager = self.req.user.matching_groups('managers') |
|
88 |
self.w(u'<table class="startup">') |
|
89 |
if manager: |
|
90 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('application entities')) |
|
91 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
178
b5478a96da3d
only hide strict suboject in default view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
92 |
if not eschema.meta and not eschema.is_subobject(strict=True)) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
93 |
if manager: |
0 | 94 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('system entities')) |
95 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
96 |
if eschema.meta and not eschema.schema_entity()) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
97 |
if 'CWAttribute' in schema: # check schema support |
0 | 98 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('schema entities')) |
99 |
self.entity_types_table(schema.eschema(etype) |
|
100 |
for etype in schema.schema_entity_types()) |
|
101 |
self.w(u'</table>') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
102 |
|
0 | 103 |
def entity_types_table(self, eschemas): |
104 |
newline = 0 |
|
105 |
infos = sorted(self.entity_types(eschemas), |
|
106 |
key=lambda (l,a,e):unormalize(l)) |
|
107 |
q, r = divmod(len(infos), 2) |
|
108 |
if r: |
|
109 |
infos.append( (None, ' ', ' ') ) |
|
110 |
infos = zip(infos[:q+r], infos[q+r:]) |
|
111 |
for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos: |
|
112 |
self.w(u'<tr>\n') |
|
113 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink, etypelink)) |
|
114 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink2, etypelink2)) |
|
115 |
self.w(u'</tr>\n') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
116 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
117 |
|
0 | 118 |
def entity_types(self, eschemas): |
119 |
"""return a list of formatted links to get a list of entities of |
|
120 |
a each entity's types |
|
121 |
""" |
|
122 |
req = self.req |
|
123 |
for eschema in eschemas: |
|
124 |
if eschema.is_final() or (not eschema.has_perm(req, 'read') and |
|
125 |
not eschema.has_local_role('read')): |
|
126 |
continue |
|
127 |
etype = eschema.type |
|
128 |
label = display_name(req, etype, 'plural') |
|
129 |
nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0] |
|
130 |
if nb > 1: |
|
131 |
view = self.vreg.select_view('list', req, req.etype_rset(etype)) |
|
132 |
url = view.url() |
|
133 |
else: |
|
134 |
url = self.build_url('view', rql='%s X' % etype) |
|
135 |
etypelink = u' <a href="%s">%s</a> (%d)' % ( |
|
136 |
html_escape(url), label, nb) |
|
137 |
yield (label, etypelink, self.add_entity_link(eschema, req)) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
138 |
|
0 | 139 |
def add_entity_link(self, eschema, req): |
140 |
"""creates a [+] link for adding an entity if user has permission to do so""" |
|
141 |
if not eschema.has_perm(req, 'add'): |
|
142 |
return u'' |
|
143 |
return u'[<a href="%s" title="%s">+</a>]' % ( |
|
144 |
html_escape(self.create_url(eschema.type)), |
|
145 |
self.req.__('add a %s' % eschema)) |
|
146 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
147 |
|
0 | 148 |
class IndexView(ManageView): |
149 |
id = 'index' |
|
150 |
title = _('index') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
151 |
|
0 | 152 |
def display_folders(self): |
329
903eb8c4ebd6
don't show folder section on index page when there is now folder yet
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
178
diff
changeset
|
153 |
return 'Folder' in self.schema and self.req.execute('Any COUNT(X) WHERE X is Folder')[0][0] |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
154 |
|
0 | 155 |
|
156 |
||
157 |
class SchemaView(StartupView): |
|
158 |
id = 'schema' |
|
159 |
title = _('application schema') |
|
160 |
||
161 |
def call(self): |
|
162 |
"""display schema information""" |
|
163 |
self.req.add_js('cubicweb.ajax.js') |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
164 |
self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css')) |
0 | 165 |
withmeta = int(self.req.form.get('withmeta', 0)) |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
166 |
section = self.req.form.get('sec', '') |
0 | 167 |
self.w(u'<img src="%s" alt="%s"/>\n' % ( |
168 |
html_escape(self.req.build_url('view', vid='schemagraph', withmeta=withmeta)), |
|
169 |
self.req._("graphical representation of the application'schema"))) |
|
170 |
if withmeta: |
|
171 |
self.w(u'<div><a href="%s">%s</a></div>' % ( |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
172 |
html_escape(self.build_url('schema', withmeta=0, sec=section)), |
0 | 173 |
self.req._('hide meta-data'))) |
174 |
else: |
|
175 |
self.w(u'<div><a href="%s">%s</a></div>' % ( |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
176 |
html_escape(self.build_url('schema', withmeta=1, sec=section)), |
0 | 177 |
self.req._('show meta-data'))) |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
178 |
self.w(u'<a href="%s">%s</a><br/>' % |
0 | 179 |
(html_escape(ajax_replace_url('detailed_schema', '', 'schematext', |
180 |
skipmeta=int(not withmeta))), |
|
181 |
self.req._('detailed schema view'))) |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
182 |
if self.req.user.matching_groups('managers'): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
183 |
self.w(u'<a href="%s">%s</a>' % |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
184 |
(html_escape(ajax_replace_url('detailed_schema', '', 'schema_security', |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
185 |
skipmeta=int(not withmeta))), |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
186 |
self.req._('security'))) |
1495
4d6e9fe80378
avoid displaying a section twice
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1494
diff
changeset
|
187 |
self.w(u'<div id="detailed_schema">') |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
188 |
if section: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
189 |
self.wview(section, None) |
1495
4d6e9fe80378
avoid displaying a section twice
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1494
diff
changeset
|
190 |
self.w(u'</div>') |
1496 | 191 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
192 |
|
1496 | 193 |
class ManagerSchemaPermissionsView(StartupView, SecurityViewMixIn): |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
194 |
id = 'schema_security' |
1535 | 195 |
__select__ = StartupView.__select__ & match_user_groups('managers') |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
196 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
197 |
def call(self, display_relations=True, |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
198 |
skiprels=('is', 'is_instance_of', 'identity', 'owned_by', 'created_by')): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
199 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
200 |
formparams = {} |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
201 |
formparams['sec'] = self.id |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
202 |
formparams['withmeta'] = int(self.req.form.get('withmeta', True)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
203 |
schema = self.schema |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
204 |
# compute entities |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
205 |
entities = [eschema for eschema in schema.entities() |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
206 |
if not eschema.is_final()] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
207 |
if not formparams['withmeta']: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
208 |
entities = [eschema for eschema in entities |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
209 |
if not eschema.meta] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
210 |
# compute relations |
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
211 |
relations = [] |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
212 |
if display_relations: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
213 |
relations = [rschema for rschema in schema.relations() |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
214 |
if not (rschema.is_final() or rschema.type in skiprels)] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
215 |
if not formparams['withmeta']: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
216 |
relations = [rschema for rschema in relations |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
217 |
if not rschema.meta] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
218 |
# index |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
219 |
self.w(u'<div id="schema_security"><a id="index" href="index"/>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
220 |
self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize()) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
221 |
self.w(u'<h4>%s</h4>' % _('Entities').capitalize()) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
222 |
ents = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
223 |
for eschema in sorted(entities): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
224 |
url = html_escape(self.build_url('schema', **formparams) + '#' + eschema.type) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
225 |
ents.append(u'<a class="grey" href="%s">%s</a> (%s)' % (url, eschema.type, _(eschema.type))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
226 |
self.w('%s' % ', '.join(ents)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
227 |
self.w(u'<h4>%s</h4>' % (_('relations').capitalize())) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
228 |
rels = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
229 |
for eschema in sorted(relations): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
230 |
url = html_escape(self.build_url('schema', **formparams) + '#' + eschema.type) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
231 |
rels.append(u'<a class="grey" href="%s">%s</a> (%s), ' % (url , eschema.type, _(eschema.type))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
232 |
self.w('%s' % ', '.join(ents)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
233 |
# entities |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
234 |
self.display_entities(entities, formparams) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
235 |
# relations |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
236 |
if relations: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
237 |
self.display_relations(relations, formparams) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
238 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
239 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
240 |
def display_entities(self, entities, formparams): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
241 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
242 |
self.w(u'<a id="entities" href="entities"/>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
243 |
self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize()) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
244 |
for eschema in sorted(entities): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
245 |
self.w(u'<a id="%s" href="%s"/>' % (eschema.type, eschema.type)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
246 |
self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
247 |
url = html_escape(self.build_url('schema', **formparams) + '#index') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
248 |
self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url, self.req.external_resource('UP_ICON'), _('up'))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
249 |
self.w(u'</h3>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
250 |
self.w(u'<div style="margin: 0px 1.5em">') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
251 |
self.schema_definition(eschema, link=False) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
252 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
253 |
# display entity attributes only if they have some permissions modified |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
254 |
modified_attrs = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
255 |
for attr, etype in eschema.attribute_definitions(): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
256 |
if self.has_schema_modified_permissions(attr, attr.ACTIONS): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
257 |
modified_attrs.append(attr) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
258 |
if modified_attrs: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
259 |
self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize()) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
260 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
261 |
self.w(u'<div style="margin: 0px 6em">') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
262 |
for attr in modified_attrs: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
263 |
self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
264 |
self.schema_definition(attr, link=False) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
265 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
266 |
else: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
267 |
self.w(u'</div>') |
0 | 268 |
|
269 |
||
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
270 |
def display_relations(self, relations, formparams): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
271 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
272 |
self.w(u'<a id="relations" href="relations"/>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
273 |
self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize()) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
274 |
for rschema in sorted(relations): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
275 |
self.w(u'<a id="%s" href="%s"/>' % (rschema.type, rschema.type)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
276 |
self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
277 |
url = html_escape(self.build_url('schema', **formparams) + '#index') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
278 |
self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url, self.req.external_resource('UP_ICON'), _('up'))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
279 |
self.w(u'</h3>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
280 |
self.w(u'<div style="margin: 0px 1.5em">') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
281 |
subjects = [str(subj) for subj in rschema.subjects()] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
282 |
self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('subject_plural:'), |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
283 |
', '.join( [str(subj) for subj in rschema.subjects()]), |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
284 |
', '.join( [_(str(subj)) for subj in rschema.subjects()]))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
285 |
self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('object_plural:'), |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
286 |
', '.join( [str(obj) for obj in rschema.objects()]), |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
287 |
', '.join( [_(str(obj)) for obj in rschema.objects()]))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
288 |
self.schema_definition(rschema, link=False) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
289 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
290 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
291 |
|
513
907c18c01c60
while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents:
505
diff
changeset
|
292 |
class SchemaUreportsView(StartupView): |
0 | 293 |
id = 'schematext' |
294 |
||
295 |
def call(self): |
|
296 |
from cubicweb.schemaviewer import SchemaViewer |
|
297 |
skipmeta = int(self.req.form.get('skipmeta', True)) |
|
298 |
schema = self.schema |
|
299 |
viewer = SchemaViewer(self.req) |
|
300 |
layout = viewer.visit_schema(schema, display_relations=True, |
|
301 |
skiprels=('is', 'is_instance_of', 'identity', |
|
302 |
'owned_by', 'created_by'), |
|
303 |
skipmeta=skipmeta) |
|
304 |
self.w(ureport_as_html(layout)) |
|
305 |