author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Thu, 28 May 2009 22:57:52 +0200 | |
changeset 1998 | 12040c090aa4 |
parent 1977 | 606923dff11b |
child 2017 | 4090a9546ea3 |
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 |
1635
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1631
diff
changeset
|
17 |
from cubicweb.common.uilib import ureport_as_html |
866563e2d0fc
don't depends on simplejson outside web/
sylvain.thenault@logilab.fr
parents:
1631
diff
changeset
|
18 |
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
|
19 |
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
|
20 |
from cubicweb.web.views.management import SecurityViewMixIn |
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 |
elif eschema.meta: |
1739 | 35 |
uicfg.indexview_etype_section.setdefault(eschema, 'system') |
1631
8370be19afd7
configurable entity types tables
sylvain.thenault@logilab.fr
parents:
1544
diff
changeset
|
36 |
else: |
1739 | 37 |
uicfg.indexview_etype_section.setdefault(eschema, 'application') |
0 | 38 |
|
39 |
def display_folders(self): |
|
40 |
return False |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
41 |
|
0 | 42 |
def call(self, **kwargs): |
43 |
"""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
|
44 |
self.req.add_css('cubicweb.manageview.css') |
0 | 45 |
self.w(u'<div>\n') |
46 |
if not self.display_folders(): |
|
47 |
self._main_index() |
|
48 |
else: |
|
49 |
self.w(u'<table><tr>\n') |
|
50 |
self.w(u'<td style="width:40%">') |
|
51 |
self._main_index() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
52 |
self.w(u'</td><td style="width:60%">') |
0 | 53 |
self.folders() |
54 |
self.w(u'</td>') |
|
55 |
self.w(u'</tr></table>\n') |
|
56 |
self.w(u'</div>\n') |
|
57 |
||
58 |
def _main_index(self): |
|
59 |
req = self.req |
|
60 |
manager = req.user.matching_groups('managers') |
|
61 |
if not manager and 'Card' in self.schema: |
|
62 |
rset = self.req.execute('Card X WHERE X wikiid "index"') |
|
63 |
else: |
|
64 |
rset = None |
|
65 |
if rset: |
|
66 |
self.wview('inlined', rset, row=0) |
|
67 |
else: |
|
68 |
self.entities() |
|
69 |
self.w(u'<div class="hr"> </div>') |
|
70 |
self.startup_views() |
|
71 |
if manager and 'Card' in self.schema: |
|
72 |
self.w(u'<div class="hr"> </div>') |
|
73 |
if rset: |
|
74 |
href = rset.get_entity(0, 0).absolute_url(vid='edition') |
|
75 |
label = self.req._('edit the index page') |
|
76 |
else: |
|
77 |
href = req.build_url('view', vid='creation', etype='Card', wikiid='index') |
|
78 |
label = self.req._('create an index page') |
|
79 |
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
|
80 |
|
0 | 81 |
def folders(self): |
82 |
self.w(u'<h4>%s</h4>\n' % self.req._('Browse by category')) |
|
1723 | 83 |
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
|
84 |
|
0 | 85 |
def startup_views(self): |
86 |
self.w(u'<h4>%s</h4>\n' % self.req._('Startup views')) |
|
87 |
self.startupviews_table() |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
88 |
|
0 | 89 |
def startupviews_table(self): |
90 |
for v in self.vreg.possible_views(self.req, None): |
|
91 |
if v.category != 'startupview' or v.id in ('index', 'tree', 'manage'): |
|
92 |
continue |
|
93 |
self.w('<p><a href="%s">%s</a></p>' % ( |
|
94 |
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
|
95 |
|
0 | 96 |
def entities(self): |
97 |
schema = self.schema |
|
98 |
self.w(u'<h4>%s</h4>\n' % self.req._('The repository holds the following entities')) |
|
99 |
manager = self.req.user.matching_groups('managers') |
|
100 |
self.w(u'<table class="startup">') |
|
101 |
if manager: |
|
102 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('application entities')) |
|
103 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
1739 | 104 |
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
|
105 |
if manager: |
0 | 106 |
self.w(u'<tr><th colspan="4">%s</th></tr>\n' % self.req._('system entities')) |
107 |
self.entity_types_table(eschema for eschema in schema.entities() |
|
1739 | 108 |
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
|
109 |
if 'CWAttribute' in schema: # check schema support |
0 | 110 |
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
|
111 |
self.entity_types_table(eschema for eschema in schema.entities() |
1739 | 112 |
if uicfg.indexview_etype_section.get(eschema) == 'schema') |
0 | 113 |
self.w(u'</table>') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
114 |
|
0 | 115 |
def entity_types_table(self, eschemas): |
116 |
newline = 0 |
|
117 |
infos = sorted(self.entity_types(eschemas), |
|
118 |
key=lambda (l,a,e):unormalize(l)) |
|
119 |
q, r = divmod(len(infos), 2) |
|
120 |
if r: |
|
121 |
infos.append( (None, ' ', ' ') ) |
|
122 |
infos = zip(infos[:q+r], infos[q+r:]) |
|
123 |
for (_, etypelink, addlink), (_, etypelink2, addlink2) in infos: |
|
124 |
self.w(u'<tr>\n') |
|
125 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink, etypelink)) |
|
126 |
self.w(u'<td class="addcol">%s</td><td>%s</td>\n' % (addlink2, etypelink2)) |
|
127 |
self.w(u'</tr>\n') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
128 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
129 |
|
0 | 130 |
def entity_types(self, eschemas): |
131 |
"""return a list of formatted links to get a list of entities of |
|
132 |
a each entity's types |
|
133 |
""" |
|
134 |
req = self.req |
|
135 |
for eschema in eschemas: |
|
136 |
if eschema.is_final() or (not eschema.has_perm(req, 'read') and |
|
137 |
not eschema.has_local_role('read')): |
|
138 |
continue |
|
139 |
etype = eschema.type |
|
140 |
label = display_name(req, etype, 'plural') |
|
141 |
nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0] |
|
142 |
if nb > 1: |
|
143 |
view = self.vreg.select_view('list', req, req.etype_rset(etype)) |
|
144 |
url = view.url() |
|
145 |
else: |
|
146 |
url = self.build_url('view', rql='%s X' % etype) |
|
147 |
etypelink = u' <a href="%s">%s</a> (%d)' % ( |
|
148 |
html_escape(url), label, nb) |
|
149 |
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
|
150 |
|
0 | 151 |
def add_entity_link(self, eschema, req): |
152 |
"""creates a [+] link for adding an entity if user has permission to do so""" |
|
153 |
if not eschema.has_perm(req, 'add'): |
|
154 |
return u'' |
|
155 |
return u'[<a href="%s" title="%s">+</a>]' % ( |
|
156 |
html_escape(self.create_url(eschema.type)), |
|
157 |
self.req.__('add a %s' % eschema)) |
|
158 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
159 |
|
0 | 160 |
class IndexView(ManageView): |
161 |
id = 'index' |
|
162 |
title = _('index') |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
163 |
|
0 | 164 |
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
|
165 |
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
|
166 |
|
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
167 |
class SchemaView(tabs.TabsMixin, StartupView): |
0 | 168 |
id = 'schema' |
169 |
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
|
170 |
tabs = [_('schema-text'), _('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
|
171 |
default_tab = 'schema-image' |
0 | 172 |
|
173 |
def call(self): |
|
174 |
"""display schema information""" |
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
|
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>') |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
187 |
% html_escape(self.build_url('view', vid='schemagraph', withmeta=1))) |
0 | 188 |
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
|
189 |
html_escape(self.req.build_url('view', vid='schemagraph', withmeta=0)), |
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 |
|
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
192 |
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
|
193 |
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
|
194 |
|
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
195 |
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
|
196 |
self.w(u'<p>%s</p>' % _('This is the list of types defined in the data ' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
197 |
'model ofin this application.')) |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
198 |
self.w(u'<p>%s</p>' % _('<em>meta</em> is True for types that are defined by the ' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
199 |
'framework itself (e.g. User and Group). ' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
200 |
'<em>final</em> is True for types that can not be the ' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
201 |
'subject of a relation (e.g. Int and String).')) |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
202 |
rset = self.req.execute('Any X,M,F ORDERBY N WHERE X is CWEType, X name N, ' |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
203 |
'X meta M, X final F') |
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
204 |
self.wview('editable-table', rset, displayfilter=True) |
1496 | 205 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
206 |
|
1496 | 207 |
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
|
208 |
id = 'schema_security' |
1535 | 209 |
__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
|
210 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
211 |
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
|
212 |
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
|
213 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
214 |
formparams = {} |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
215 |
formparams['sec'] = self.id |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
216 |
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
|
217 |
schema = self.schema |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
218 |
# compute entities |
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 schema.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.is_final()] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
221 |
if not formparams['withmeta']: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
222 |
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
|
223 |
if not eschema.meta] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
224 |
# compute relations |
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
225 |
relations = [] |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
226 |
if display_relations: |
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 schema.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.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
|
229 |
if not formparams['withmeta']: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
230 |
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
|
231 |
if not rschema.meta] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
232 |
# 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'<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
|
234 |
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
|
235 |
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
|
236 |
ents = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
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
|
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 = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
# entities |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
248 |
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
|
249 |
# relations |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
250 |
if relations: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
251 |
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
|
252 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
253 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
254 |
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
|
255 |
_ = self.req._ |
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="entities" href="entities"/>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
self.w(u'</h3>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
|
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
267 |
# 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
|
268 |
modified_attrs = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
modified_attrs.append(attr) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
272 |
if 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>%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
|
274 |
self.w(u'</div>') |
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 style="margin: 0px 6em">') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
280 |
else: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
281 |
self.w(u'</div>') |
0 | 282 |
|
283 |
||
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
284 |
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
|
285 |
_ = self.req._ |
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="relations" href="relations"/>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
self.w(u'</h3>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
', '.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
|
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 |
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
|
300 |
', '.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
|
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 |
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
|
303 |
self.w(u'</div>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
853
diff
changeset
|
304 |
|
1532
111c52e0022f
duh? remaining __selectors__, probably a wrong merge
sylvain.thenault@logilab.fr
parents:
1523
diff
changeset
|
305 |
|
513
907c18c01c60
while EntityView has been used here?? (changeset 501 by laure)
sylvain.thenault@logilab.fr
parents:
505
diff
changeset
|
306 |
class SchemaUreportsView(StartupView): |
0 | 307 |
id = 'schematext' |
308 |
||
309 |
def call(self): |
|
310 |
from cubicweb.schemaviewer import SchemaViewer |
|
311 |
skipmeta = int(self.req.form.get('skipmeta', True)) |
|
312 |
schema = self.schema |
|
313 |
viewer = SchemaViewer(self.req) |
|
314 |
layout = viewer.visit_schema(schema, display_relations=True, |
|
315 |
skiprels=('is', 'is_instance_of', 'identity', |
|
316 |
'owned_by', 'created_by'), |
|
317 |
skipmeta=skipmeta) |
|
318 |
self.w(ureport_as_html(layout)) |
|
319 |
||
1998
12040c090aa4
[views] change schema views: remove view eschema and use tabs for cwetype
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
320 |