author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 06 Jul 2009 09:33:09 +0200 | |
branch | stable |
changeset 2265 | 4c028cb136a4 |
parent 2227 | 21c9b63a4730 |
child 2293 | 7ded2a1416e4 |
child 2312 | af4d8f75c5db |
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 |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
10 |
_ = unicode |
0 | 11 |
|
1132 | 12 |
from logilab.common.textutils import unormalize |
0 | 13 |
from logilab.mtconverter import html_escape |
14 |
||
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
15 |
from cubicweb.view import StartupView |
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
16 |
from cubicweb.selectors import match_user_groups, implements |
2265
4c028cb136a4
add import to remove deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2227
diff
changeset
|
17 |
from cubicweb.schema import display_name |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1631
diff
changeset
|
18 |
from cubicweb.common.uilib import ureport_as_html |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1631
diff
changeset
|
19 |
from cubicweb.web import ajax_replace_url, uicfg, httpcache |
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
20 |
from cubicweb.web.views import tabs |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
21 |
from cubicweb.web.views.management import SecurityViewMixIn |
0 | 22 |
|
23 |
class ManageView(StartupView): |
|
24 |
id = 'manage' |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
25 |
title = _('manage') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
26 |
http_cache_manager = httpcache.EtagHTTPCacheManager |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
27 |
|
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
28 |
@classmethod |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
29 |
def vreg_initialization_completed(cls): |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
30 |
for eschema in cls.schema.entities(): |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
31 |
if eschema.schema_entity(): |
1739 | 32 |
uicfg.indexview_etype_section.setdefault(eschema, 'schema') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
33 |
elif eschema.is_subobject(strict=True): |
1739 | 34 |
uicfg.indexview_etype_section.setdefault(eschema, 'subobject') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
35 |
elif eschema.meta: |
1739 | 36 |
uicfg.indexview_etype_section.setdefault(eschema, 'system') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
37 |
else: |
1739 | 38 |
uicfg.indexview_etype_section.setdefault(eschema, 'application') |
0 | 39 |
|
40 |
def display_folders(self): |
|
41 |
return False |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
42 |
|
0 | 43 |
def call(self, **kwargs): |
44 |
"""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
|
45 |
self.req.add_css('cubicweb.manageview.css') |
0 | 46 |
self.w(u'<div>\n') |
47 |
if not self.display_folders(): |
|
48 |
self._main_index() |
|
49 |
else: |
|
50 |
self.w(u'<table><tr>\n') |
|
51 |
self.w(u'<td style="width:40%">') |
|
52 |
self._main_index() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
53 |
self.w(u'</td><td style="width:60%">') |
0 | 54 |
self.folders() |
55 |
self.w(u'</td>') |
|
56 |
self.w(u'</tr></table>\n') |
|
57 |
self.w(u'</div>\n') |
|
58 |
||
59 |
def _main_index(self): |
|
60 |
req = self.req |
|
61 |
manager = req.user.matching_groups('managers') |
|
62 |
if not manager and 'Card' in self.schema: |
|
63 |
rset = self.req.execute('Card X WHERE X wikiid "index"') |
|
64 |
else: |
|
65 |
rset = None |
|
66 |
if rset: |
|
67 |
self.wview('inlined', rset, row=0) |
|
68 |
else: |
|
69 |
self.entities() |
|
70 |
self.w(u'<div class="hr"> </div>') |
|
71 |
self.startup_views() |
|
72 |
if manager and 'Card' in self.schema: |
|
73 |
self.w(u'<div class="hr"> </div>') |
|
74 |
if rset: |
|
75 |
href = rset.get_entity(0, 0).absolute_url(vid='edition') |
|
76 |
label = self.req._('edit the index page') |
|
77 |
else: |
|
78 |
href = req.build_url('view', vid='creation', etype='Card', wikiid='index') |
|
79 |
label = self.req._('create an index page') |
|
80 |
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
|
81 |
|
0 | 82 |
def folders(self): |
83 |
self.w(u'<h4>%s</h4>\n' % self.req._('Browse by category')) |
|
1723 | 84 |
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
|
85 |
|
0 | 86 |
def startup_views(self): |
87 |
self.w(u'<h4>%s</h4>\n' % self.req._('Startup views')) |
|
88 |
self.startupviews_table() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
89 |
|
0 | 90 |
def startupviews_table(self): |
91 |
for v in self.vreg.possible_views(self.req, None): |
|
92 |
if v.category != 'startupview' or v.id in ('index', 'tree', 'manage'): |
|
93 |
continue |
|
94 |
self.w('<p><a href="%s">%s</a></p>' % ( |
|
95 |
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
|
96 |
|
0 | 97 |
def entities(self): |
98 |
schema = self.schema |
|
99 |
self.w(u'<h4>%s</h4>\n' % self.req._('The repository holds the following entities')) |
|
100 |
manager = self.req.user.matching_groups('managers') |
|
101 |
self.w(u'<table class="startup">') |
|
102 |
if manager: |
|
103 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('application entities')) |
|
104 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
1739 | 105 |
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
|
106 |
if manager: |
0 | 107 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('system entities')) |
108 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
1739 | 109 |
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
|
110 |
if 'CWAttribute' in schema: # check schema support |
0 | 111 |
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
|
112 |
self.entity_types_table(eschema for eschema in schema.entities() |
1739 | 113 |
if uicfg.indexview_etype_section.get(eschema) == 'schema') |
0 | 114 |
self.w(u'</table>') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
115 |
|
0 | 116 |
def entity_types_table(self, eschemas): |
117 |
newline = 0 |
|
118 |
infos = sorted(self.entity_types(eschemas), |
|
119 |
key=lambda (l,a,e):unormalize(l)) |
|
120 |
q, r = divmod(len(infos), 2) |
|
121 |
if r: |
|
122 |
infos.append( (None, ' ', ' ') ) |
|
123 |
infos = zip(infos[:q+r], infos[q+r:]) |
|
124 |
for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos: |
|
125 |
self.w(u'<tr>\n') |
|
126 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink, etypelink)) |
|
127 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink2, etypelink2)) |
|
128 |
self.w(u'</tr>\n') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
129 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
130 |
|
0 | 131 |
def entity_types(self, eschemas): |
132 |
"""return a list of formatted links to get a list of entities of |
|
133 |
a each entity's types |
|
134 |
""" |
|
135 |
req = self.req |
|
136 |
for eschema in eschemas: |
|
137 |
if eschema.is_final() or (not eschema.has_perm(req, 'read') and |
|
138 |
not eschema.has_local_role('read')): |
|
139 |
continue |
|
140 |
etype = eschema.type |
|
141 |
label = display_name(req, etype, 'plural') |
|
142 |
nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0] |
|
143 |
if nb > 1: |
|
144 |
view = self.vreg.select_view('list', req, req.etype_rset(etype)) |
|
145 |
url = view.url() |
|
146 |
else: |
|
147 |
url = self.build_url('view', rql='%s X' % etype) |
|
148 |
etypelink = u' <a href="%s">%s</a> (%d)' % ( |
|
149 |
html_escape(url), label, nb) |
|
150 |
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
|
151 |
|
0 | 152 |
def add_entity_link(self, eschema, req): |
153 |
"""creates a [+] link for adding an entity if user has permission to do so""" |
|
154 |
if not eschema.has_perm(req, 'add'): |
|
155 |
return u'' |
|
156 |
return u'[<a href="%s" title="%s">+</a>]' % ( |
|
157 |
html_escape(self.create_url(eschema.type)), |
|
158 |
self.req.__('add a %s' % eschema)) |
|
159 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
160 |
|
0 | 161 |
class IndexView(ManageView): |
162 |
id = 'index' |
|
163 |
title = _('index') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
164 |
|
0 | 165 |
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
|
166 |
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
|
167 |
|
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
168 |
class SchemaView(tabs.TabsMixin, StartupView): |
0 | 169 |
id = 'schema' |
170 |
title = _('application schema') |
|
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
171 |
tabs = [_('schema-text'), _('schema-image')] |
2017
4090a9546ea3
[views] change default tab to text for /schema
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1998
diff
changeset
|
172 |
default_tab = 'schema-text' |
0 | 173 |
|
174 |
def call(self): |
|
175 |
"""display schema information""" |
|
176 |
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
|
177 |
self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css')) |
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
178 |
self.w(u'<h1>%s</h1>' % _('Schema of the data model')) |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
179 |
self.render_tabs(self.tabs, self.default_tab) |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
180 |
|
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
181 |
|
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
182 |
class SchemaTabImageView(StartupView): |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
183 |
id = 'schema-image' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
184 |
|
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
185 |
def call(self): |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
186 |
self.w(_(u'<div>This schema of the data model <em>excludes</em> the ' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
187 |
u'meta-data, but you can also display a <a href="%s">complete ' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
188 |
u'schema with meta-data</a>.</div>') |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
189 |
% html_escape(self.build_url('view', vid='schemagraph', withmeta=1))) |
0 | 190 |
self.w(u'<img src="%s" alt="%s"/>\n' % ( |
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
191 |
html_escape(self.req.build_url('view', vid='schemagraph', withmeta=0)), |
0 | 192 |
self.req._("graphical representation of the application'schema"))) |
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
193 |
|
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
194 |
|
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
195 |
class SchemaTabTextView(StartupView): |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
196 |
id = 'schema-text' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
197 |
|
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
198 |
def call(self): |
2227
21c9b63a4730
hide final etype, don't display meta since it will soon disappear (eg in 3.4)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2158
diff
changeset
|
199 |
rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, ' |
21c9b63a4730
hide final etype, don't display meta since it will soon disappear (eg in 3.4)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2158
diff
changeset
|
200 |
'X final FALSE') |
21c9b63a4730
hide final etype, don't display meta since it will soon disappear (eg in 3.4)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2158
diff
changeset
|
201 |
self.wview('table', rset, displayfilter=True) |
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): |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
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')): |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
210 |
self.req.add_css('cubicweb.acl.css') |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
211 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
212 |
formparams = {} |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
213 |
formparams['sec'] = self.id |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
214 |
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
|
215 |
schema = self.schema |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
216 |
# compute entities |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
217 |
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
|
218 |
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
|
219 |
if not formparams['withmeta']: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
220 |
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
|
221 |
if not eschema.meta] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
222 |
# compute relations |
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] |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
229 |
else: |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
230 |
relations = [] |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
231 |
# index |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
ents = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
236 |
for eschema in sorted(entities): |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
237 |
url = html_escape(self.build_url('schema', **formparams)) |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
238 |
ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % ( |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
239 |
url, eschema.type, eschema.type, _(eschema.type))) |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
240 |
self.w(u', '.join(ents)) |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
241 |
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
|
242 |
rels = [] |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
243 |
for rschema in sorted(relations): |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
244 |
url = html_escape(self.build_url('schema', **formparams)) |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
245 |
rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' % ( |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
246 |
url , rschema.type, rschema.type, _(rschema.type))) |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
247 |
self.w(u', '.join(ents)) |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
248 |
# entities |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
249 |
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
|
250 |
# relations |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
251 |
if relations: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
252 |
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
|
253 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
254 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
255 |
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
|
256 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
self.w(u'</h3>') |
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 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
|
266 |
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
|
267 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
268 |
# 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
|
269 |
modified_attrs = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
270 |
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
|
271 |
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
|
272 |
modified_attrs.append(attr) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
273 |
if 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>%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
|
275 |
self.w(u'</div>') |
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 style="margin: 0px 6em">') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
281 |
else: |
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>') |
0 | 283 |
|
284 |
||
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
285 |
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
|
286 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
self.w(u'</h3>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
', '.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
|
299 |
', '.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
|
300 |
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
|
301 |
', '.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
|
302 |
', '.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
|
303 |
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
|
304 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
305 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
306 |
|
513
907c18c01c60
while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents:
505
diff
changeset
|
307 |
class SchemaUreportsView(StartupView): |
0 | 308 |
id = 'schematext' |
309 |
||
310 |
def call(self): |
|
311 |
from cubicweb.schemaviewer import SchemaViewer |
|
312 |
skipmeta = int(self.req.form.get('skipmeta', True)) |
|
313 |
schema = self.schema |
|
314 |
viewer = SchemaViewer(self.req) |
|
315 |
layout = viewer.visit_schema(schema, display_relations=True, |
|
316 |
skiprels=('is', 'is_instance_of', 'identity', |
|
317 |
'owned_by', 'created_by'), |
|
318 |
skipmeta=skipmeta) |
|
319 |
self.w(ureport_as_html(layout)) |
|
320 |
||
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
321 |