author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 22 Jul 2009 18:35:08 +0200 | |
changeset 2422 | 96da7dc42eb5 |
parent 2387 | ea1defea9636 |
child 2436 | 44b2eea35efa |
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 |
2387
ea1defea9636
[views] fix some crashers (schema still does not render properly, might be yams side)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2381
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
0 | 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 |
2293 | 17 |
from cubicweb.schema import META_RELATIONS_TYPES, 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 |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
20 |
from cubicweb.web.views import tabs, management, schema as schemamod |
0 | 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') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
25 |
http_cache_manager = httpcache.EtagHTTPCacheManager |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
26 |
|
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
27 |
@classmethod |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
28 |
def vreg_initialization_completed(cls): |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
29 |
for eschema in cls.schema.entities(): |
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
30 |
if eschema.schema_entity(): |
1739 | 31 |
uicfg.indexview_etype_section.setdefault(eschema, 'schema') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
32 |
elif eschema.is_subobject(strict=True): |
1739 | 33 |
uicfg.indexview_etype_section.setdefault(eschema, 'subobject') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
34 |
else: |
1739 | 35 |
uicfg.indexview_etype_section.setdefault(eschema, 'application') |
0 | 36 |
|
37 |
def display_folders(self): |
|
38 |
return False |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
39 |
|
0 | 40 |
def call(self, **kwargs): |
41 |
"""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
|
42 |
self.req.add_css('cubicweb.manageview.css') |
0 | 43 |
self.w(u'<div>\n') |
44 |
if not self.display_folders(): |
|
45 |
self._main_index() |
|
46 |
else: |
|
47 |
self.w(u'<table><tr>\n') |
|
48 |
self.w(u'<td style="width:40%">') |
|
49 |
self._main_index() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
50 |
self.w(u'</td><td style="width:60%">') |
0 | 51 |
self.folders() |
52 |
self.w(u'</td>') |
|
53 |
self.w(u'</tr></table>\n') |
|
54 |
self.w(u'</div>\n') |
|
55 |
||
56 |
def _main_index(self): |
|
57 |
req = self.req |
|
58 |
manager = req.user.matching_groups('managers') |
|
59 |
if not manager and 'Card' in self.schema: |
|
60 |
rset = self.req.execute('Card X WHERE X wikiid "index"') |
|
61 |
else: |
|
62 |
rset = None |
|
63 |
if rset: |
|
64 |
self.wview('inlined', rset, row=0) |
|
65 |
else: |
|
66 |
self.entities() |
|
67 |
self.w(u'<div class="hr"> </div>') |
|
68 |
self.startup_views() |
|
69 |
if manager and 'Card' in self.schema: |
|
70 |
self.w(u'<div class="hr"> </div>') |
|
71 |
if rset: |
|
72 |
href = rset.get_entity(0, 0).absolute_url(vid='edition') |
|
73 |
label = self.req._('edit the index page') |
|
74 |
else: |
|
75 |
href = req.build_url('view', vid='creation', etype='Card', wikiid='index') |
|
76 |
label = self.req._('create an index page') |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
77 |
self.w(u'<br/><a href="%s">%s</a>\n' % (xml_escape(href), label)) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
78 |
|
0 | 79 |
def folders(self): |
80 |
self.w(u'<h4>%s</h4>\n' % self.req._('Browse by category')) |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
81 |
self.vreg.select('views', 'tree', self.req).render(w=self.w) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
82 |
|
0 | 83 |
def startup_views(self): |
84 |
self.w(u'<h4>%s</h4>\n' % self.req._('Startup views')) |
|
85 |
self.startupviews_table() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
86 |
|
0 | 87 |
def startupviews_table(self): |
88 |
for v in self.vreg.possible_views(self.req, None): |
|
89 |
if v.category != 'startupview' or v.id in ('index', 'tree', 'manage'): |
|
90 |
continue |
|
91 |
self.w('<p><a href="%s">%s</a></p>' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
92 |
xml_escape(v.url()), xml_escape(self.req._(v.title).capitalize()))) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
93 |
|
0 | 94 |
def entities(self): |
95 |
schema = self.schema |
|
96 |
self.w(u'<h4>%s</h4>\n' % self.req._('The repository holds the following entities')) |
|
97 |
manager = self.req.user.matching_groups('managers') |
|
98 |
self.w(u'<table class="startup">') |
|
99 |
if manager: |
|
100 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('application entities')) |
|
101 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
1739 | 102 |
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
|
103 |
if manager: |
0 | 104 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('system entities')) |
105 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
1739 | 106 |
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
|
107 |
if 'CWAttribute' in schema: # check schema support |
0 | 108 |
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
|
109 |
self.entity_types_table(eschema for eschema in schema.entities() |
1739 | 110 |
if uicfg.indexview_etype_section.get(eschema) == 'schema') |
0 | 111 |
self.w(u'</table>') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
112 |
|
0 | 113 |
def entity_types_table(self, eschemas): |
114 |
newline = 0 |
|
115 |
infos = sorted(self.entity_types(eschemas), |
|
116 |
key=lambda (l,a,e):unormalize(l)) |
|
117 |
q, r = divmod(len(infos), 2) |
|
118 |
if r: |
|
119 |
infos.append( (None, ' ', ' ') ) |
|
120 |
infos = zip(infos[:q+r], infos[q+r:]) |
|
121 |
for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos: |
|
122 |
self.w(u'<tr>\n') |
|
123 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink, etypelink)) |
|
124 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink2, etypelink2)) |
|
125 |
self.w(u'</tr>\n') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
126 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
127 |
|
0 | 128 |
def entity_types(self, eschemas): |
129 |
"""return a list of formatted links to get a list of entities of |
|
130 |
a each entity's types |
|
131 |
""" |
|
132 |
req = self.req |
|
133 |
for eschema in eschemas: |
|
134 |
if eschema.is_final() or (not eschema.has_perm(req, 'read') and |
|
135 |
not eschema.has_local_role('read')): |
|
136 |
continue |
|
137 |
etype = eschema.type |
|
138 |
label = display_name(req, etype, 'plural') |
|
139 |
nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0] |
|
140 |
if nb > 1: |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
141 |
view = self.vreg.select('views', 'list', req, |
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
142 |
rset=req.etype_rset(etype)) |
0 | 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)' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
147 |
xml_escape(url), label, nb) |
0 | 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>]' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
155 |
xml_escape(self.create_url(eschema.type)), |
0 | 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' |
|
2368
b41aef0e63a7
use msgid, update i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
161 |
title = _('view_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 |
|
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
166 |
class SchemaView(tabs.TabsMixin, StartupView): |
0 | 167 |
id = 'schema' |
168 |
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
|
169 |
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
|
170 |
default_tab = 'schema-text' |
0 | 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')) |
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
176 |
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
|
177 |
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
|
178 |
|
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
179 |
|
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
|
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
u'schema with meta-data</a>.</div>') |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
187 |
% xml_escape(self.build_url('view', vid='schemagraph', withmeta=1))) |
0 | 188 |
self.w(u'<img src="%s" alt="%s"/>\n' % ( |
2381 | 189 |
xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)), |
0 | 190 |
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
|
191 |
|
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
192 |
|
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 |
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
|
194 |
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
|
195 |
|
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
'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
|
199 |
self.wview('table', rset, displayfilter=True) |
1496 | 200 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
201 |
|
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
202 |
class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn): |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
203 |
id = 'schema-security' |
1535 | 204 |
__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
|
205 |
|
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
206 |
def call(self, display_relations=True): |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
207 |
self.req.add_css('cubicweb.acl.css') |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
208 |
skiptypes = schemamod.skip_types(self.req) |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
209 |
formparams = {} |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
210 |
formparams['sec'] = self.id |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
211 |
if not skiptypes: |
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
212 |
formparams['skipmeta'] = u'0' |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
213 |
schema = self.schema |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
214 |
# compute entities |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
215 |
entities = sorted(eschema for eschema in schema.entities() |
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
216 |
if not (eschema.is_final() or eschema in skiptypes)) |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
217 |
# compute relations |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
218 |
if display_relations: |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
219 |
relations = sorted(rschema for rschema in schema.relations() |
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
220 |
if not (rschema.is_final() |
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
221 |
or rschema in skiptypes |
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
222 |
or rschema in META_RELATIONS_TYPES)) |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
223 |
else: |
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
224 |
relations = [] |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
225 |
# index |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
226 |
_ = self.req._ |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
ents = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
231 |
for eschema in sorted(entities): |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
232 |
url = xml_escape(self.build_url('schema', **formparams)) |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
rels = [] |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
238 |
for rschema in sorted(relations): |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
239 |
url = xml_escape(self.build_url('schema', **formparams)) |
2158
a2f2430dcd50
d-t-w, cleaner code, add missing css
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2017
diff
changeset
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
# entities |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
244 |
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
|
245 |
# relations |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
246 |
if relations: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
247 |
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
|
248 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
249 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
250 |
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
|
251 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
252 |
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
|
253 |
self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize()) |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
254 |
for eschema in entities: |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
255 |
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
|
256 |
self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type))) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
257 |
url = xml_escape(self.build_url('schema', **formparams) + '#index') |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
258 |
self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
259 |
url, self.req.external_resource('UP_ICON'), _('up'))) |
1494
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 |
# 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
|
264 |
modified_attrs = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
modified_attrs.append(attr) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
268 |
if modified_attrs: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
269 |
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
|
270 |
self.w(u'</div>') |
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 style="margin: 0px 6em">') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
272 |
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
|
273 |
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
|
274 |
self.schema_definition(attr, link=False) |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
275 |
self.w(u'</div>') |
0 | 276 |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
277 |
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
|
278 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
279 |
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
|
280 |
self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize()) |
2181
94ca417b9b07
backport stable branch, make schema-security consistent with other schema views changes, uniformize skipmeta/withmeta
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
281 |
for rschema in relations: |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
282 |
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
|
283 |
self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type))) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
284 |
url = xml_escape(self.build_url('schema', **formparams) + '#index') |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
285 |
self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
286 |
url, self.req.external_resource('UP_ICON'), _('up'))) |
1494
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>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
288 |
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
|
289 |
subjects = [str(subj) for subj in rschema.subjects()] |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
290 |
self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
291 |
_('subject_plural:'), |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
292 |
', '.join(str(subj) for subj in rschema.subjects()), |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
293 |
', '.join(_(str(subj)) for subj in rschema.subjects()))) |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
294 |
self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
295 |
_('object_plural:'), |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
296 |
', '.join(str(obj) for obj in rschema.objects()), |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
297 |
', '.join(_(str(obj)) for obj in rschema.objects()))) |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
298 |
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
|
299 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
300 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
301 |
|
513
907c18c01c60
while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents:
505
diff
changeset
|
302 |
class SchemaUreportsView(StartupView): |
0 | 303 |
id = 'schematext' |
304 |
||
305 |
def call(self): |
|
306 |
from cubicweb.schemaviewer import SchemaViewer |
|
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
307 |
if int(self.req.form.get('skipmeta', True)): |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
308 |
skip = schema.SKIP_TYPES |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
309 |
else: |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
310 |
skip = () |
0 | 311 |
viewer = SchemaViewer(self.req) |
2126
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
312 |
layout = viewer.visit_schema(self.schema, display_relations=True, |
a25859917ccc
stop using meta attribute from yams schema. Use instead sets defining meta relations and another defining schema types. Refactor various schema view based on this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2058
diff
changeset
|
313 |
skiptypes=skip) |
0 | 314 |
self.w(ureport_as_html(layout)) |
315 |
||
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
316 |