author | sylvain.thenault@logilab.fr |
Mon, 04 May 2009 15:50:31 +0200 | |
branch | tls-sprint |
changeset 1655 | b9b59e7239ab |
parent 1580 | e26bbb0a6eb9 |
child 1720 | 14c9a0a1aca1 |
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 |
1556 | 17 |
from cubicweb.common import tags, uilib |
1580
e26bbb0a6eb9
use tag_attribute, rwidgets should contain widget instance, not name
sylvain.thenault@logilab.fr
parents:
1556
diff
changeset
|
18 |
from cubicweb.web import uicfg, formwidgets, action |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
19 |
from cubicweb.web.views import TmpFileViewMixin, primary, 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 |
|
1533 | 22 |
uicfg.rcategories.tag_relation('primary', ('CWPermission', 'require_group', '*'), 'subject') |
1580
e26bbb0a6eb9
use tag_attribute, rwidgets should contain widget instance, not name
sylvain.thenault@logilab.fr
parents:
1556
diff
changeset
|
23 |
uicfg.rcategories.tag_attribute('generated', 'EEtype', 'final') |
e26bbb0a6eb9
use tag_attribute, rwidgets should contain widget instance, not name
sylvain.thenault@logilab.fr
parents:
1556
diff
changeset
|
24 |
uicfg.rcategories.tag_attribute('generated', 'ERtype', 'final') |
1533 | 25 |
uicfg.rinlined.tag_relation(True, ('CWRelation', 'relation_type', '*'), 'subject') |
26 |
uicfg.rinlined.tag_relation(True, ('CWRelation', 'from_entity', '*'), 'subject') |
|
27 |
uicfg.rinlined.tag_relation(True, ('CWRelation', 'to_entity', '*'), 'subject') |
|
1580
e26bbb0a6eb9
use tag_attribute, rwidgets should contain widget instance, not name
sylvain.thenault@logilab.fr
parents:
1556
diff
changeset
|
28 |
uicfg.rwidgets.tag_attribute(formwidgets.TextInput, 'RQLExpression', 'expression') |
1151
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
29 |
|
1533 | 30 |
uicfg.rmode.tag_relation('create', ('*', 'state_of', 'CWEType'), 'object') |
31 |
uicfg.rmode.tag_relation('create', ('*', 'transition_of', 'CWEType'), 'object') |
|
32 |
uicfg.rmode.tag_relation('create', ('*', 'relation_type', 'CWRType'), 'object') |
|
33 |
uicfg.rmode.tag_relation('link', ('*', 'from_entity', 'CWEType'), 'object') |
|
34 |
uicfg.rmode.tag_relation('link', ('*', 'to_entity', 'CWEType'), 'object') |
|
0 | 35 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
36 |
for attr in ('name', 'meta', 'final'): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
37 |
uicfg.rdisplay.tag_attribute({}, 'CWRType', attr) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
38 |
for attr in ('name', 'meta', 'final', 'symetric', 'inlined'): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
39 |
uicfg.rdisplay.tag_attribute({}, 'CWRType', attr) |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
40 |
|
0 | 41 |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
42 |
class ViewSchemaAction(action.Action): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
43 |
id = 'schema' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
44 |
__select__ = yes() |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
45 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
46 |
title = _("site schema") |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
47 |
category = 'siteactions' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
48 |
order = 30 |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
49 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
50 |
def url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
51 |
return self.build_url(self.id) |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
52 |
|
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
53 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
54 |
# schema entity types views ################################################### |
0 | 55 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
56 |
class CWRDEFPrimaryView(primary.PrimaryView): |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
57 |
__select__ = implements('CWAttribute', 'CWRelation') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
58 |
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
|
59 |
|
0 | 60 |
def content_title(self, entity): |
61 |
return html_escape(entity.dc_long_title()) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
62 |
|
0 | 63 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
64 |
class CWETypeOneLineView(baseviews.OneLineView): |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
65 |
__select__ = implements('CWEType') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
66 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
67 |
def cell_call(self, row, col, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
68 |
entity = self.entity(row, col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
69 |
final = entity.final |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
70 |
if final: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
if final: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
74 |
self.w(u'</em>') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
75 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
76 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
77 |
# in memory schema views (yams class instances) ############################### |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
78 |
SKIPPED_RELS = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by', |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
79 |
'has_text',) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
80 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
81 |
class CWETypeSchemaView(primary.PrimaryView): |
0 | 82 |
id = 'eschema' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
83 |
__select__ = implements('CWEType') |
0 | 84 |
title = _('in memory entity schema') |
85 |
main_related_section = False |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
86 |
skip_rels = SKIPPED_RELS |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
87 |
|
1556 | 88 |
def render_entity_attributes(self, entity): |
89 |
super(CWETypeSchemaView, self).render_entity_attributes(entity) |
|
0 | 90 |
eschema = self.vreg.schema.eschema(entity.name) |
91 |
viewer = SchemaViewer(self.req) |
|
92 |
layout = viewer.visit_entityschema(eschema, skiprels=self.skip_rels) |
|
1556 | 93 |
self.w(uilib.ureport_as_html(layout)) |
0 | 94 |
if not eschema.is_final(): |
1556 | 95 |
msg = self.req._('graphical schema for %s') % entity.name |
96 |
self.w(tags.img(src=entity.absolute_url(vid='eschemagraph'), |
|
97 |
alt=msg)) |
|
0 | 98 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
99 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
100 |
class CWRTypeSchemaView(primary.PrimaryView): |
0 | 101 |
id = 'eschema' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
102 |
__select__ = implements('CWRType') |
0 | 103 |
title = _('in memory relation schema') |
104 |
main_related_section = False |
|
105 |
||
1556 | 106 |
def render_entity_attributes(self, entity): |
107 |
super(CWRTypeSchemaView, self).render_entity_attributes(entity) |
|
0 | 108 |
rschema = self.vreg.schema.rschema(entity.name) |
109 |
viewer = SchemaViewer(self.req) |
|
110 |
layout = viewer.visit_relationschema(rschema) |
|
1556 | 111 |
self.w(uilib.ureport_as_html(layout)) |
0 | 112 |
if not rschema.is_final(): |
1556 | 113 |
msg = self.req._('graphical schema for %s') % entity.name |
114 |
self.w(tags.img(src=entity.absolute_url(vid='eschemagraph'), |
|
115 |
alt=msg)) |
|
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
116 |
|
0 | 117 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
118 |
# schema images ############################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
119 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
120 |
class ImageView(EntityView): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
121 |
__select__ = implements('CWEType') |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
122 |
id = 'image' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
123 |
title = _('image') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
124 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
125 |
def cell_call(self, row, col): |
0 | 126 |
entity = self.entity(row, col) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
127 |
url = entity.absolute_url(vid='eschemagraph') |
0 | 128 |
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
|
129 |
html_escape(url), |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
130 |
html_escape(self.req._('graphical schema for %s') % entity.name))) |
0 | 131 |
|
132 |
||
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
133 |
class RestrictedSchemaDotPropsHandler(s2d.SchemaDotPropsHandler): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
134 |
def __init__(self, req): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
135 |
# FIXME: colors are arbitrary |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
136 |
self.nextcolor = cycle( ('#aa0000', '#00aa00', '#0000aa', |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
137 |
'#000000', '#888888') ).next |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
138 |
self.req = req |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
139 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
140 |
def display_attr(self, rschema): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
141 |
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
|
142 |
or rschema.has_perm(self.req, 'read')) |
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 |
# 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
|
145 |
def node_properties(self, eschema): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
146 |
"""return default DOT drawing options for an entity schema""" |
1132 | 147 |
label = ['{', eschema.type, '|'] |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
148 |
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
|
149 |
if rel.final and self.display_attr(rel))) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
150 |
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
|
151 |
return {'label' : ''.join(label), 'shape' : "record", |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
152 |
'fontname' : "Courier", 'style' : "filled"} |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
153 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
154 |
def edge_properties(self, rschema, subjnode, objnode): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
155 |
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
|
156 |
# 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
|
157 |
if not rschema.symetric: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
158 |
kwargs['color'] = self.nextcolor() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
159 |
kwargs['fontcolor'] = kwargs['color'] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
160 |
# 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
|
161 |
# + 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
|
162 |
kwargs['decorate'] = 'false' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
163 |
return kwargs |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
164 |
|
0 | 165 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
166 |
class RestrictedSchemaVisitorMiIn: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
167 |
def __init__(self, req, *args, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
168 |
# hack hack hack |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
169 |
assert len(self.__class__.__bases__) == 2 |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
170 |
self.__parent = self.__class__.__bases__[1] |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
171 |
self.__parent.__init__(self, *args, **kwargs) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
172 |
self.req = req |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
173 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
174 |
def nodes(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
175 |
for etype, eschema in self.__parent.nodes(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
176 |
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
|
177 |
yield eschema.type, eschema |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
178 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
179 |
def edges(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
yield setype, oetype, rschema |
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 FullSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.FullSchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
186 |
pass |
0 | 187 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
188 |
class OneHopESchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopESchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
189 |
pass |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
190 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
191 |
class OneHopRSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopRSchemaVisitor): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
192 |
pass |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
193 |
|
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 SchemaImageView(TmpFileViewMixin, StartupView): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
196 |
id = 'schemagraph' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
197 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
198 |
content_type = 'image/png' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
199 |
skip_rels = SKIPPED_RELS |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
200 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
201 |
"""display global schema information""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
205 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
206 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
207 |
class CWETypeSchemaImageView(TmpFileViewMixin, EntityView): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
208 |
id = 'eschemagraph' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
209 |
__select__ = implements('CWEType') |
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
210 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
211 |
content_type = 'image/png' |
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
212 |
skip_rels = SKIPPED_RELS |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
213 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
214 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
215 |
"""display schema information for an entity""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
216 |
entity = self.entity(self.row, self.col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
217 |
eschema = self.vreg.schema.eschema(entity.name) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
218 |
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
|
219 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
220 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
221 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
222 |
class CWRTypeSchemaImageView(CWETypeSchemaImageView): |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
223 |
__select__ = implements('CWRType') |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
224 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
225 |
def _generate(self, tmpfile): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
226 |
"""display schema information for an entity""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
227 |
entity = self.entity(self.row, self.col) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
228 |
rschema = self.vreg.schema.rschema(entity.name) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
229 |
visitor = OneHopRSchemaVisitor(self.req, rschema) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
230 |
s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
1012
diff
changeset
|
231 |
prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |