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