author | sylvain.thenault@logilab.fr |
Tue, 28 Apr 2009 19:09:37 +0200 | |
branch | tls-sprint |
changeset 1519 | 5cfc5cc1dd20 |
parent 1511 | 514e4e53a3c7 |
child 1533 | bcd4bfff658b |
permissions | -rw-r--r-- |
0 | 1 |
"""Specific views for schema related entities |
2 |
||
3 |
:organization: Logilab |
|
787 | 4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
9 |
from itertools import cycle |
0 | 10 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
11 |
from logilab.mtconverter import html_escape |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
12 |
from yams import schema2dot as s2d |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
13 |
|
1132 | 14 |
from cubicweb.selectors import implements, yes |
0 | 15 |
from cubicweb.schemaviewer import SchemaViewer |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
16 |
from cubicweb.view import EntityView, StartupView |
0 | 17 |
from cubicweb.common.uilib import ureport_as_html |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
18 |
from cubicweb.web import uicfg, action |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
19 |
from cubicweb.web.views import TmpFileViewMixin, baseviews |
1151
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
20 |
|
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
21 |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
22 |
uicfg.rcategories.set_rtag('primary', 'require_group', 'subject', 'CWPermission') |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
23 |
uicfg.rcategories.set_rtag('generated', 'final', 'subject', 'EEtype') |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
24 |
uicfg.rcategories.set_rtag('generated', 'final', 'subject', 'ERtype') |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
25 |
uicfg.rinlined.set_rtag(True, 'relation_type', 'subject', 'CWRelation') |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
26 |
uicfg.rinlined.set_rtag(True, 'from_entity', 'subject', 'CWRelation') |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
27 |
uicfg.rinlined.set_rtag(True, 'to_entity', 'subject', 'CWRelation') |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
28 |
uicfg.rwidgets.set_rtag('StringWidget', 'expression', 'subject', 'RQLExpression') |
1151
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
29 |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
30 |
uicfg.rmode.set_rtag('create', 'state_of', 'object', otype='CWEType') |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
31 |
uicfg.rmode.set_rtag('create', 'transition_of', 'object', otype='CWEType') |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
32 |
uicfg.rmode.set_rtag('create', 'relation_type', 'object', otype='CWRType') |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
33 |
uicfg.rmode.set_rtag('link', 'from_entity', 'object', otype='CWEType') |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
34 |
uicfg.rmode.set_rtag('link', 'to_entity', 'object', otype='CWEType') |
0 | 35 |
|
36 |
||
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
37 |
class ViewSchemaAction(action.Action): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
38 |
id = 'schema' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
39 |
__select__ = yes() |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
40 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
41 |
title = _("site schema") |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
42 |
category = 'siteactions' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
43 |
order = 30 |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
44 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
45 |
def url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
46 |
return self.build_url(self.id) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
47 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
48 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
49 |
# schema entity types views ################################################### |
0 | 50 |
|
51 |
class _SchemaEntityPrimaryView(baseviews.PrimaryView): |
|
52 |
show_attr_label = False |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
53 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
54 |
|
0 | 55 |
def content_title(self, entity): |
56 |
return html_escape(entity.dc_long_title()) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
57 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
58 |
class CWETypePrimaryView(_SchemaEntityPrimaryView): |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
59 |
__select__ = implements('CWEType') |
0 | 60 |
skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final') |
61 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
62 |
class CWRTypePrimaryView(_SchemaEntityPrimaryView): |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
63 |
__select__ = implements('CWRType') |
0 | 64 |
skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final', |
65 |
'symetric', 'inlined') |
|
66 |
||
67 |
class ErdefPrimaryView(_SchemaEntityPrimaryView): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
68 |
__select__ = implements('CWAttribute', 'CWRelation') |
0 | 69 |
show_attr_label = True |
70 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
71 |
class CWETypeOneLineView(baseviews.OneLineView): |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
72 |
__select__ = implements('CWEType') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
73 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
74 |
def cell_call(self, row, col, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
75 |
entity = self.entity(row, col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
76 |
final = entity.final |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
77 |
if final: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
78 |
self.w(u'<em class="finalentity">') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
79 |
super(CWETypeOneLineView, self).cell_call(row, col, **kwargs) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
80 |
if final: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
81 |
self.w(u'</em>') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
82 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
83 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
84 |
# in memory schema views (yams class instances) ############################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
85 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
86 |
class CWETypeSchemaView(CWETypePrimaryView): |
0 | 87 |
id = 'eschema' |
88 |
title = _('in memory entity schema') |
|
89 |
main_related_section = False |
|
90 |
skip_rels = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by', |
|
91 |
'has_text',) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
92 |
|
0 | 93 |
def render_entity_attributes(self, entity, siderelations): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
94 |
super(CWETypeSchemaView, self).render_entity_attributes(entity, siderelations) |
0 | 95 |
eschema = self.vreg.schema.eschema(entity.name) |
96 |
viewer = SchemaViewer(self.req) |
|
97 |
layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels) |
|
98 |
self.w(ureport_as_html(layout)) |
|
99 |
if not eschema.is_final(): |
|
100 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
101 |
html_escape(entity.absolute_url(vid='eschemagraph')), |
|
102 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
103 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
104 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
105 |
class CWRTypeSchemaView(CWRTypePrimaryView): |
0 | 106 |
id = 'eschema' |
107 |
title = _('in memory relation schema') |
|
108 |
main_related_section = False |
|
109 |
||
110 |
def render_entity_attributes(self, entity, siderelations): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
111 |
super(CWRTypeSchemaView, self).render_entity_attributes(entity, siderelations) |
0 | 112 |
rschema = self.vreg.schema.rschema(entity.name) |
113 |
viewer = SchemaViewer(self.req) |
|
114 |
layout = viewer.visit_relationschema(rschema) |
|
115 |
self.w(ureport_as_html(layout)) |
|
116 |
if not rschema.is_final(): |
|
117 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
118 |
html_escape(entity.absolute_url(vid='eschemagraph')), |
|
119 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
120 |
|
0 | 121 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
122 |
# schema images ############################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
123 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
124 |
class ImageView(EntityView): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
125 |
__select__ = implements('CWEType') |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
126 |
id = 'image' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
127 |
title = _('image') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
128 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
129 |
def cell_call(self, row, col): |
0 | 130 |
entity = self.entity(row, col) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
131 |
url = entity.absolute_url(vid='eschemagraph') |
0 | 132 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
133 |
html_escape(url), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
134 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
0 | 135 |
|
136 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
137 |
class RestrictedSchemaDotPropsHandler(s2d.SchemaDotPropsHandler): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
138 |
def __init__(self, req): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
139 |
# FIXME: colors are arbitrary |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
140 |
self.nextcolor = cycle( ('#aa0000', '#00aa00', '#0000aa', |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
141 |
'#000000', '#888888') ).next |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
142 |
self.req = req |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
143 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
144 |
def display_attr(self, rschema): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
145 |
return not rschema.meta and (rschema.has_local_role('read') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
146 |
or rschema.has_perm(self.req, 'read')) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
147 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
148 |
# XXX remove this method once yams > 0.20 is out |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
149 |
def node_properties(self, eschema): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
150 |
"""return default DOT drawing options for an entity schema""" |
1132 | 151 |
label = ['{', eschema.type, '|'] |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
152 |
label.append(r'\l'.join(rel.type for rel in eschema.subject_relations() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
153 |
if rel.final and self.display_attr(rel))) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
154 |
label.append(r'\l}') # trailing \l ensure alignement of the last one |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
155 |
return {'label' : ''.join(label), 'shape' : "record", |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
156 |
'fontname' : "Courier", 'style' : "filled"} |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
157 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
158 |
def edge_properties(self, rschema, subjnode, objnode): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
159 |
kwargs = super(RestrictedSchemaDotPropsHandler, self).edge_properties(rschema, subjnode, objnode) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
160 |
# symetric rels are handled differently, let yams decide what's best |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
161 |
if not rschema.symetric: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
162 |
kwargs['color'] = self.nextcolor() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
163 |
kwargs['fontcolor'] = kwargs['color'] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
164 |
# dot label decoration is just awful (1 line underlining the label |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
165 |
# + 1 line going to the closest edge spline point) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
166 |
kwargs['decorate'] = 'false' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
167 |
return kwargs |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
168 |
|
0 | 169 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
170 |
class RestrictedSchemaVisitorMiIn: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
171 |
def __init__(self, req, *args, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
172 |
# hack hack hack |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
173 |
assert len(self.__class__.__bases__) == 2 |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
174 |
self.__parent = self.__class__.__bases__[1] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
175 |
self.__parent.__init__(self, *args, **kwargs) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
176 |
self.req = req |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
177 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
178 |
def nodes(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
179 |
for etype, eschema in self.__parent.nodes(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
180 |
if eschema.has_local_role('read') or eschema.has_perm(self.req, 'read'): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
181 |
yield eschema.type, eschema |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
182 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
183 |
def edges(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
184 |
for setype, oetype, rschema in self.__parent.edges(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
185 |
if rschema.has_local_role('read') or rschema.has_perm(self.req, 'read'): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
186 |
yield setype, oetype, rschema |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
187 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
188 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
189 |
class FullSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.FullSchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
190 |
pass |
0 | 191 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
192 |
class OneHopESchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopESchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
193 |
pass |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
194 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
195 |
class OneHopRSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopRSchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
196 |
pass |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
197 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
198 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
199 |
class SchemaImageView(TmpFileViewMixin, StartupView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
200 |
id = 'schemagraph' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
201 |
content_type = 'image/png' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
202 |
skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
203 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
204 |
"""display global schema information""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
205 |
skipmeta = not int(self.req.form.get('withmeta', 0)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
206 |
visitor = FullSchemaVisitor(self.req, self.schema, skiprels=self.skip_rels, skipmeta=skipmeta) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
207 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
208 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
209 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
210 |
class CWETypeSchemaImageView(TmpFileViewMixin, EntityView): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
211 |
id = 'eschemagraph' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
212 |
content_type = 'image/png' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
213 |
__select__ = implements('CWEType') |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
214 |
skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
215 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
216 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
217 |
"""display schema information for an entity""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
218 |
entity = self.entity(self.row, self.col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
219 |
eschema = self.vreg.schema.eschema(entity.name) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
220 |
visitor = OneHopESchemaVisitor(self.req, eschema, skiprels=self.skip_rels) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
221 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
222 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
223 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
224 |
class CWRTypeSchemaImageView(CWETypeSchemaImageView): |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
225 |
__select__ = implements('CWRType') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
226 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
227 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
228 |
"""display schema information for an entity""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
229 |
entity = self.entity(self.row, self.col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
230 |
rschema = self.vreg.schema.rschema(entity.name) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
231 |
visitor = OneHopRSchemaVisitor(self.req, rschema) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
232 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
233 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |