author | sylvain.thenault@logilab.fr |
Mon, 23 Mar 2009 17:55:59 +0100 | |
branch | tls-sprint |
changeset 1132 | 96752791c2b6 |
parent 1091 | b5e253c0dd13 |
child 1151 | b20677336ee6 |
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 |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
18 |
from cubicweb.web.action import Action |
0 | 19 |
from cubicweb.web.views import baseviews |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
20 |
from cubicweb.web.views import TmpFileViewMixin |
0 | 21 |
|
22 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
23 |
class ViewSchemaAction(Action): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
24 |
id = 'schema' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
25 |
__select__ = yes() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
26 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
27 |
title = _("site schema") |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
28 |
category = 'siteactions' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
29 |
order = 30 |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
30 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
31 |
def url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
32 |
return self.build_url(self.id) |
0 | 33 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
34 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
35 |
# schema entity types views ################################################### |
0 | 36 |
|
37 |
class _SchemaEntityPrimaryView(baseviews.PrimaryView): |
|
38 |
show_attr_label = False |
|
39 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
|
40 |
||
41 |
def content_title(self, entity): |
|
42 |
return html_escape(entity.dc_long_title()) |
|
43 |
||
44 |
class EETypePrimaryView(_SchemaEntityPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
45 |
__select__ = implements('EEType') |
0 | 46 |
skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final') |
47 |
||
48 |
class ERTypePrimaryView(_SchemaEntityPrimaryView): |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
49 |
__select__ = implements('ERType') |
0 | 50 |
skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final', |
51 |
'symetric', 'inlined') |
|
52 |
||
53 |
class ErdefPrimaryView(_SchemaEntityPrimaryView): |
|
1012 | 54 |
__select__ = implements('EFRDef', 'ENFRDef') |
0 | 55 |
show_attr_label = True |
56 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
57 |
class EETypeOneLineView(baseviews.OneLineView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
58 |
__select__ = implements('EEType') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
59 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
60 |
def cell_call(self, row, col, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
61 |
entity = self.entity(row, col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
62 |
final = entity.final |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
63 |
if final: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
64 |
self.w(u'<em class="finalentity">') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
65 |
super(EETypeOneLineView, self).cell_call(row, col, **kwargs) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
66 |
if final: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
67 |
self.w(u'</em>') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
68 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
69 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
70 |
# in memory schema views (yams class instances) ############################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
71 |
|
0 | 72 |
class EETypeSchemaView(EETypePrimaryView): |
73 |
id = 'eschema' |
|
74 |
title = _('in memory entity schema') |
|
75 |
main_related_section = False |
|
76 |
skip_rels = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by', |
|
77 |
'has_text',) |
|
78 |
||
79 |
def render_entity_attributes(self, entity, siderelations): |
|
80 |
super(EETypeSchemaView, self).render_entity_attributes(entity, siderelations) |
|
81 |
eschema = self.vreg.schema.eschema(entity.name) |
|
82 |
viewer = SchemaViewer(self.req) |
|
83 |
layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels) |
|
84 |
self.w(ureport_as_html(layout)) |
|
85 |
if not eschema.is_final(): |
|
86 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
87 |
html_escape(entity.absolute_url(vid='eschemagraph')), |
|
88 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
89 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
90 |
|
0 | 91 |
class ERTypeSchemaView(ERTypePrimaryView): |
92 |
id = 'eschema' |
|
93 |
title = _('in memory relation schema') |
|
94 |
main_related_section = False |
|
95 |
||
96 |
def render_entity_attributes(self, entity, siderelations): |
|
97 |
super(ERTypeSchemaView, self).render_entity_attributes(entity, siderelations) |
|
98 |
rschema = self.vreg.schema.rschema(entity.name) |
|
99 |
viewer = SchemaViewer(self.req) |
|
100 |
layout = viewer.visit_relationschema(rschema) |
|
101 |
self.w(ureport_as_html(layout)) |
|
102 |
if not rschema.is_final(): |
|
103 |
self.w(u'<img src="%s" alt="%s"/>' % ( |
|
104 |
html_escape(entity.absolute_url(vid='eschemagraph')), |
|
105 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
106 |
|
0 | 107 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
108 |
# schema images ############################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
109 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
110 |
class ImageView(EntityView): |
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
111 |
__select__ = implements('EEType') |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
112 |
id = 'image' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
113 |
title = _('image') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
114 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
115 |
def cell_call(self, row, col): |
0 | 116 |
entity = self.entity(row, col) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
117 |
url = entity.absolute_url(vid='eschemagraph') |
0 | 118 |
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
|
119 |
html_escape(url), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
120 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
0 | 121 |
|
122 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
123 |
class RestrictedSchemaDotPropsHandler(s2d.SchemaDotPropsHandler): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
124 |
def __init__(self, req): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
125 |
# FIXME: colors are arbitrary |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
126 |
self.nextcolor = cycle( ('#aa0000', '#00aa00', '#0000aa', |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
127 |
'#000000', '#888888') ).next |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
128 |
self.req = req |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
129 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
130 |
def display_attr(self, rschema): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
131 |
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
|
132 |
or rschema.has_perm(self.req, 'read')) |
0 | 133 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
134 |
# 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
|
135 |
def node_properties(self, eschema): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
136 |
"""return default DOT drawing options for an entity schema""" |
1132 | 137 |
label = ['{', eschema.type, '|'] |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
138 |
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
|
139 |
if rel.final and self.display_attr(rel))) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
140 |
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
|
141 |
return {'label' : ''.join(label), 'shape' : "record", |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
142 |
'fontname' : "Courier", 'style' : "filled"} |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
143 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
144 |
def edge_properties(self, rschema, subjnode, objnode): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
145 |
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
|
146 |
# 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
|
147 |
if not rschema.symetric: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
148 |
kwargs['color'] = self.nextcolor() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
149 |
kwargs['fontcolor'] = kwargs['color'] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
150 |
# 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
|
151 |
# + 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
|
152 |
kwargs['decorate'] = 'false' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
153 |
return kwargs |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
154 |
|
0 | 155 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
156 |
class RestrictedSchemaVisitorMiIn: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
157 |
def __init__(self, req, *args, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
158 |
# hack hack hack |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
159 |
assert len(self.__class__.__bases__) == 2 |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
160 |
self.__parent = self.__class__.__bases__[1] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
161 |
self.__parent.__init__(self, *args, **kwargs) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
162 |
self.req = req |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
163 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
164 |
def nodes(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
165 |
for etype, eschema in self.__parent.nodes(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
166 |
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
|
167 |
yield eschema.type, eschema |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
168 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
169 |
def edges(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
170 |
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
|
171 |
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
|
172 |
yield setype, oetype, rschema |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
173 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
174 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
175 |
class FullSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.FullSchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
176 |
pass |
0 | 177 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
178 |
class OneHopESchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopESchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
179 |
pass |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
180 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
181 |
class OneHopRSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopRSchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
182 |
pass |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
183 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
184 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
185 |
class SchemaImageView(TmpFileViewMixin, StartupView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
186 |
id = 'schemagraph' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
187 |
content_type = 'image/png' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
188 |
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
|
189 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
190 |
"""display global schema information""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
194 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
195 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
196 |
class EETypeSchemaImageView(TmpFileViewMixin, EntityView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
197 |
id = 'eschemagraph' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
198 |
content_type = 'image/png' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
199 |
__select__ = implements('EEType') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
200 |
skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of') |
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
201 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
202 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
203 |
"""display schema information for an entity""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
204 |
entity = self.entity(self.row, self.col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
205 |
eschema = self.vreg.schema.eschema(entity.name) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
206 |
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
|
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 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
210 |
class ERTypeSchemaImageView(EETypeSchemaImageView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
211 |
__select__ = implements('ERType') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
212 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
213 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
214 |
"""display schema information for an entity""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
215 |
entity = self.entity(self.row, self.col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
216 |
rschema = self.vreg.schema.rschema(entity.name) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
217 |
visitor = OneHopRSchemaVisitor(self.req, rschema) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
218 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
219 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |