14 from cubicweb.selectors import implements, yes |
14 from cubicweb.selectors import implements, yes |
15 from cubicweb.schemaviewer import SchemaViewer |
15 from cubicweb.schemaviewer import SchemaViewer |
16 from cubicweb.view import EntityView, StartupView |
16 from cubicweb.view import EntityView, StartupView |
17 from cubicweb.common.uilib import ureport_as_html |
17 from cubicweb.common.uilib import ureport_as_html |
18 from cubicweb.web import uicfg, action |
18 from cubicweb.web import uicfg, action |
19 from cubicweb.web.views import TmpFileViewMixin, baseviews |
19 from cubicweb.web.views import TmpFileViewMixin, primary, baseviews |
20 |
20 |
21 |
21 |
22 uicfg.rcategories.tag_relation('primary', ('CWPermission', 'require_group', '*'), 'subject') |
22 uicfg.rcategories.tag_relation('primary', ('CWPermission', 'require_group', '*'), 'subject') |
23 uicfg.rcategories.tag_relation('generated', ('EEtype', 'final', '*'), 'subject') |
23 uicfg.rcategories.tag_relation('generated', ('EEtype', 'final', '*'), 'subject') |
24 uicfg.rcategories.tag_relation('generated', ('ERtype', 'final', '*'), 'subject') |
24 uicfg.rcategories.tag_relation('generated', ('ERtype', 'final', '*'), 'subject') |
31 uicfg.rmode.tag_relation('create', ('*', 'transition_of', 'CWEType'), 'object') |
31 uicfg.rmode.tag_relation('create', ('*', 'transition_of', 'CWEType'), 'object') |
32 uicfg.rmode.tag_relation('create', ('*', 'relation_type', 'CWRType'), 'object') |
32 uicfg.rmode.tag_relation('create', ('*', 'relation_type', 'CWRType'), 'object') |
33 uicfg.rmode.tag_relation('link', ('*', 'from_entity', 'CWEType'), 'object') |
33 uicfg.rmode.tag_relation('link', ('*', 'from_entity', 'CWEType'), 'object') |
34 uicfg.rmode.tag_relation('link', ('*', 'to_entity', 'CWEType'), 'object') |
34 uicfg.rmode.tag_relation('link', ('*', 'to_entity', 'CWEType'), 'object') |
35 |
35 |
|
36 for attr in ('name', 'meta', 'final'): |
|
37 uicfg.rdisplay.tag_attribute({}, 'CWRType', attr) |
|
38 for attr in ('name', 'meta', 'final', 'symetric', 'inlined'): |
|
39 uicfg.rdisplay.tag_attribute({}, 'CWRType', attr) |
|
40 |
36 |
41 |
37 class ViewSchemaAction(action.Action): |
42 class ViewSchemaAction(action.Action): |
38 id = 'schema' |
43 id = 'schema' |
39 __select__ = yes() |
44 __select__ = yes() |
40 |
45 |
46 return self.build_url(self.id) |
51 return self.build_url(self.id) |
47 |
52 |
48 |
53 |
49 # schema entity types views ################################################### |
54 # schema entity types views ################################################### |
50 |
55 |
51 class _SchemaEntityPrimaryView(baseviews.PrimaryView): |
56 class CWRDEFPrimaryView(primary.PrimaryView): |
52 show_attr_label = False |
57 __select__ = implements('CWAttribute', 'CWRelation') |
53 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
58 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
54 |
59 |
55 def content_title(self, entity): |
60 def content_title(self, entity): |
56 return html_escape(entity.dc_long_title()) |
61 return html_escape(entity.dc_long_title()) |
57 |
62 |
58 class CWETypePrimaryView(_SchemaEntityPrimaryView): |
|
59 __select__ = implements('CWEType') |
|
60 skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final') |
|
61 |
|
62 class CWRTypePrimaryView(_SchemaEntityPrimaryView): |
|
63 __select__ = implements('CWRType') |
|
64 skip_attrs = _SchemaEntityPrimaryView.skip_attrs + ('name', 'meta', 'final', |
|
65 'symetric', 'inlined') |
|
66 |
|
67 class ErdefPrimaryView(_SchemaEntityPrimaryView): |
|
68 __select__ = implements('CWAttribute', 'CWRelation') |
|
69 show_attr_label = True |
|
70 |
63 |
71 class CWETypeOneLineView(baseviews.OneLineView): |
64 class CWETypeOneLineView(baseviews.OneLineView): |
72 __select__ = implements('CWEType') |
65 __select__ = implements('CWEType') |
73 |
66 |
74 def cell_call(self, row, col, **kwargs): |
67 def cell_call(self, row, col, **kwargs): |
80 if final: |
73 if final: |
81 self.w(u'</em>') |
74 self.w(u'</em>') |
82 |
75 |
83 |
76 |
84 # in memory schema views (yams class instances) ############################### |
77 # in memory schema views (yams class instances) ############################### |
85 |
78 SKIPPED_RELS = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by', |
86 class CWETypeSchemaView(CWETypePrimaryView): |
79 'has_text',) |
|
80 |
|
81 class CWETypeSchemaView(primary.PrimaryView): |
87 id = 'eschema' |
82 id = 'eschema' |
|
83 __select__ = implements('CWEType') |
88 title = _('in memory entity schema') |
84 title = _('in memory entity schema') |
89 main_related_section = False |
85 main_related_section = False |
90 skip_rels = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by', |
86 skip_rels = SKIPPED_RELS |
91 'has_text',) |
|
92 |
87 |
93 def render_entity_attributes(self, entity, siderelations): |
88 def render_entity_attributes(self, entity, siderelations): |
94 super(CWETypeSchemaView, self).render_entity_attributes(entity, siderelations) |
89 super(CWETypeSchemaView, self).render_entity_attributes(entity, siderelations) |
95 eschema = self.vreg.schema.eschema(entity.name) |
90 eschema = self.vreg.schema.eschema(entity.name) |
96 viewer = SchemaViewer(self.req) |
91 viewer = SchemaViewer(self.req) |
100 self.w(u'<img src="%s" alt="%s"/>' % ( |
95 self.w(u'<img src="%s" alt="%s"/>' % ( |
101 html_escape(entity.absolute_url(vid='eschemagraph')), |
96 html_escape(entity.absolute_url(vid='eschemagraph')), |
102 html_escape(self.req._('graphical schema for %s') % entity.name))) |
97 html_escape(self.req._('graphical schema for %s') % entity.name))) |
103 |
98 |
104 |
99 |
105 class CWRTypeSchemaView(CWRTypePrimaryView): |
100 class CWRTypeSchemaView(primary.PrimaryView): |
106 id = 'eschema' |
101 id = 'eschema' |
|
102 __select__ = implements('CWRType') |
107 title = _('in memory relation schema') |
103 title = _('in memory relation schema') |
108 main_related_section = False |
104 main_related_section = False |
109 |
105 |
110 def render_entity_attributes(self, entity, siderelations): |
106 def render_entity_attributes(self, entity, siderelations): |
111 super(CWRTypeSchemaView, self).render_entity_attributes(entity, siderelations) |
107 super(CWRTypeSchemaView, self).render_entity_attributes(entity, siderelations) |
196 pass |
192 pass |
197 |
193 |
198 |
194 |
199 class SchemaImageView(TmpFileViewMixin, StartupView): |
195 class SchemaImageView(TmpFileViewMixin, StartupView): |
200 id = 'schemagraph' |
196 id = 'schemagraph' |
|
197 |
201 content_type = 'image/png' |
198 content_type = 'image/png' |
202 skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of') |
199 skip_rels = SKIPPED_RELS |
203 def _generate(self, tmpfile): |
200 def _generate(self, tmpfile): |
204 """display global schema information""" |
201 """display global schema information""" |
205 skipmeta = not int(self.req.form.get('withmeta', 0)) |
202 skipmeta = not int(self.req.form.get('withmeta', 0)) |
206 visitor = FullSchemaVisitor(self.req, self.schema, skiprels=self.skip_rels, skipmeta=skipmeta) |
203 visitor = FullSchemaVisitor(self.req, self.schema, skiprels=self.skip_rels, skipmeta=skipmeta) |
207 s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
204 s2d.schema2dot(outputfile=tmpfile, visitor=visitor, |
208 prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |
205 prophdlr=RestrictedSchemaDotPropsHandler(self.req)) |
209 |
206 |
210 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView): |
207 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView): |
211 id = 'eschemagraph' |
208 id = 'eschemagraph' |
|
209 __select__ = implements('CWEType') |
|
210 |
212 content_type = 'image/png' |
211 content_type = 'image/png' |
213 __select__ = implements('CWEType') |
212 skip_rels = SKIPPED_RELS |
214 skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of') |
|
215 |
213 |
216 def _generate(self, tmpfile): |
214 def _generate(self, tmpfile): |
217 """display schema information for an entity""" |
215 """display schema information for an entity""" |
218 entity = self.entity(self.row, self.col) |
216 entity = self.entity(self.row, self.col) |
219 eschema = self.vreg.schema.eschema(entity.name) |
217 eschema = self.vreg.schema.eschema(entity.name) |