55 |
55 |
56 def call(self): |
56 def call(self): |
57 self.w(_(u'<div>This schema of the data model <em>excludes</em> the ' |
57 self.w(_(u'<div>This schema of the data model <em>excludes</em> the ' |
58 u'meta-data, but you can also display a <a href="%s">complete ' |
58 u'meta-data, but you can also display a <a href="%s">complete ' |
59 u'schema with meta-data</a>.</div>') |
59 u'schema with meta-data</a>.</div>') |
60 % xml_escape(self.build_url('view', vid='schemagraph', skipmeta=0))) |
60 % xml_escape(self._cw.build_url('view', vid='schemagraph', skipmeta=0))) |
61 self.w(u'<img src="%s" alt="%s"/>\n' % ( |
61 self.w(u'<img src="%s" alt="%s"/>\n' % ( |
62 xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)), |
62 xml_escape(self._cw.build_url('view', vid='schemagraph', skipmeta=1)), |
63 self.req._("graphical representation of the instance'schema"))) |
63 self._cw._("graphical representation of the instance'schema"))) |
64 |
64 |
65 |
65 |
66 class SchemaTabTextView(StartupView): |
66 class SchemaTabTextView(StartupView): |
67 __regid__ = 'schema-text' |
67 __regid__ = 'schema-text' |
68 |
68 |
69 def call(self): |
69 def call(self): |
70 rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, ' |
70 rset = self._cw.execute('Any X ORDERBY N WHERE X is CWEType, X name N, ' |
71 'X final FALSE') |
71 'X final FALSE') |
72 self.wview('table', rset, displayfilter=True) |
72 self.wview('table', rset, displayfilter=True) |
73 |
73 |
74 |
74 |
75 class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn): |
75 class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn): |
76 __regid__ = 'schema-security' |
76 __regid__ = 'schema-security' |
77 __select__ = StartupView.__select__ & match_user_groups('managers') |
77 __select__ = StartupView.__select__ & match_user_groups('managers') |
78 |
78 |
79 def call(self, display_relations=True): |
79 def call(self, display_relations=True): |
80 self.req.add_css('cubicweb.acl.css') |
80 self._cw.add_css('cubicweb.acl.css') |
81 skiptypes = skip_types(self.req) |
81 skiptypes = skip_types(self._cw) |
82 formparams = {} |
82 formparams = {} |
83 formparams['sec'] = self.id |
83 formparams['sec'] = self.__regid__ |
84 if not skiptypes: |
84 if not skiptypes: |
85 formparams['skipmeta'] = u'0' |
85 formparams['skipmeta'] = u'0' |
86 schema = self.schema |
86 schema = self._cw.schema |
87 # compute entities |
87 # compute entities |
88 entities = sorted(eschema for eschema in schema.entities() |
88 entities = sorted(eschema for eschema in schema.entities() |
89 if not (eschema.is_final() or eschema in skiptypes)) |
89 if not (eschema.is_final() or eschema in skiptypes)) |
90 # compute relations |
90 # compute relations |
91 if display_relations: |
91 if display_relations: |
94 or rschema in skiptypes |
94 or rschema in skiptypes |
95 or rschema in META_RTYPES)) |
95 or rschema in META_RTYPES)) |
96 else: |
96 else: |
97 relations = [] |
97 relations = [] |
98 # index |
98 # index |
99 _ = self.req._ |
99 _ = self._cw._ |
100 self.w(u'<div id="schema_security"><a id="index" href="index"/>') |
100 self.w(u'<div id="schema_security"><a id="index" href="index"/>') |
101 self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize()) |
101 self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize()) |
102 self.w(u'<h4>%s</h4>' % _('Entities').capitalize()) |
102 self.w(u'<h4>%s</h4>' % _('Entities').capitalize()) |
103 ents = [] |
103 ents = [] |
104 for eschema in sorted(entities): |
104 for eschema in sorted(entities): |
105 url = xml_escape(self.build_url('schema', **formparams)) |
105 url = xml_escape(self._cw.build_url('schema', **formparams)) |
106 ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % ( |
106 ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % ( |
107 url, eschema.type, eschema.type, _(eschema.type))) |
107 url, eschema.type, eschema.type, _(eschema.type))) |
108 self.w(u', '.join(ents)) |
108 self.w(u', '.join(ents)) |
109 self.w(u'<h4>%s</h4>' % (_('relations').capitalize())) |
109 self.w(u'<h4>%s</h4>' % (_('relations').capitalize())) |
110 rels = [] |
110 rels = [] |
111 for rschema in sorted(relations): |
111 for rschema in sorted(relations): |
112 url = xml_escape(self.build_url('schema', **formparams)) |
112 url = xml_escape(self._cw.build_url('schema', **formparams)) |
113 rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' % ( |
113 rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' % ( |
114 url , rschema.type, rschema.type, _(rschema.type))) |
114 url , rschema.type, rschema.type, _(rschema.type))) |
115 self.w(u', '.join(ents)) |
115 self.w(u', '.join(ents)) |
116 # entities |
116 # entities |
117 self.display_entities(entities, formparams) |
117 self.display_entities(entities, formparams) |
119 if relations: |
119 if relations: |
120 self.display_relations(relations, formparams) |
120 self.display_relations(relations, formparams) |
121 self.w(u'</div>') |
121 self.w(u'</div>') |
122 |
122 |
123 def display_entities(self, entities, formparams): |
123 def display_entities(self, entities, formparams): |
124 _ = self.req._ |
124 _ = self._cw._ |
125 self.w(u'<a id="entities" href="entities"/>') |
125 self.w(u'<a id="entities" href="entities"/>') |
126 self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize()) |
126 self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize()) |
127 for eschema in entities: |
127 for eschema in entities: |
128 self.w(u'<a id="%s" href="%s"/>' % (eschema.type, eschema.type)) |
128 self.w(u'<a id="%s" href="%s"/>' % (eschema.type, eschema.type)) |
129 self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type))) |
129 self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type))) |
130 url = xml_escape(self.build_url('schema', **formparams) + '#index') |
130 url = xml_escape(self._cw.build_url('schema', **formparams) + '#index') |
131 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
131 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
132 url, self.req.external_resource('UP_ICON'), _('up'))) |
132 url, self._cw.external_resource('UP_ICON'), _('up'))) |
133 self.w(u'</h3>') |
133 self.w(u'</h3>') |
134 self.w(u'<div style="margin: 0px 1.5em">') |
134 self.w(u'<div style="margin: 0px 1.5em">') |
135 self.schema_definition(eschema, link=False) |
135 self._cw.schema_definition(eschema, link=False) |
136 # display entity attributes only if they have some permissions modified |
136 # display entity attributes only if they have some permissions modified |
137 modified_attrs = [] |
137 modified_attrs = [] |
138 for attr, etype in eschema.attribute_definitions(): |
138 for attr, etype in eschema.attribute_definitions(): |
139 if self.has_schema_modified_permissions(attr, attr.ACTIONS): |
139 if self.has_schema_modified_permissions(attr, attr.ACTIONS): |
140 modified_attrs.append(attr) |
140 modified_attrs.append(attr) |
142 self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize()) |
142 self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize()) |
143 self.w(u'</div>') |
143 self.w(u'</div>') |
144 self.w(u'<div style="margin: 0px 6em">') |
144 self.w(u'<div style="margin: 0px 6em">') |
145 for attr in modified_attrs: |
145 for attr in modified_attrs: |
146 self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type))) |
146 self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type))) |
147 self.schema_definition(attr, link=False) |
147 self._cw.schema_definition(attr, link=False) |
148 self.w(u'</div>') |
148 self.w(u'</div>') |
149 |
149 |
150 def display_relations(self, relations, formparams): |
150 def display_relations(self, relations, formparams): |
151 _ = self.req._ |
151 _ = self._cw._ |
152 self.w(u'<a id="relations" href="relations"/>') |
152 self.w(u'<a id="relations" href="relations"/>') |
153 self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize()) |
153 self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize()) |
154 for rschema in relations: |
154 for rschema in relations: |
155 self.w(u'<a id="%s" href="%s"/>' % (rschema.type, rschema.type)) |
155 self.w(u'<a id="%s" href="%s"/>' % (rschema.type, rschema.type)) |
156 self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type))) |
156 self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type))) |
157 url = xml_escape(self.build_url('schema', **formparams) + '#index') |
157 url = xml_escape(self._cw.build_url('schema', **formparams) + '#index') |
158 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
158 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
159 url, self.req.external_resource('UP_ICON'), _('up'))) |
159 url, self._cw.external_resource('UP_ICON'), _('up'))) |
160 self.w(u'</h3>') |
160 self.w(u'</h3>') |
161 self.w(u'<div style="margin: 0px 1.5em">') |
161 self.w(u'<div style="margin: 0px 1.5em">') |
162 subjects = [str(subj) for subj in rschema.subjects()] |
162 subjects = [str(subj) for subj in rschema.subjects()] |
163 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
163 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
164 _('subject_plural:'), |
164 _('subject_plural:'), |
166 ', '.join(_(str(subj)) for subj in rschema.subjects()))) |
166 ', '.join(_(str(subj)) for subj in rschema.subjects()))) |
167 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
167 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
168 _('object_plural:'), |
168 _('object_plural:'), |
169 ', '.join(str(obj) for obj in rschema.objects()), |
169 ', '.join(str(obj) for obj in rschema.objects()), |
170 ', '.join(_(str(obj)) for obj in rschema.objects()))) |
170 ', '.join(_(str(obj)) for obj in rschema.objects()))) |
171 self.schema_definition(rschema, link=False) |
171 self._cw.schema_definition(rschema, link=False) |
172 self.w(u'</div>') |
172 self.w(u'</div>') |
173 |
173 |
174 |
174 |
175 class SchemaUreportsView(StartupView): |
175 class SchemaUreportsView(StartupView): |
176 __regid__ = 'schema-block' |
176 __regid__ = 'schema-block' |
177 |
177 |
178 def call(self): |
178 def call(self): |
179 viewer = SchemaViewer(self.req) |
179 viewer = SchemaViewer(self._cw) |
180 layout = viewer.visit_schema(self.schema, display_relations=True, |
180 layout = viewer.visit_schema(self._cw.schema, display_relations=True, |
181 skiptypes=skip_types(self.req)) |
181 skiptypes=skip_types(self._cw)) |
182 self.w(uilib.ureport_as_html(layout)) |
182 self.w(uilib.ureport_as_html(layout)) |
183 |
183 |
184 |
184 |
185 # CWAttribute / CWRelation ##################################################### |
185 # CWAttribute / CWRelation ##################################################### |
186 |
186 |
226 class CWETypeSTextView(EntityView): |
226 class CWETypeSTextView(EntityView): |
227 __regid__ = 'cwetype-schema-text' |
227 __regid__ = 'cwetype-schema-text' |
228 __select__ = EntityView.__select__ & implements('CWEType') |
228 __select__ = EntityView.__select__ & implements('CWEType') |
229 |
229 |
230 def cell_call(self, row, col): |
230 def cell_call(self, row, col): |
231 entity = self.rset.get_entity(row, col) |
231 entity = self.cw_rset.get_entity(row, col) |
232 self.w(u'<h2>%s</h2>' % _('Attributes')) |
232 self.w(u'<h2>%s</h2>' % _('Attributes')) |
233 rset = self.req.execute('Any N,F,D,I,J,DE,A ' |
233 rset = self._cw.execute('Any N,F,D,I,J,DE,A ' |
234 'ORDERBY AA WHERE A is CWAttribute, ' |
234 'ORDERBY AA WHERE A is CWAttribute, ' |
235 'A ordernum AA, A defaultval D, ' |
235 'A ordernum AA, A defaultval D, ' |
236 'A description DE, ' |
236 'A description DE, ' |
237 'A fulltextindexed I, A internationalizable J, ' |
237 'A fulltextindexed I, A internationalizable J, ' |
238 'A relation_type R, R name N, ' |
238 'A relation_type R, R name N, ' |
239 'A to_entity O, O name F, ' |
239 'A to_entity O, O name F, ' |
240 'A from_entity S, S eid %(x)s', |
240 'A from_entity S, S eid %(x)s', |
241 {'x': entity.eid}) |
241 {'x': entity.eid}) |
242 self.wview('editable-table', rset, 'null', displayfilter=True) |
242 self.wview('editable-table', rset, 'null', displayfilter=True) |
243 self.w(u'<h2>%s</h2>' % _('Relations')) |
243 self.w(u'<h2>%s</h2>' % _('Relations')) |
244 rset = self.req.execute( |
244 rset = self._cw.execute( |
245 'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN ' |
245 'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN ' |
246 'WHERE A is CWRelation, A description D, A composite K?, ' |
246 'WHERE A is CWRelation, A description D, A composite K?, ' |
247 'A relation_type R, R name RN, A to_entity TT, TT name TTN, ' |
247 'A relation_type R, R name RN, A to_entity TT, TT name TTN, ' |
248 'A cardinality C, A from_entity S, S eid %(x)s', |
248 'A cardinality C, A from_entity S, S eid %(x)s', |
249 {'x': entity.eid}) |
249 {'x': entity.eid}) |
250 self.wview('editable-table', rset, 'null', displayfilter=True, |
250 self.wview('editable-table', rset, 'null', displayfilter=True, |
251 displaycols=range(6), mainindex=5) |
251 displaycols=range(6), mainindex=5) |
252 rset = self.req.execute( |
252 rset = self._cw.execute( |
253 'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN ' |
253 'Any R,C,TT,K,D,A,RN,TTN ORDERBY RN ' |
254 'WHERE A is CWRelation, A description D, A composite K?, ' |
254 'WHERE A is CWRelation, A description D, A composite K?, ' |
255 'A relation_type R, R name RN, A from_entity TT, TT name TTN, ' |
255 'A relation_type R, R name RN, A from_entity TT, TT name TTN, ' |
256 'A cardinality C, A to_entity O, O eid %(x)s', |
256 'A cardinality C, A to_entity O, O eid %(x)s', |
257 {'x': entity.eid}) |
257 {'x': entity.eid}) |
262 class CWETypeSImageView(EntityView): |
262 class CWETypeSImageView(EntityView): |
263 __regid__ = 'cwetype-schema-image' |
263 __regid__ = 'cwetype-schema-image' |
264 __select__ = EntityView.__select__ & implements('CWEType') |
264 __select__ = EntityView.__select__ & implements('CWEType') |
265 |
265 |
266 def cell_call(self, row, col): |
266 def cell_call(self, row, col): |
267 entity = self.rset.get_entity(row, col) |
267 entity = self.cw_rset.get_entity(row, col) |
268 url = entity.absolute_url(vid='schemagraph') |
268 url = entity.absolute_url(vid='schemagraph') |
269 self.w(u'<img src="%s" alt="%s"/>' % ( |
269 self.w(u'<img src="%s" alt="%s"/>' % ( |
270 xml_escape(url), |
270 xml_escape(url), |
271 xml_escape(self.req._('graphical schema for %s') % entity.name))) |
271 xml_escape(self._cw._('graphical schema for %s') % entity.name))) |
272 |
272 |
273 |
273 |
274 class CWETypeSPermView(EntityView): |
274 class CWETypeSPermView(EntityView): |
275 __regid__ = 'cwetype-schema-permissions' |
275 __regid__ = 'cwetype-schema-permissions' |
276 __select__ = EntityView.__select__ & implements('CWEType') |
276 __select__ = EntityView.__select__ & implements('CWEType') |
277 |
277 |
278 def cell_call(self, row, col): |
278 def cell_call(self, row, col): |
279 entity = self.rset.get_entity(row, col) |
279 entity = self.cw_rset.get_entity(row, col) |
280 self.w(u'<h2>%s</h2>' % _('Add permissions')) |
280 self.w(u'<h2>%s</h2>' % _('Add permissions')) |
281 rset = self.req.execute('Any P WHERE X add_permission P, ' |
281 rset = self._cw.execute('Any P WHERE X add_permission P, ' |
282 'X eid %(x)s', |
282 'X eid %(x)s', |
283 {'x': entity.eid}) |
283 {'x': entity.eid}) |
284 self.wview('outofcontext', rset, 'null') |
284 self.wview('outofcontext', rset, 'null') |
285 self.w(u'<h2>%s</h2>' % _('Read permissions')) |
285 self.w(u'<h2>%s</h2>' % _('Read permissions')) |
286 rset = self.req.execute('Any P WHERE X read_permission P, ' |
286 rset = self._cw.execute('Any P WHERE X read_permission P, ' |
287 'X eid %(x)s', |
287 'X eid %(x)s', |
288 {'x': entity.eid}) |
288 {'x': entity.eid}) |
289 self.wview('outofcontext', rset, 'null') |
289 self.wview('outofcontext', rset, 'null') |
290 self.w(u'<h2>%s</h2>' % _('Update permissions')) |
290 self.w(u'<h2>%s</h2>' % _('Update permissions')) |
291 rset = self.req.execute('Any P WHERE X update_permission P, ' |
291 rset = self._cw.execute('Any P WHERE X update_permission P, ' |
292 'X eid %(x)s', |
292 'X eid %(x)s', |
293 {'x': entity.eid}) |
293 {'x': entity.eid}) |
294 self.wview('outofcontext', rset, 'null') |
294 self.wview('outofcontext', rset, 'null') |
295 self.w(u'<h2>%s</h2>' % _('Delete permissions')) |
295 self.w(u'<h2>%s</h2>' % _('Delete permissions')) |
296 rset = self.req.execute('Any P WHERE X delete_permission P, ' |
296 rset = self._cw.execute('Any P WHERE X delete_permission P, ' |
297 'X eid %(x)s', |
297 'X eid %(x)s', |
298 {'x': entity.eid}) |
298 {'x': entity.eid}) |
299 self.wview('outofcontext', rset, 'null') |
299 self.wview('outofcontext', rset, 'null') |
300 |
300 |
301 |
301 |
303 __regid__ = 'cwetype-workflow' |
303 __regid__ = 'cwetype-workflow' |
304 __select__ = (EntityView.__select__ & implements('CWEType') & |
304 __select__ = (EntityView.__select__ & implements('CWEType') & |
305 has_related_entities('workflow_of', 'object')) |
305 has_related_entities('workflow_of', 'object')) |
306 |
306 |
307 def cell_call(self, row, col): |
307 def cell_call(self, row, col): |
308 entity = self.rset.get_entity(row, col) |
308 entity = self.cw_rset.get_entity(row, col) |
309 if entity.default_workflow: |
309 if entity.default_workflow: |
310 wf = entity.default_workflow[0] |
310 wf = entity.default_workflow[0] |
311 self.w(u'<h1>%s (%s)</h1>' % (wf.name, self.req._('default'))) |
311 self.w(u'<h1>%s (%s)</h1>' % (wf.name, self._cw._('default'))) |
312 self.wf_image(wf) |
312 self.wf_image(wf) |
313 for altwf in entity.reverse_workflow_of: |
313 for altwf in entity.reverse_workflow_of: |
314 if altwf.eid == wf.eid: |
314 if altwf.eid == wf.eid: |
315 continue |
315 continue |
316 self.w(u'<h1>%s</h1>' % altwf.name) |
316 self.w(u'<h1>%s</h1>' % altwf.name) |
317 self.wf_image(altwf) |
317 self.wf_image(altwf) |
318 |
318 |
319 def wf_image(self, wf): |
319 def wf_image(self, wf): |
320 self.w(u'<img src="%s" alt="%s"/>' % ( |
320 self.w(u'<img src="%s" alt="%s"/>' % ( |
321 xml_escape(wf.absolute_url(vid='wfgraph')), |
321 xml_escape(wf.absolute_url(vid='wfgraph')), |
322 xml_escape(self.req._('graphical representation of %s') % wf.name))) |
322 xml_escape(self._cw._('graphical representation of %s') % wf.name))) |
323 |
323 |
324 |
324 |
325 # CWRType ###################################################################### |
325 # CWRType ###################################################################### |
326 |
326 |
327 class CWRTypeSchemaView(primary.PrimaryView): |
327 class CWRTypeSchemaView(primary.PrimaryView): |
329 title = _('in memory relation schema') |
329 title = _('in memory relation schema') |
330 main_related_section = False |
330 main_related_section = False |
331 |
331 |
332 def render_entity_attributes(self, entity): |
332 def render_entity_attributes(self, entity): |
333 super(CWRTypeSchemaView, self).render_entity_attributes(entity) |
333 super(CWRTypeSchemaView, self).render_entity_attributes(entity) |
334 rschema = self.vreg.schema.rschema(entity.name) |
334 rschema = self._cw.vreg.schema.rschema(entity.name) |
335 viewer = SchemaViewer(self.req) |
335 viewer = SchemaViewer(self._cw) |
336 layout = viewer.visit_relationschema(rschema) |
336 layout = viewer.visit_relationschema(rschema) |
337 self.w(uilib.ureport_as_html(layout)) |
337 self.w(uilib.ureport_as_html(layout)) |
338 if not rschema.is_final(): |
338 if not rschema.is_final(): |
339 msg = self.req._('graphical schema for %s') % entity.name |
339 msg = self._cw._('graphical schema for %s') % entity.name |
340 self.w(tags.img(src=entity.absolute_url(vid='schemagraph'), |
340 self.w(tags.img(src=entity.absolute_url(vid='schemagraph'), |
341 alt=msg)) |
341 alt=msg)) |
342 |
342 |
343 |
343 |
344 # schema images ############################################################### |
344 # schema images ############################################################### |
345 |
345 |
346 class RestrictedSchemaVisitorMixIn(object): |
346 class RestrictedSchemaVisitorMixIn(object): |
347 def __init__(self, req, *args, **kwargs): |
347 def __init__(self, req, *args, **kwargs): |
348 self.req = req |
348 self._cw = req |
349 super(RestrictedSchemaVisitorMixIn, self).__init__(*args, **kwargs) |
349 super(RestrictedSchemaVisitorMixIn, self).__init__(*args, **kwargs) |
350 |
350 |
351 def should_display_schema(self, rschema): |
351 def should_display_schema(self, rschema): |
352 return (super(RestrictedSchemaVisitorMixIn, self).should_display_schema(rschema) |
352 return (super(RestrictedSchemaVisitorMixIn, self).should_display_schema(rschema) |
353 and (rschema.has_local_role('read') |
353 and (rschema.has_local_role('read') |
354 or rschema.has_perm(self.req, 'read'))) |
354 or rschema.has_perm(self._cw, 'read'))) |
355 |
355 |
356 def should_display_attr(self, rschema): |
356 def should_display_attr(self, rschema): |
357 return (super(RestrictedSchemaVisitorMixIn, self).should_display_attr(rschema) |
357 return (super(RestrictedSchemaVisitorMixIn, self).should_display_attr(rschema) |
358 and (rschema.has_local_role('read') |
358 and (rschema.has_local_role('read') |
359 or rschema.has_perm(self.req, 'read'))) |
359 or rschema.has_perm(self._cw, 'read'))) |
360 |
360 |
361 |
361 |
362 class FullSchemaVisitor(RestrictedSchemaVisitorMixIn, s2d.FullSchemaVisitor): |
362 class FullSchemaVisitor(RestrictedSchemaVisitorMixIn, s2d.FullSchemaVisitor): |
363 pass |
363 pass |
364 |
364 |
375 __regid__ = 'schemagraph' |
375 __regid__ = 'schemagraph' |
376 content_type = 'image/png' |
376 content_type = 'image/png' |
377 |
377 |
378 def _generate(self, tmpfile): |
378 def _generate(self, tmpfile): |
379 """display global schema information""" |
379 """display global schema information""" |
380 print 'skipedtypes', skip_types(self.req) |
380 print 'skipedtypes', skip_types(self._cw) |
381 visitor = FullSchemaVisitor(self.req, self.schema, |
381 visitor = FullSchemaVisitor(self._cw, self._cw.schema, |
382 skiptypes=skip_types(self.req)) |
382 skiptypes=skip_types(self._cw)) |
383 s2d.schema2dot(outputfile=tmpfile, visitor=visitor) |
383 s2d.schema2dot(outputfile=tmpfile, visitor=visitor) |
384 |
384 |
385 |
385 |
386 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView): |
386 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView): |
387 __regid__ = 'schemagraph' |
387 __regid__ = 'schemagraph' |
388 __select__ = implements('CWEType') |
388 __select__ = implements('CWEType') |
389 content_type = 'image/png' |
389 content_type = 'image/png' |
390 |
390 |
391 def _generate(self, tmpfile): |
391 def _generate(self, tmpfile): |
392 """display schema information for an entity""" |
392 """display schema information for an entity""" |
393 entity = self.rset.get_entity(self.row, self.col) |
393 entity = self.cw_rset.get_entity(self.cw_row, self.cw_col) |
394 eschema = self.vreg.schema.eschema(entity.name) |
394 eschema = self._cw.vreg.schema.eschema(entity.name) |
395 visitor = OneHopESchemaVisitor(self.req, eschema, |
395 visitor = OneHopESchemaVisitor(self._cw, eschema, |
396 skiptypes=skip_types(self.req)) |
396 skiptypes=skip_types(self._cw)) |
397 s2d.schema2dot(outputfile=tmpfile, visitor=visitor) |
397 s2d.schema2dot(outputfile=tmpfile, visitor=visitor) |
398 |
398 |
399 |
399 |
400 class CWRTypeSchemaImageView(CWETypeSchemaImageView): |
400 class CWRTypeSchemaImageView(CWETypeSchemaImageView): |
401 __select__ = implements('CWRType') |
401 __select__ = implements('CWRType') |
402 |
402 |
403 def _generate(self, tmpfile): |
403 def _generate(self, tmpfile): |
404 """display schema information for an entity""" |
404 """display schema information for an entity""" |
405 entity = self.rset.get_entity(self.row, self.col) |
405 entity = self.cw_rset.get_entity(self.cw_row, self.cw_col) |
406 rschema = self.vreg.schema.rschema(entity.name) |
406 rschema = self._cw.vreg.schema.rschema(entity.name) |
407 visitor = OneHopRSchemaVisitor(self.req, rschema) |
407 visitor = OneHopRSchemaVisitor(self._cw, rschema) |
408 s2d.schema2dot(outputfile=tmpfile, visitor=visitor) |
408 s2d.schema2dot(outputfile=tmpfile, visitor=visitor) |
409 |
409 |
410 |
410 |
411 # misc: facets, actions ######################################################## |
411 # misc: facets, actions ######################################################## |
412 |
412 |